diff --git a/attached_assets/Pasted--Environment-NODE-ENV-production-DATABASE-URL-Present-PORT-3000-Re-1755164310896_1755164310896.txt b/attached_assets/Pasted--Environment-NODE-ENV-production-DATABASE-URL-Present-PORT-3000-Re-1755164310896_1755164310896.txt new file mode 100644 index 0000000..164eed9 --- /dev/null +++ b/attached_assets/Pasted--Environment-NODE-ENV-production-DATABASE-URL-Present-PORT-3000-Re-1755164310896_1755164310896.txt @@ -0,0 +1,195 @@ + + +๐Ÿณ Environment: { NODE_ENV: 'production', DATABASE_URL: 'Present', PORT: '3000' } + +๐Ÿ”ง Registering all production routes... + +๐Ÿ”„ Running automatic production migrations... + +๐Ÿ”„ MIGRATION: Starting SAV production migrations... + +๐Ÿ”„ MIGRATION: Database URL configured: postgresql://logiflow_admin:Lo... + +๐Ÿ”„ MIGRATION: Checking if priority column exists... + +โŒ MIGRATION ERROR: Failed to run SAV production migrations: NeonDbError: Error connecting to database: fetch failed + + at execute (file:///app/node_modules/@neondatabase/serverless/index.mjs:1549:24) + + at process.processTicksAndRejections (node:internal/process/task_queues:95:5) + + at async runProductionMigrations (file:///app/dist/index.js:3263:33) + + at async registerProductionRoutes (file:///app/dist/index.js:6321:3) + + at async file:///app/dist/index.js:6369:1 { + + severity: undefined, + + code: undefined, + + detail: undefined, + + hint: undefined, + + position: undefined, + + internalPosition: undefined, + + internalQuery: undefined, + + where: undefined, + + schema: undefined, + + table: undefined, + + column: undefined, + + dataType: undefined, + + constraint: undefined, + + file: undefined, + + line: undefined, + + routine: undefined, + + sourceError: TypeError: fetch failed + + at node:internal/deps/undici/undici:13510:13 + + at process.processTicksAndRejections (node:internal/process/task_queues:95:5) + + at async execute (file:///app/node_modules/@neondatabase/serverless/index.mjs:1548:15) + + at async runProductionMigrations (file:///app/dist/index.js:3263:33) + + at async registerProductionRoutes (file:///app/dist/index.js:6321:3) + + at async file:///app/dist/index.js:6369:1 { + + [cause]: Error: connect ECONNREFUSED 172.20.0.10:443 + + at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1611:16) { + + errno: -111, + + code: 'ECONNREFUSED', + + syscall: 'connect', + + address: '172.20.0.10', + + port: 443 + + } + + } + +} + +โŒ MIGRATION ERROR: Error details: { + + message: 'Error connecting to database: fetch failed', + + code: undefined, + + stack: 'NeonDbError: Error connecting to database: fetch failed\n' + + + ' at execute (file:///app/node_modules/@neondatabase/serverless/index.mjs:1549:24)\n' + + + ' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' + + + ' at async runProductionMigrations (file:///app/dist/index.js:3263:33)\n' + + + ' at async registerProductionRoutes (file:///app/dist/index.js:6321:3)\n' + + + ' at async file:///app/dist/index.js:6369:1' + +} + +node:internal/modules/run_main:123 + + triggerUncaughtException( + + ^ + +NeonDbError: Error connecting to database: fetch failed + + at execute (file:///app/node_modules/@neondatabase/serverless/index.mjs:1549:24) + + at process.processTicksAndRejections (node:internal/process/task_queues:95:5) + + at async runProductionMigrations (file:///app/dist/index.js:3263:33) + + at async registerProductionRoutes (file:///app/dist/index.js:6321:3) + + at async file:///app/dist/index.js:6369:1 { + + severity: undefined, + + code: undefined, + + detail: undefined, + + hint: undefined, + + position: undefined, + + internalPosition: undefined, + + internalQuery: undefined, + + where: undefined, + + schema: undefined, + + table: undefined, + + column: undefined, + + dataType: undefined, + + constraint: undefined, + + file: undefined, + + line: undefined, + + routine: undefined, + + sourceError: TypeError: fetch failed + + at node:internal/deps/undici/undici:13510:13 + + at process.processTicksAndRejections (node:internal/process/task_queues:95:5) + + at async execute (file:///app/node_modules/@neondatabase/serverless/index.mjs:1548:15) + + at async runProductionMigrations (file:///app/dist/index.js:3263:33) + + at async registerProductionRoutes (file:///app/dist/index.js:6321:3) + + at async file:///app/dist/index.js:6369:1 { + + [cause]: Error: connect ECONNREFUSED 172.20.0.10:443 + + at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1611:16) { + + errno: -111, + + code: 'ECONNREFUSED', + + syscall: 'connect', + + address: '172.20.0.10', + + port: 443 + + } + + } + +} \ No newline at end of file diff --git a/server/migrations.production.ts b/server/migrations.production.ts index 5ba56bc..b4f6f09 100644 --- a/server/migrations.production.ts +++ b/server/migrations.production.ts @@ -1,4 +1,4 @@ -import { neon } from '@neondatabase/serverless'; +import { Client } from 'pg'; export async function runProductionMigrations() { const databaseUrl = process.env.DATABASE_URL; @@ -10,44 +10,50 @@ export async function runProductionMigrations() { console.log('๐Ÿ”„ MIGRATION: Starting SAV production migrations...'); console.log('๐Ÿ”„ MIGRATION: Database URL configured:', databaseUrl.substring(0, 30) + '...'); - const sql = neon(databaseUrl); + const client = new Client({ + connectionString: databaseUrl, + ssl: false, // No SSL for local Docker + }); try { + await client.connect(); + console.log('โœ… MIGRATION: Connected to PostgreSQL database'); + console.log('๐Ÿ”„ MIGRATION: Checking if priority column exists...'); // Vรฉrifier si la colonne priority existe - const checkPriorityColumn = await sql` + const checkPriorityColumn = await client.query(` SELECT 1 FROM information_schema.columns WHERE table_name='sav_tickets' AND column_name='priority' - `; + `); - console.log('๐Ÿ”„ MIGRATION: Priority column check result:', checkPriorityColumn.length); + console.log('๐Ÿ”„ MIGRATION: Priority column check result:', checkPriorityColumn.rows.length); - if (checkPriorityColumn.length === 0) { + if (checkPriorityColumn.rows.length === 0) { console.log('๐Ÿ“ MIGRATION: Priority column missing, adding it now...'); // Ajouter seulement la colonne priority manquante - await sql` + await client.query(` ALTER TABLE sav_tickets ADD COLUMN priority varchar(50) NOT NULL DEFAULT 'normale'; - `; + `); console.log('โœ… MIGRATION: Priority column added successfully!'); // Crรฉer les index pour optimiser les performances - await sql` + await client.query(` CREATE INDEX IF NOT EXISTS idx_sav_tickets_priority ON sav_tickets(priority); - `; + `); console.log('โœ… MIGRATION: Priority index created successfully!'); // Vรฉrification finale - const verificationResult = await sql` + const verificationResult = await client.query(` SELECT COUNT(*) as total_records, COUNT(CASE WHEN priority IS NOT NULL THEN 1 END) as records_with_priority FROM sav_tickets; - `; + `); console.log('โœ… MIGRATION: SAV migration completed successfully!'); - console.log('๐Ÿ“Š MIGRATION: Verification result:', verificationResult); + console.log('๐Ÿ“Š MIGRATION: Verification result:', verificationResult.rows[0]); } else { console.log('โœ… MIGRATION: Priority column already exists, skipping migration'); @@ -61,7 +67,8 @@ export async function runProductionMigrations() { stack: error?.stack }); // Ne pas faire รฉchouer le dรฉmarrage du serveur pour les erreurs de migration - // Mais logger l'erreur pour diagnostic - throw error; // Re-throw pour voir l'erreur dans les logs + } finally { + await client.end(); + console.log('๐Ÿ”Œ MIGRATION: Database connection closed'); } } \ No newline at end of file