import { pool } from '../src/lib/db.js'; // Idempotent migration using the project's DB pool: add `featured` TINYINT(1) to `menus` if missing // Usage: node scripts/add-featured-column.mjs async function columnExists(connection) { const dbName = process.env.DB_NAME || 'warme'; const [rows] = await connection.query( `SELECT COUNT(*) as cnt FROM information_schema.columns WHERE table_schema = ? AND table_name = 'menus' AND column_name = 'featured'`, [dbName] ); return rows[0].cnt > 0; } async function run() { const connection = await pool.getConnection(); try { const exists = await columnExists(connection); if (exists) { console.log('Column `featured` already exists on `menus`. Nothing to do.'); return; } console.log('Adding `featured` column to `menus`...'); await connection.query(`ALTER TABLE menus ADD COLUMN featured TINYINT(1) NOT NULL DEFAULT 0`); console.log('Column added. Ensuring existing rows have 0...'); await connection.query(`UPDATE menus SET featured = 0 WHERE featured IS NULL`); console.log('Migration completed successfully.'); } finally { connection.release(); await pool.end(); } } run().then(() => process.exit(0)).catch((err) => { console.error('Migration failed:', err); process.exit(1); });