feat(audit): EventId + CorrelationId columns + filtered unique index (F3 + F4)

ConfigAuditLog gains two nullable columns (EventId, CorrelationId) + a filtered
unique index UX_ConfigAuditLog_EventId. EF migration
20260526105027_AddConfigAuditLogEventIdColumns is additive (nullable + filtered
index = legacy rows backfill cleanly).

AuditWriterActor now writes EventId + CorrelationId into the dedicated columns
instead of synthesising a JSON wrapper into DetailsJson. Cross-restart dedup
is now real: a retry of an already-flushed batch hits the unique index and
SaveChanges throws; the existing catch drops the duplicate without losing the
rest of the batch.

WrapDetails helper deleted — F4 (its JSON hardening) becomes moot.

AuditWriterActorTests.Details_wrapper_embeds_eventId_and_correlationId renamed
+ rewritten to assert against the columns. All 29 ControlPlane tests pass,
all 95 v2 tests green.
This commit is contained in:
Joseph Doherty
2026-05-26 06:52:53 -04:00
parent 8e5c8e29f7
commit f57f61deac
7 changed files with 1850 additions and 19 deletions

View File

@@ -78,7 +78,7 @@ public sealed class AuditWriterActorTests : ControlPlaneActorTestBase
}
[Fact]
public void Details_wrapper_embeds_eventId_and_correlationId()
public void EventId_and_CorrelationId_are_persisted_to_dedicated_columns()
{
var dbFactory = NewInMemoryDbFactory();
var actor = Sys.ActorOf(AuditWriterActor.Props(dbFactory));
@@ -92,9 +92,9 @@ public sealed class AuditWriterActorTests : ControlPlaneActorTestBase
using var db = dbFactory.CreateDbContext();
var row = db.ConfigAuditLogs.Single();
row.DetailsJson.ShouldNotBeNull();
row.DetailsJson.ShouldContain(eventId.ToString("N"));
row.DetailsJson.ShouldContain("\"correlationId\":");
row.EventId.ShouldBe(eventId);
row.CorrelationId.ShouldNotBeNull();
row.DetailsJson.ShouldBe("{\"field\":\"value\"}");
row.EventType.ShouldBe("Config:Edit");
row.NodeId.ShouldBe("node-a");
}