<?php
require_once __DIR__ . '/../../db/config.php';

$db = db();

// Step 1: Back-fill bni_group_id from group_id where bni_group_id is NULL
$db->exec("UPDATE meetings SET bni_group_id = group_id WHERE bni_group_id IS NULL");

// Step 2: Modify bni_group_id to be NOT NULL
$db->exec("ALTER TABLE meetings MODIFY COLUMN bni_group_id INT(11) NOT NULL");

// Step 3: Find and drop the foreign key constraint on group_id
$db->exec("ALTER TABLE meetings DROP FOREIGN KEY `meetings_ibfk_1`");

// Step 4: Drop the old group_id column
$db->exec("ALTER TABLE meetings DROP COLUMN group_id");

echo "Migration 035 cleanup meetings table applied successfully.";
