mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-22 16:03:29 +10:00
initial commit of v5
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { drizzle } from "drizzle-orm/node-postgres";
|
||||
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
||||
import { definePlugin } from "nitro";
|
||||
import { Pool } from "pg";
|
||||
|
||||
async function migrateDatabase() {
|
||||
console.log("⌛ Running database migrations...");
|
||||
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
|
||||
if (!connectionString) {
|
||||
throw new Error("DATABASE_URL is not set");
|
||||
}
|
||||
|
||||
const pool = new Pool({ connectionString });
|
||||
const db = drizzle({ client: pool });
|
||||
|
||||
try {
|
||||
await migrate(db, { migrationsFolder: "./migrations" });
|
||||
console.log("✅ Database migrations completed");
|
||||
} catch (error) {
|
||||
console.error("🚨 Database migrations failed:", error);
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
export default definePlugin(async () => {
|
||||
await migrateDatabase();
|
||||
});
|
||||
Reference in New Issue
Block a user