fix(db): repair fresh migration chain
This commit is contained in:
@@ -402,8 +402,6 @@ public static class StartupInitializationExtensions
|
||||
{
|
||||
// EF migrations are used for the app schema. In some environments `dotnet ef` isn’t available,
|
||||
// so create the ASP.NET Core Identity tables directly if they don’t 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)
|
||||
|
||||
Reference in New Issue
Block a user