first commit
This commit is contained in:
27
db.ts
Normal file
27
db.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { drizzle } from "drizzle-orm/node-postgres";
|
||||
import { Pool } from "pg";
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
// Create pool - DATABASE_URL check will happen at runtime when pool is actually used
|
||||
// During build time, this won't fail even if DATABASE_URL is not set
|
||||
const pool = new Pool({
|
||||
connectionString: process.env.DATABASE_URL || "postgresql://localhost:5432/temp",
|
||||
max: 20,
|
||||
idleTimeoutMillis: 30000,
|
||||
connectionTimeoutMillis: 10000,
|
||||
ssl: process.env.DATABASE_SSL === "true" ? { rejectUnauthorized: false } : false,
|
||||
});
|
||||
|
||||
// Test connection on startup
|
||||
pool.on("error", (err) => {
|
||||
console.error("Unexpected error on idle client", err);
|
||||
});
|
||||
|
||||
// Validate DATABASE_URL at runtime (not during build)
|
||||
if (process.env.NODE_ENV === "production" && !process.env.DATABASE_URL) {
|
||||
console.warn("WARNING: DATABASE_URL is not set. Database operations will fail.");
|
||||
}
|
||||
|
||||
export const db = drizzle(pool);
|
||||
Reference in New Issue
Block a user