// Idempotent schema migration. Mirrors LabWise's server/src/db/migrate.ts — // reads schema.sql and runs it through the same env-driven pg config the app // uses, then exits. Compose's CMD chains this before `node index.js`. const fs = require('fs'); const path = require('path'); const { Pool } = require('pg'); async function migrate() { const sql = fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf-8'); const pool = new Pool(); try { await pool.query(sql); console.log('[migrate] schema applied'); } finally { await pool.end(); } } migrate().catch((err) => { console.error('[migrate] failed:', err); process.exit(1); });