#!/usr/bin/env node /** * Backfill pgmigrations.run_on for 1783000000001 so `npm run migrate up` * passes node-pg-migrate order check on homelab DBs that applied pricing * DDL out of timestamp sequence (pricing convoy branch merged after frame migrations). * * Requires POSTGRES_URL_DIRECT (homelab deckhearth URL). * * Usage: * node --env-file=.env.local scripts/fix-pricing-pgmigration-order.js */ import postgres from 'postgres'; function requireEnv(name) { const value = process.env[name]?.trim(); if (!value) { console.error(`❌ ${name} is required`); process.exit(1); } return value; } const MIGRATION_NAME = '1783000000001_add-pricing-schema'; /** Between 1782000000001 (embeddings) and 1786757312884 (visibility index). */ const RUN_ON = '2026-06-15 12:00:00+00'; async function main() { const url = requireEnv('POSTGRES_URL_DIRECT'); const isPrivateLan = /(?:^|@)(?:localhost|127\.0\.0\.1|192\.168\.|10\.|172\.(?:1[6-9]|2\d|3[01])\.)/.test(url); const sql = postgres(url, { ssl: isPrivateLan ? false : 'require', max: 1 }); try { const existing = await sql` SELECT name, run_on FROM pgmigrations WHERE name = ${MIGRATION_NAME} `; if (existing.length === 0) { console.error(`❌ No pgmigrations row for ${MIGRATION_NAME}. Run pricing migration SQL first.`); process.exit(1); } const before = existing[0].run_on; await sql` UPDATE pgmigrations SET run_on = ${RUN_ON}::timestamptz WHERE name = ${MIGRATION_NAME} `; console.log(`✅ Updated ${MIGRATION_NAME}`); console.log(` run_on: ${before} → ${RUN_ON}`); console.log('Next: npm run migrate up'); } finally { await sql.end({ timeout: 5 }); } } main().catch((err) => { console.error(err.message || err); process.exit(1); });