mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-12 01:37:40 +02:00
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
This commit is contained in:
1 parent
59389aa08d
commit
1ef584c823
1 file changed
+73
@@ -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);
|
||||
Reference in new issue
Block a user