From d4878e6c8ff07b2e087344fe0a86e1d3900ba55c Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Tue, 12 Aug 2025 08:20:19 +0000 Subject: [PATCH] Fix database schema inspection on production servers Update database connection logic in `routes.ts` to use the established `pool` for schema inspection queries, resolving issues with data retrieval on production environments. Replit-Commit-Author: Agent Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/kdCs97W --- server/routes.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/routes.ts b/server/routes.ts index 707cd85..b317599 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -3,6 +3,7 @@ import { createServer, type Server } from "http"; import { storage } from "./storage"; import { setupLocalAuth, requireAuth } from "./localAuth"; import { requireModulePermission, requireAdmin } from "./permissions"; +import { db, pool } from "./db"; console.log('🔍 Using development storage and authentication'); @@ -1405,6 +1406,11 @@ export async function registerRoutes(app: Express): Promise { console.log('\n🔍 ===== DÉBUT SCAN SCHÉMA BASE DE DONNÉES ====='); console.log('⏰ Timestamp:', new Date().toISOString()); + // VĂ©rifier que pool est disponible + if (!pool) { + throw new Error('Pool de base de donnĂ©es non disponible en production'); + } + // RĂ©cupĂ©rer les tables const tablesQuery = ` SELECT table_name @@ -1413,7 +1419,7 @@ export async function registerRoutes(app: Express): Promise { ORDER BY table_name `; - const tablesResult = await (storage as any).db.query(tablesQuery); + const tablesResult = await pool.query(tablesQuery); console.log(`\n📊 TOTAL DES TABLES TROUVÉES: ${tablesResult.rows.length}`); console.log('=========================================='); @@ -1439,7 +1445,7 @@ export async function registerRoutes(app: Express): Promise { ORDER BY ordinal_position `; - const columnsResult = await (storage as any).db.query(columnsQuery, [tableName]); + const columnsResult = await pool.query(columnsQuery, [tableName]); if (columnsResult.rows.length > 0) { columnsResult.rows.forEach((col, index) => { @@ -1453,7 +1459,7 @@ export async function registerRoutes(app: Express): Promise { // Compter les enregistrements dans la table try { const countQuery = `SELECT COUNT(*) as total FROM "${tableName}"`; - const countResult = await (storage as any).db.query(countQuery); + const countResult = await pool.query(countQuery); console.log(` 📈 Nombre d'enregistrements: ${countResult.rows[0].total}`); } catch (countError) { console.log(` ⚠ Impossible de compter les enregistrements: ${countError.message}`); @@ -1484,7 +1490,7 @@ export async function registerRoutes(app: Express): Promise { ORDER BY tc.table_name, kcu.column_name `; - const fkResult = await (storage as any).db.query(fkQuery); + const fkResult = await pool.query(fkQuery); if (fkResult.rows.length > 0) { fkResult.rows.forEach(fk => {