<?php
/**
 * Migration to add custom institution name and address fields to exams table
 */

// This script adds custom institution fields to the exams table
// These fields allow overriding the site-wide settings for specific exam routines

echo "Adding custom institution fields to exams table...\n";

try {
    // Database connection
    require_once __DIR__ . '/../config/database.php';
    
    // Add columns for custom institution name and address
    $sql = "
        ALTER TABLE exams 
        ADD COLUMN custom_institution_name VARCHAR(255) NULL DEFAULT NULL,
        ADD COLUMN custom_institution_address VARCHAR(255) NULL DEFAULT NULL
    ";
    
    $pdo->exec($sql);
    
    echo "SUCCESS: Custom institution fields added to exams table.\n";
    echo "Fields added:\n";
    echo "  - custom_institution_name (VARCHAR 255)\n";
    echo "  - custom_institution_address (VARCHAR 255)\n";
    
} catch (Exception $e) {
    if (strpos($e->getMessage(), 'Duplicate column name') !== false) {
        echo "INFO: Columns already exist. No changes made.\n";
    } else {
        echo "ERROR: " . $e->getMessage() . "\n";
        exit(1);
    }
}

echo "Migration completed.\n";