From 1ef584c823b81ab70299a57abc15a092d2afd8e0 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Tue, 12 Aug 2025 07:59:42 +0000 Subject: [PATCH] Add script to log database table and field information Create a new Node.js script (debug-production-schema.js) that connects to the production PostgreSQL database, queries `information_schema` to retrieve all table names and their respective column details (name, type, nullability, default value), and logs this schema information to the console for debugging and analysis. 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/xTmsprA --- debug-production-schema.js | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 debug-production-schema.js diff --git a/debug-production-schema.js b/debug-production-schema.js new file mode 100644 index 0000000..3e3ce17 --- /dev/null +++ b/debug-production-schema.js @@ -0,0 +1,73 @@ +import { Client } from 'pg'; + +async function logProductionSchema() { + // URL de connexion à votre base de production + const productionDbUrl = process.env.DATABASE_URL_PRODUCTION || process.env.DATABASE_URL; + + if (!productionDbUrl) { + console.error('❌ DATABASE_URL_PRODUCTION ou DATABASE_URL non définie'); + return; + } + + const client = new Client({ + connectionString: productionDbUrl, + ssl: productionDbUrl.includes('neon.tech') ? { rejectUnauthorized: false } : false + }); + + try { + await client.connect(); + console.log('✅ Connecté à la base de production'); + + // Récupérer tous les noms de tables + const tablesQuery = ` + SELECT table_name + FROM information_schema.tables + WHERE table_schema = 'public' + ORDER BY table_name; + `; + + const tablesResult = await client.query(tablesQuery); + console.log('\n📋 TABLES DE LA BASE DE PRODUCTION:'); + console.log('====================================='); + + for (const row of tablesResult.rows) { + const tableName = row.table_name; + console.log(`\n🔸 Table: ${tableName}`); + + // Récupérer les colonnes de chaque table + const columnsQuery = ` + SELECT + column_name, + data_type, + is_nullable, + column_default + FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = $1 + ORDER BY ordinal_position; + `; + + const columnsResult = await client.query(columnsQuery, [tableName]); + + if (columnsResult.rows.length > 0) { + console.log(' Colonnes:'); + columnsResult.rows.forEach(col => { + const nullable = col.is_nullable === 'YES' ? 'NULL' : 'NOT NULL'; + const defaultVal = col.column_default ? ` DEFAULT ${col.column_default}` : ''; + console.log(` - ${col.column_name}: ${col.data_type} ${nullable}${defaultVal}`); + }); + } + } + + console.log('\n📊 RÉSUMÉ:'); + console.log(`Total des tables: ${tablesResult.rows.length}`); + + } catch (error) { + console.error('❌ Erreur lors de la connexion:', error.message); + } finally { + await client.end(); + } +} + +// Exécuter le script +logProductionSchema().catch(console.error); \ No newline at end of file