<?php
/**
 * Script to update existing exam records to ensure they have the new custom institution fields
 */

echo "Updating existing exam records with default values for custom institution fields...\n";

try {
    // Database connection
    require_once __DIR__ . '/../config/database.php';
    
    // Update all existing exams to have NULL values for the new fields
    $sql = "UPDATE exams SET custom_institution_name = NULL, custom_institution_address = NULL WHERE custom_institution_name IS NULL OR custom_institution_address IS NULL";
    
    $stmt = $pdo->prepare($sql);
    $stmt->execute();
    
    $rowCount = $stmt->rowCount();
    
    echo "SUCCESS: Updated $rowCount exam records with default values for custom institution fields.\n";
    
} catch (Exception $e) {
    echo "ERROR: " . $e->getMessage() . "\n";
    exit(1);
}

echo "Update completed.\n";