27 lines
804 B
JavaScript
27 lines
804 B
JavaScript
|
|
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);
|
||
|
|
|
||
|
|
if (!process.env.DATABASE_URL) {
|
||
|
|
console.error("ERROR: DATABASE_URL is required");
|
||
|
|
process.exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log("Running database migrations...");
|
||
|
|
const client = postgres(process.env.DATABASE_URL, { max: 1 });
|
||
|
|
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);
|
||
|
|
process.exit(1);
|
||
|
|
} finally {
|
||
|
|
await client.end();
|
||
|
|
}
|