mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-12 09:47:54 +02:00
Update database connection to use standard PG client for migrations
Switches the production migration script from Neon's `neon` client to the standard `pg` client, improving connection robustness and compatibility. Also includes error handling and connection closing for migrations. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 31f9bd88-0285-4787-81b3-31ceeea5a08b Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/31f9bd88-0285-4787-81b3-31ceeea5a08b/hP2S4TA
This commit is contained in:
1 parent
27ae1a836f
commit
c734ea0ca2
2 files changed
+217
-15
No files matched your search
@@ -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