require('dotenv').config(); const { Pool } = require('pg'); const TABLES = [ 'permissions', 'role_permissions', 'branches', 'categories', 'skus', 'customers', 'suppliers', 'system_configs', 'customer_processing_aliases', ]; (async () => { const pool = new Pool({ connectionString: process.env.DATABASE_URL }); const out = { label: process.env.SNAPSHOT_LABEL || 'env', counts: {} }; for (const table of TABLES) { const reg = await pool.query(`SELECT to_regclass('public.' || $1) AS t`, [table]); if (!reg.rows[0].t) { out.counts[table] = null; continue; } const r = await pool.query(`SELECT count(*)::int AS c FROM ${table}`); out.counts[table] = r.rows[0].c; } console.log(JSON.stringify(out, null, 2)); await pool.end(); })().catch((e) => { console.error(e); process.exit(1); });