mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
This commit modifies the database connection logic to prioritize PostgreSQL, introduces a new PostgreSQL initialization script with table creation and test data, and refactors announcement storage to use a global instance. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce/zIqUatC
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import * as schema from "@shared/schema";
|
|
|
|
// Simple environment detection
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
const dbUrl = process.env.DATABASE_URL;
|
|
|
|
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 (dbUrl && (isProduction || process.env.FORCE_POSTGRES === 'true')) {
|
|
// Use PostgreSQL for production or when forced
|
|
console.log('🐘 Using PostgreSQL database');
|
|
const { Pool } = await import('pg');
|
|
const { drizzle } = await import('drizzle-orm/node-postgres');
|
|
|
|
pool = new Pool({
|
|
connectionString: dbUrl,
|
|
ssl: dbUrl.includes('localhost') ? false : { rejectUnauthorized: false },
|
|
max: 10,
|
|
idleTimeoutMillis: 30000,
|
|
connectionTimeoutMillis: 5000,
|
|
});
|
|
|
|
db = drizzle({ client: pool, schema });
|
|
|
|
// Test connection
|
|
try {
|
|
await pool.connect().then((client: any) => {
|
|
console.log('✅ PostgreSQL connection test successful');
|
|
client.release();
|
|
});
|
|
} catch (error) {
|
|
console.error('❌ PostgreSQL connection test failed:', error);
|
|
// Continue anyway, will use MemStorage as fallback
|
|
pool = null;
|
|
db = null;
|
|
}
|
|
} else {
|
|
// Development fallback: use MemStorage
|
|
console.log('🔧 DEV: Using MemStorage (development fallback)');
|
|
pool = null;
|
|
db = null;
|
|
}
|
|
|
|
export { db, pool }; |