2026-02-19 15:43:43 -06:00
|
|
|
import { applyPendingMigrations, inspectMigrations } from "./client.js";
|
2026-03-10 15:31:05 -05:00
|
|
|
import { resolveMigrationConnection } from "./migration-runtime.js";
|
2026-02-16 13:31:52 -06:00
|
|
|
|
2026-03-10 15:31:05 -05:00
|
|
|
async function main(): Promise<void> {
|
|
|
|
|
const resolved = await resolveMigrationConnection();
|
2026-02-16 13:31:52 -06:00
|
|
|
|
2026-03-10 15:31:05 -05:00
|
|
|
console.log(`Migrating database via ${resolved.source}`);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const before = await inspectMigrations(resolved.connectionString);
|
|
|
|
|
if (before.status === "upToDate") {
|
|
|
|
|
console.log("No pending migrations");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-16 13:31:52 -06:00
|
|
|
|
2026-03-10 15:31:05 -05:00
|
|
|
console.log(`Applying ${before.pendingMigrations.length} pending migration(s)...`);
|
|
|
|
|
await applyPendingMigrations(resolved.connectionString);
|
2026-02-18 11:45:43 -06:00
|
|
|
|
2026-03-10 15:31:05 -05:00
|
|
|
const after = await inspectMigrations(resolved.connectionString);
|
|
|
|
|
if (after.status !== "upToDate") {
|
|
|
|
|
throw new Error(`Migrations incomplete: ${after.pendingMigrations.join(", ")}`);
|
|
|
|
|
}
|
|
|
|
|
console.log("Migrations complete");
|
|
|
|
|
} finally {
|
|
|
|
|
await resolved.stop();
|
2026-02-19 15:43:43 -06:00
|
|
|
}
|
|
|
|
|
}
|
2026-03-10 15:31:05 -05:00
|
|
|
|
|
|
|
|
await main();
|