Ensure PostgreSQL tables are created and data is migrated

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
This commit is contained in:
michaelschal committed 2025-08-16 13:27:09 +00:00
1 parent a3889dd088
commit b1ea9dcc9b
4 files changed
+47 -39

No files matched your search

+10 -20
View File
@@ -14,15 +14,15 @@ console.log('🔗 Database initialization:', {
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');
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: false,
ssl: dbUrl.includes('localhost') ? false : { rejectUnauthorized: false },
max: 10,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 5000,
@@ -38,25 +38,15 @@ if (isProduction && dbUrl && (dbUrl.includes('logiflow-db') || dbUrl.includes('l
});
} 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
// Continue anyway, will use MemStorage as fallback
pool = null;
db = null;
console.log('🔧 DEV: No DATABASE_URL, using MemStorage');
}
} else {
// Development fallback: use MemStorage
console.log('🔧 DEV: Using MemStorage (development fallback)');
pool = null;
db = null;
}
export { db, pool };