<?php
/**
 * Migration: Add is_fourth_subject column to student_subjects table
 * This column is required for the fourth subject feature
 */

require_once '../config/database.php';

echo "Adding is_fourth_subject column to student_subjects table...\n";

try {
    // Check if the column already exists
    $stmt = $pdo->prepare("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'student_subjects' AND COLUMN_NAME = 'is_fourth_subject' AND TABLE_SCHEMA = (SELECT DATABASE())");
    $stmt->execute();
    $column_exists = $stmt->fetch();

    if ($column_exists) {
        echo "✓ is_fourth_subject column already exists\n";
    } else {
        // Add the column
        $pdo->exec("ALTER TABLE student_subjects ADD COLUMN is_fourth_subject BOOLEAN DEFAULT FALSE AFTER subject_id");
        echo "✓ is_fourth_subject column added successfully\n";
    }

} catch (Exception $e) {
    echo "✗ Error adding is_fourth_subject column: " . $e->getMessage() . "\n";
    exit(1);
}

echo "Migration completed successfully!\n";
?>