feat(audit)!: ScadaBridge C5 — collapse central dbo.AuditLog to 10 canonical cols + persisted computed cols; CollapseAuditLogToCanonical migration; repo writes canonical directly (Task 2.5)
This commit is contained in:
@@ -154,6 +154,43 @@ public class ScadaBridgeDbContext : DbContext, IDataProtectionKeyContext
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(ScadaBridgeDbContext).Assembly);
|
||||
|
||||
ApplySecretColumnEncryption(modelBuilder);
|
||||
|
||||
NeutralizeSqlServerComputedColumnsForNonSqlServerProviders(modelBuilder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// C5 (Task 2.5): the central <c>dbo.AuditLog</c> persisted computed columns use
|
||||
/// SQL Server's <c>JSON_VALUE</c> expression, which only SQL Server can evaluate.
|
||||
/// On a non-SQL-Server provider (the SQLite test contexts) emitting that SQL in a
|
||||
/// <c>CREATE TABLE</c> fails ("no such function: JSON_VALUE"). Strip the
|
||||
/// computed-column SQL for any non-SQL-Server provider so those columns degrade to
|
||||
/// plain (always-null on the test provider) nullable columns; SQL Server keeps the
|
||||
/// real <c>… AS JSON_VALUE(...) PERSISTED</c> definitions. This is a model-shape
|
||||
/// adaptation only — it never runs under the design-time SQL Server provider, so the
|
||||
/// migration / model-snapshot remain the canonical SQL Server shape.
|
||||
/// </summary>
|
||||
private void NeutralizeSqlServerComputedColumnsForNonSqlServerProviders(ModelBuilder modelBuilder)
|
||||
{
|
||||
// Database.IsSqlServer() reads the configured provider — true for production and
|
||||
// for the design-time factory (UseSqlServer), false for the SQLite test contexts.
|
||||
if (Database.IsSqlServer())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||
{
|
||||
foreach (var property in entityType.GetProperties())
|
||||
{
|
||||
if (property.GetComputedColumnSql() is not null)
|
||||
{
|
||||
property.SetComputedColumnSql(null);
|
||||
property.SetColumnType(null);
|
||||
property.ValueGenerated = Microsoft.EntityFrameworkCore.Metadata.ValueGenerated.Never;
|
||||
property.SetAfterSaveBehavior(Microsoft.EntityFrameworkCore.Metadata.PropertySaveBehavior.Save);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user