'use strict';

const { Pool } = require('pg');
const fs = require('fs');
const path = require('path');
try { require('dotenv').config(); } catch {}

const pool = new Pool({
  user: process.env.DB_USER || 'homeschool_user',
  password: process.env.DB_PASSWORD,
  host: process.env.DB_HOST || 'localhost',
  port: Number(process.env.DB_PORT || 5432),
  database: process.env.DB_NAME || 'jnm_homeschool_db'
});

(async () => {
  const sql = fs.readFileSync(path.join(__dirname, 'v33-student-menu-controls.sql'), 'utf8');
  await pool.query(sql);
  console.log('PASS: V33 student menu-control database table is ready.');
})().catch(error => {
  console.error('FAIL: V33 database update failed:', error.message);
  process.exitCode = 1;
}).finally(async () => {
  try { await pool.end(); } catch {}
});
