mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-15 18:30:39 +09:00
Fix legacy migration reconciliation
This commit is contained in:
parent
0c121b856f
commit
3d01217aef
2 changed files with 177 additions and 7 deletions
|
|
@ -646,13 +646,26 @@ export async function applyPendingMigrations(url: string): Promise<void> {
|
|||
const initialState = await inspectMigrations(url);
|
||||
if (initialState.status === "upToDate") return;
|
||||
|
||||
const sql = createUtilitySql(url);
|
||||
if (initialState.reason === "no-migration-journal-empty-db") {
|
||||
const sql = createUtilitySql(url);
|
||||
try {
|
||||
const db = drizzlePg(sql);
|
||||
await migratePg(db, { migrationsFolder: MIGRATIONS_FOLDER });
|
||||
} finally {
|
||||
await sql.end();
|
||||
}
|
||||
|
||||
try {
|
||||
const db = drizzlePg(sql);
|
||||
await migratePg(db, { migrationsFolder: MIGRATIONS_FOLDER });
|
||||
} finally {
|
||||
await sql.end();
|
||||
const bootstrappedState = await inspectMigrations(url);
|
||||
if (bootstrappedState.status === "upToDate") return;
|
||||
throw new Error(
|
||||
`Failed to bootstrap migrations: ${bootstrappedState.pendingMigrations.join(", ")}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (initialState.reason === "no-migration-journal-non-empty-db") {
|
||||
throw new Error(
|
||||
"Database has tables but no migration journal; automatic migration is unsafe. Initialize migration history manually.",
|
||||
);
|
||||
}
|
||||
|
||||
let state = await inspectMigrations(url);
|
||||
|
|
@ -665,7 +678,7 @@ export async function applyPendingMigrations(url: string): Promise<void> {
|
|||
}
|
||||
|
||||
if (state.status !== "needsMigrations" || state.reason !== "pending-migrations") {
|
||||
throw new Error("Migrations are still pending after attempted apply; run inspectMigrations for details.");
|
||||
throw new Error("Migrations are still pending after migration-history reconciliation; run inspectMigrations for details.");
|
||||
}
|
||||
|
||||
await applyPendingMigrationsManually(url, state.pendingMigrations);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue