mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-14 06:47:00 +10:00
lot of bugfixes, better migration script
This commit is contained in:
@@ -1,18 +1,28 @@
|
||||
import { sql } from "drizzle-orm";
|
||||
import { drizzle } from "drizzle-orm/node-postgres";
|
||||
import { Pool } from "pg";
|
||||
import { env } from "@/utils/env";
|
||||
|
||||
const pool = new Pool({ connectionString: env.DATABASE_URL });
|
||||
const db = drizzle({ client: pool });
|
||||
const productionUrl = process.env.PRODUCTION_DATABASE_URL;
|
||||
if (!productionUrl) throw new Error("PRODUCTION_DATABASE_URL is not set");
|
||||
const productionPool = new Pool({ connectionString: productionUrl });
|
||||
const productionDb = drizzle({ client: productionPool });
|
||||
|
||||
const localUrl = process.env.DATABASE_URL;
|
||||
if (!localUrl) throw new Error("DATABASE_URL is not set");
|
||||
const localPool = new Pool({ connectionString: localUrl });
|
||||
const localDb = drizzle({ client: localPool });
|
||||
|
||||
try {
|
||||
const result = await db.execute(sql`SELECT 1 as connected`);
|
||||
console.log("✅ Database connection successful", JSON.stringify(result));
|
||||
const productionResult = await productionDb.execute(sql`SELECT 1 as connected`);
|
||||
console.log("✅ Production database connection successful", JSON.stringify(productionResult));
|
||||
|
||||
const localResult = await localDb.execute(sql`SELECT 1 as connected`);
|
||||
console.log("✅ Local database connection successful", JSON.stringify(localResult));
|
||||
} catch (error) {
|
||||
console.error("🚨 Database connection failed:", error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await pool.end();
|
||||
await productionPool.end();
|
||||
await localPool.end();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user