chore(db): align SourceNode unicode metadata + document partition-aligned index recipe

Tidies flagged by code review on the T6/T7/T8 migration bundle:

- Add `.IsUnicode(false)` to the three SourceNode EF property mappings to
  match every other ASCII varchar column on the same entities. Physical
  column was already `varchar(64)` because `HasColumnType` wins, but the EF
  model metadata flag was inconsistent.
- Add `unicode: false` to the three AddColumn<string> calls in the migrations
  + their Designer snapshots so the historical snapshots match the model.
- Update the model snapshot to carry IsUnicode(false) on each SourceNode entry.
- Document the SELECT-list invariant on SiteCallAuditRepository.QueryAsync:
  EF Core's FromSqlInterpolated requires every entity-tracked column in the
  result set, so future SiteCall columns must extend the list too.
- Amend plan Task 6 Step 2 to document the partition-aligned raw-SQL index
  recipe and the staging-table sync requirement.
This commit is contained in:
Joseph Doherty
2026-05-23 16:45:19 -04:00
parent 1a77bc5f38
commit 8fb9eb0ce7
12 changed files with 37 additions and 8 deletions

View File

@@ -469,13 +469,22 @@ migrationBuilder.AddColumn<string>(
maxLength: 64,
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_AuditLog_Node_Occurred",
table: "AuditLog",
columns: new[] { "SourceNode", "OccurredAtUtc" });
// IMPORTANT: AuditLog is partitioned on ps_AuditLog_Month(OccurredAtUtc).
// `migrationBuilder.CreateIndex(...)` lands the index on [PRIMARY], which breaks
// `ALTER TABLE … SWITCH PARTITION` (the purge mechanism). Match the pattern used
// by the other `IX_AuditLog_*` indexes (see 20260520142214_AddAuditLogTable.cs
// and 20260521184044_AddAuditLogExecutionId.cs) — raw SQL with the partition
// scheme spelled out. Keep the fluent `HasIndex(...).HasDatabaseName(...)` in
// the EF configuration so the model snapshot stays in sync.
migrationBuilder.Sql(@"
CREATE NONCLUSTERED INDEX IX_AuditLog_Node_Occurred
ON dbo.AuditLog (SourceNode, OccurredAtUtc)
ON ps_AuditLog_Month(OccurredAtUtc);");
```
`Down()` drops the index then the column.
`Down()` drops the index (`IF EXISTS DROP INDEX … ON dbo.AuditLog`, raw SQL) then the column.
You will *also* need to extend `AuditLogRepository.SwitchOutPartitionAsync`'s staging-table CREATE to include `SourceNode varchar(64) NULL` in the final ordinal position. `SWITCH PARTITION` rejects schema mismatches between live and staging — without this, the PartitionPurge integration tests fail.
**Step 3: Update EF configuration**