fix(site-runtime): add SQLite schema migration for backup_configuration column
Existing site databases created before the primary/backup data connections feature lack the backup_configuration and failover_retry_count columns. Added TryAddColumnAsync migration that runs on startup after table creation.
This commit is contained in:
@@ -101,9 +101,35 @@ public class SiteStorageService
|
|||||||
";
|
";
|
||||||
await command.ExecuteNonQueryAsync();
|
await command.ExecuteNonQueryAsync();
|
||||||
|
|
||||||
|
// Schema migrations — add columns that may not exist on older databases
|
||||||
|
await MigrateSchemaAsync(connection);
|
||||||
|
|
||||||
_logger.LogInformation("Site SQLite storage initialized at {ConnectionString}", _connectionString);
|
_logger.LogInformation("Site SQLite storage initialized at {ConnectionString}", _connectionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task MigrateSchemaAsync(SqliteConnection connection)
|
||||||
|
{
|
||||||
|
// Add backup_configuration and failover_retry_count to data_connection_definitions
|
||||||
|
// (added in primary/backup data connections feature)
|
||||||
|
await TryAddColumnAsync(connection, "data_connection_definitions", "backup_configuration", "TEXT");
|
||||||
|
await TryAddColumnAsync(connection, "data_connection_definitions", "failover_retry_count", "INTEGER NOT NULL DEFAULT 3");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task TryAddColumnAsync(SqliteConnection connection, string table, string column, string type)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await using var cmd = connection.CreateCommand();
|
||||||
|
cmd.CommandText = $"ALTER TABLE {table} ADD COLUMN {column} {type}";
|
||||||
|
await cmd.ExecuteNonQueryAsync();
|
||||||
|
_logger.LogInformation("Migrated: added column {Column} to {Table}", column, table);
|
||||||
|
}
|
||||||
|
catch (SqliteException ex) when (ex.Message.Contains("duplicate column"))
|
||||||
|
{
|
||||||
|
// Column already exists — no action needed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Deployed Configuration CRUD ──
|
// ── Deployed Configuration CRUD ──
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user