fix(db): repair fresh migration chain
CI and Deploy / test (pull_request) Successful in 5m19s
CI and Deploy / deploy (pull_request) Has been skipped

This commit is contained in:
cesnimda
2026-08-15 20:47:36 +02:00
parent 191de69c48
commit 74a1e0d845
15 changed files with 297 additions and 35 deletions
@@ -402,8 +402,6 @@ public static class StartupInitializationExtensions
{
// EF migrations are used for the app schema. In some environments `dotnet ef` isnt available,
// so create the ASP.NET Core Identity tables directly if they dont exist yet.
if (HasTable(c, "AspNetUsers")) return;
Exec(c, """
CREATE TABLE IF NOT EXISTS "AspNetRoles" (
"Id" TEXT NOT NULL CONSTRAINT "PK_AspNetRoles" PRIMARY KEY,
@@ -2014,11 +2012,24 @@ public static class StartupInitializationExtensions
{
using var migrationScope = app.Services.CreateScope();
var migrationDb = migrationScope.ServiceProvider.GetRequiredService<JobTrackerContext>();
var migrator = migrationDb.Database.GetService<IMigrator>();
while (migrationDb.Database.GetPendingMigrations().FirstOrDefault() is { } migration)
if (useSqliteBootstrap)
{
migrator.Migrate(migration);
ReconcileSchema();
var migrator = migrationDb.Database.GetService<IMigrator>();
while (migrationDb.Database.GetPendingMigrations().FirstOrDefault() is { } migration)
{
migrator.Migrate(migration);
ReconcileSchema();
}
}
else
{
// MariaDB ALTER operations do not rebuild tables from a snapshot, so they do
// not need SQLite's per-migration reconciliation. Reconciling between its
// historical migrations can add a later column (for example Companies.Source)
// immediately before the migration that owns it, producing a duplicate-column
// failure on a clean database. Apply the chain first, then use the common final
// reconciliation pass for provider-safe repairs and reconciler-owned tables.
migrationDb.Database.Migrate();
}
}
catch (Exception ex)