Files
mercadodevida/project/scripts/db-status.mjs
rikrdo 425fedd13e feat(F-002): database foundation with migrations and dev compose
- node-pg-migrate + pg: baseline migration (extensions, app_meta) with working down
- src/infrastructure/db fail-fast pool and typed query helper
- docker-compose: postgres:16-alpine + redis:7-alpine with one-command up
- table naming convention <module>_<table> documented in README
- integration tests (6) against real PostgreSQL; strict identifier validation
  for test DDL after security-gate hardening round
- deps justified in spec/tech.md; all gates approved; verify.sh green
2026-08-14 22:00:16 +02:00

32 lines
858 B
JavaScript

#!/usr/bin/env node
/**
* db:status — list applied migrations from the pg_migrations tracking table.
* Usage: DATABASE_URL=... node scripts/db-status.mjs
*/
import pg from 'pg';
import process from 'node:process';
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
console.error('DATABASE_URL is required');
process.exit(2);
}
const pool = new pg.Pool({ connectionString, max: 1 });
try {
const result = await pool.query('SELECT id, name, run_on FROM pgmigrations ORDER BY id');
if (result.rows.length === 0) {
console.log('No migrations applied.');
} else {
for (const row of result.rows) {
console.log(`${row.id}\t${row.name}\t(applied ${row.run_on})`);
}
}
} catch (error) {
console.error('Failed to read migration status', error);
process.exitCode = 1;
} finally {
await pool.end();
}