Update dependencies and logic in `server/db.ts` to use either the standard PostgreSQL driver or the Neon serverless driver based on the environment, along with configuration adjustments in `ecosystem.config.cjs`. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 42d8028a-fa71-4ec2-938c-e43eedf7df01 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/42d8028a-fa71-4ec2-938c-e43eedf7df01/EAVbbe1
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
// Integration: javascript_database blueprint
|
|
import { Pool as NeonPool, neonConfig } from '@neondatabase/serverless';
|
|
import { drizzle as drizzleNeon } from 'drizzle-orm/neon-serverless';
|
|
import { drizzle as drizzlePg } from 'drizzle-orm/node-postgres';
|
|
import { Pool as PgPool } from 'pg';
|
|
import ws from "ws";
|
|
import * as schema from "@shared/schema";
|
|
|
|
if (!process.env.DATABASE_URL) {
|
|
throw new Error(
|
|
"DATABASE_URL must be set. Did you forget to provision a database?",
|
|
);
|
|
}
|
|
|
|
// Usa driver standard PostgreSQL per server locale, Neon per cloud
|
|
const isLocalDb = process.env.DATABASE_URL.includes('localhost') ||
|
|
process.env.DATABASE_URL.includes('127.0.0.1') ||
|
|
process.env.DOMAIN === 'vt.alfacom.it';
|
|
|
|
let pool: NeonPool | PgPool;
|
|
let db: any; // Type unification per drizzle
|
|
|
|
if (isLocalDb) {
|
|
console.log("🗄️ Usando driver PostgreSQL standard (locale)");
|
|
pool = new PgPool({ connectionString: process.env.DATABASE_URL });
|
|
db = drizzlePg(pool, { schema });
|
|
} else {
|
|
console.log("🗄️ Usando driver Neon serverless (cloud)");
|
|
neonConfig.webSocketConstructor = ws;
|
|
pool = new NeonPool({ connectionString: process.env.DATABASE_URL });
|
|
db = drizzleNeon({ client: pool, schema });
|
|
}
|
|
|
|
export { pool, db };
|