require('dotenv').config(); const { Pool } = require('pg'); (async () => { const pool = new Pool({ connectionString: process.env.DATABASE_URL }); const migrations = await pool.query( `SELECT filename FROM schema_migrations ORDER BY filename` ); const tables = await pool.query(` SELECT tablename FROM pg_tables WHERE schemaname = 'public' ORDER BY tablename `); const configs = await pool.query(` SELECT config_key, branch_code, md5(config_value::text) AS value_hash, length(config_value::text) AS value_len, updated_at FROM system_configs ORDER BY config_key, branch_code NULLS FIRST `); const criticalTables = [ 'customer_processing_aliases', 'customer_recipients', 'product_substitutions', 'delivery_signatures', 'picking_tasks', 'processing_tasks', 'customer_quote_versions', ]; const exists = {}; for (const t of criticalTables) { const r = await pool.query(`SELECT to_regclass('public.' || $1) AS reg`, [t]); exists[t] = Boolean(r.rows[0].reg); } const gitVersion = process.env.SNAPSHOT_LABEL || 'unknown'; console.log( JSON.stringify( { label: gitVersion, at: new Date().toISOString(), migrations: migrations.rows.map((r) => r.filename), tables: tables.rows.map((r) => r.tablename), configs: configs.rows, criticalTables: exists, }, null, 2 ) ); await pool.end(); })().catch((e) => { console.error(e); process.exit(1); });