2026-04-06 00:07:36 -04:00
|
|
|
import { drizzle } from "drizzle-orm/postgres-js";
|
|
|
|
|
import { migrate } from "drizzle-orm/postgres-js/migrator";
|
|
|
|
|
import postgres from "postgres";
|
|
|
|
|
import { fileURLToPath } from "url";
|
|
|
|
|
import path from "path";
|
|
|
|
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
|
|
2026-04-06 17:15:18 -04:00
|
|
|
const migrationUrl = process.env.DATABASE_DIRECT_URL || process.env.DATABASE_URL;
|
|
|
|
|
if (!migrationUrl) {
|
|
|
|
|
console.error("ERROR: DATABASE_URL (or DATABASE_DIRECT_URL) is required");
|
2026-04-06 00:07:36 -04:00
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("Running database migrations...");
|
2026-04-06 17:15:18 -04:00
|
|
|
const client = postgres(migrationUrl, {
|
2026-04-06 04:20:25 +00:00
|
|
|
max: 1,
|
|
|
|
|
onnotice: () => {}, // suppress NOTICE messages (schema/table already exists, etc.)
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-06 00:07:36 -04:00
|
|
|
try {
|
|
|
|
|
const db = drizzle(client);
|
|
|
|
|
await migrate(db, { migrationsFolder: path.resolve(__dirname, "../drizzle") });
|
|
|
|
|
console.log("Migrations completed successfully");
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Migration failed:", err);
|
2026-04-06 04:20:25 +00:00
|
|
|
await client.end().catch(() => {});
|
2026-04-06 00:07:36 -04:00
|
|
|
process.exit(1);
|
|
|
|
|
}
|
2026-04-06 04:20:25 +00:00
|
|
|
|
|
|
|
|
await client.end().catch(() => {});
|
|
|
|
|
process.exit(0);
|