2026-02-19 15:43:43 -06:00
|
|
|
import { applyPendingMigrations, inspectMigrations } from "./client.js";
|
2026-02-16 13:31:52 -06:00
|
|
|
|
|
|
|
|
const url = process.env.DATABASE_URL;
|
|
|
|
|
|
2026-02-18 11:45:43 -06:00
|
|
|
if (!url) {
|
|
|
|
|
throw new Error("DATABASE_URL is required for db:migrate");
|
2026-02-16 19:07:37 -06:00
|
|
|
}
|
2026-02-16 13:31:52 -06:00
|
|
|
|
2026-02-19 15:43:43 -06:00
|
|
|
const before = await inspectMigrations(url);
|
|
|
|
|
if (before.status === "upToDate") {
|
|
|
|
|
console.log("No pending migrations");
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`Applying ${before.pendingMigrations.length} pending migration(s)...`);
|
|
|
|
|
await applyPendingMigrations(url);
|
2026-02-18 11:45:43 -06:00
|
|
|
|
2026-02-19 15:43:43 -06:00
|
|
|
const after = await inspectMigrations(url);
|
|
|
|
|
if (after.status !== "upToDate") {
|
|
|
|
|
throw new Error(`Migrations incomplete: ${after.pendingMigrations.join(", ")}`);
|
|
|
|
|
}
|
|
|
|
|
console.log("Migrations complete");
|
|
|
|
|
}
|