require('dotenv').config(); const fs = require('fs'); const path = require('path'); const pool = require('../server/db'); async function main() { const sqlPath = path.join(__dirname, '../db/migrate-checkup-flags.sql'); const sql = fs.readFileSync(sqlPath, 'utf8'); await pool.query(sql); await pool.query( `UPDATE paintings SET checkup_checked = true WHERE checkup_fixed = true AND NOT checkup_checked` ); const { rows } = await pool.query(` SELECT COUNT(*) FILTER (WHERE checkup_checked)::int AS checked, COUNT(*) FILTER (WHERE checkup_fixed)::int AS fixed FROM paintings `); console.log(`checkup flags ready (${rows[0].checked} checked, ${rows[0].fixed} fixed)`); await pool.end(); } main().catch((err) => { console.error(err); process.exit(1); });