feat(config-db): migration AuditLogChannelOccurredIndex — partition-aligned IX_AuditLog_Channel_Occurred (AUD-5, WP6 task 6.5)

Adds IX_AuditLog_Channel_Occurred (Category, OccurredAtUtc) ON
ps_AuditLog_Month(OccurredAtUtc) via raw SQL (EF CreateIndex cannot express
the partition scheme), like ReviewRemediationIndexes. Idempotent QA/DEV
script: docs/plans/sql/AuditLogChannelOccurredIndex.sql (sqlcmd -I). Kept in
its own commit so the integrator can regenerate it on merge with the other
WPs' migrations.

Index-name pins updated: AuditLogEntityTypeConfigurationTests and
FlipAuditLogClusteredKeyMigrationTests (head shape asserts the new index is
partition-aligned on ps_AuditLog_Month; the pre-flip round-trip shape does
not carry it).
This commit is contained in:
Joseph Doherty
2026-12-03 10:59:03 -05:00
parent b3fba593a3
commit 9a574746dc
6 changed files with 2402 additions and 1 deletions
@@ -186,6 +186,7 @@ public class AuditLogEntityTypeConfigurationTests : IDisposable
var expected = new[]
{
"IX_AuditLog_Actor_Occurred",
"IX_AuditLog_Channel_Occurred", // AuditLogChannelOccurredIndex (AUD-5)
"IX_AuditLog_Channel_Status_Occurred",
"IX_AuditLog_CorrelationId",
"IX_AuditLog_Execution",
@@ -70,7 +70,11 @@ public sealed class FlipAuditLogClusteredKeyMigrationTests : IClassFixture<MsSql
Assert.True(indexes["PK_AuditLog"].Clustered);
Assert.Equal("EventId, OccurredAtUtc", indexes["UX_AuditLog_EventId_Occurred"].Keys);
Assert.True(indexes["UX_AuditLog_EventId_Occurred"].Unique);
Assert.Equal(NonClusteredIndexes.Length + 2, indexes.Count);
// + PK + UX + IX_AuditLog_Channel_Occurred (AuditLogChannelOccurredIndex, AUD-5 — added
// after the flip, so the pre-flip round-trip shape below does not carry it).
Assert.Equal(NonClusteredIndexes.Length + 3, indexes.Count);
Assert.Equal("Category, OccurredAtUtc", indexes["IX_AuditLog_Channel_Occurred"].Keys);
Assert.False(indexes["IX_AuditLog_Channel_Occurred"].Clustered);
Assert.All(indexes.Values, i => Assert.Equal("ps_AuditLog_Month", i.DataSpace));
AssertNonClusteredIndexes(indexes, withChainIndexes: false);
Assert.Equal(ExpectedGrants, await ReadGrantsAsync());