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
@@ -22,4 +22,16 @@ public sealed class ConfigAuditLog
public long? GenerationId { get; set; }
public string? DetailsJson { get; set; }
/// <summary>
/// Stable per-event identifier from <c>AuditEvent.EventId</c>. Filtered unique index on
/// this column gives cross-restart idempotency for the batched AuditWriterActor: a flush
/// that retries after a process crash can re-send the same EventId without producing a
/// duplicate row. Nullable so pre-v2 rows backfill cleanly.
/// </summary>
public Guid? EventId { get; set; }
/// <summary>Correlation ID from <c>AuditEvent.CorrelationId</c> so an audit row joins to its
/// originating request/workflow. Nullable for the same backfill reason as <see cref="EventId"/>.</summary>
public Guid? CorrelationId { get; set; }
}