mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-20 13:38:15 +02:00
Configure production database connection for increased reliability
Updates the server-side database configuration to use standard PostgreSQL for production environments, ensuring a more robust and reliable connection. Previously, it might have defaulted to a different setup or encountered connection issues. Replit-Commit-Author: Agent Replit-Commit-Session-Id: d396e5bd-e32d-4a20-9e7d-71e7102ddc6c Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/d396e5bd-e32d-4a20-9e7d-71e7102ddc6c/CrwFq15
This commit is contained in:
1 parent
2aecaa2672
commit
22a6c5d7f6
6 files changed
+305
-15
No files matched your search
+57
-10
@@ -1,15 +1,62 @@
|
||||
import { Pool, neonConfig } from '@neondatabase/serverless';
|
||||
import { drizzle } from 'drizzle-orm/neon-serverless';
|
||||
import ws from "ws";
|
||||
import * as schema from "@shared/schema";
|
||||
|
||||
neonConfig.webSocketConstructor = ws;
|
||||
// Simple environment detection
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
const dbUrl = process.env.DATABASE_URL;
|
||||
|
||||
if (!process.env.DATABASE_URL) {
|
||||
throw new Error(
|
||||
"DATABASE_URL must be set. Did you forget to provision a database?",
|
||||
);
|
||||
console.log('🔗 Database initialization:', {
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
isProduction,
|
||||
hasDbUrl: !!dbUrl,
|
||||
dbHost: dbUrl ? new URL(dbUrl).hostname : 'none'
|
||||
});
|
||||
|
||||
let db: any;
|
||||
let pool: any;
|
||||
|
||||
if (isProduction && dbUrl && (dbUrl.includes('logiflow-db') || dbUrl.includes('localhost') || dbUrl.includes('127.0.0.1'))) {
|
||||
// Standard PostgreSQL for production Docker
|
||||
console.log('🐳 PRODUCTION: Using standard PostgreSQL');
|
||||
const { Pool } = await import('pg');
|
||||
const { drizzle } = await import('drizzle-orm/node-postgres');
|
||||
|
||||
pool = new Pool({
|
||||
connectionString: dbUrl,
|
||||
ssl: false,
|
||||
max: 10,
|
||||
idleTimeoutMillis: 30000,
|
||||
connectionTimeoutMillis: 5000,
|
||||
});
|
||||
|
||||
db = drizzle({ client: pool, schema });
|
||||
|
||||
// Test connection
|
||||
try {
|
||||
await pool.connect().then(client => {
|
||||
console.log('✅ PostgreSQL connection test successful');
|
||||
client.release();
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('❌ PostgreSQL connection test failed:', error);
|
||||
}
|
||||
} else {
|
||||
// Fallback: use Neon for development (but will be overridden by MemStorage)
|
||||
console.log('🔧 DEV: Using Neon (fallback, will use MemStorage)');
|
||||
const { Pool, neonConfig } = await import('@neondatabase/serverless');
|
||||
const { drizzle } = await import('drizzle-orm/neon-serverless');
|
||||
const ws = await import('ws');
|
||||
|
||||
neonConfig.webSocketConstructor = ws.default;
|
||||
|
||||
if (dbUrl) {
|
||||
pool = new Pool({ connectionString: dbUrl });
|
||||
db = drizzle({ client: pool, schema });
|
||||
} else {
|
||||
// Create dummy instances for development
|
||||
pool = null;
|
||||
db = null;
|
||||
console.log('🔧 DEV: No DATABASE_URL, using MemStorage');
|
||||
}
|
||||
}
|
||||
|
||||
export const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
||||
export const db = drizzle({ client: pool, schema });
|
||||
export { db, pool };
|
||||
Reference in new issue
Block a user