mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Merge pull request #117 from R0m1k3/1.1
Update database connection to use standard PG client for migrations
This commit is contained in:
2 files changed
+217
-15
No files matched your search
+195
@@ -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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user