/**
 * Adds meet_url + classroom_url columns to lesson_plans.
 *
 * Originally introduced on feat/p1-ux-3-meet-classroom (commit 64d6389)
 * but dev hadn't picked it up yet. Class Room (P1-UX-7 §9) needs the
 * same columns so the VC/VM buttons render. Applied to dev here so the
 * slices are independent of each other.
 *
 * Idempotent: each ADD COLUMN is wrapped in a try/catch swallow so re-
 * applying this migration against an already-migrated DB is a no-op,
 * matching the convention used by the rest of the migrations folder.
 */

exports.up = async function (knex) {
  try {
    await knex.schema.raw('ALTER TABLE lesson_plans ADD COLUMN meet_url TEXT');
    console.log('[migrate:2026-07-17b] lesson_plans.meet_url added');
  } catch (err) {
    if (!/duplicate column|already exists/i.test(String(err && err.message))) {
      throw err;
    }
  }
  try {
    await knex.schema.raw('ALTER TABLE lesson_plans ADD COLUMN classroom_url TEXT');
    console.log('[migrate:2026-07-17b] lesson_plans.classroom_url added');
  } catch (err) {
    if (!/duplicate column|already exists/i.test(String(err && err.message))) {
      throw err;
    }
  }
};

exports.down = async function (knex) {
  await knex.schema.raw('ALTER TABLE lesson_plans DROP COLUMN meet_url');
  await knex.schema.raw('ALTER TABLE lesson_plans DROP COLUMN classroom_url');
};
