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

try {
    $pdo = db();

    // Add bni_group_id to people table
    $stmt = $pdo->query("SHOW COLUMNS FROM people LIKE 'bni_group_id'");
    if ($stmt->rowCount() == 0) {
        $pdo->exec("ALTER TABLE people ADD COLUMN bni_group_id INT NULL AFTER `role`;");
        $pdo->exec("ALTER TABLE people ADD CONSTRAINT fk_people_bni_group FOREIGN KEY (bni_group_id) REFERENCES bni_groups(id) ON DELETE SET NULL;");
    }

    echo "Migration 017 completed successfully." . PHP_EOL;

} catch (PDOException $e) {
    die("Migration 017 failed: " . $e->getMessage());
}
?>