<?php
// Script to update exam_questions table with new columns

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

try {
    // Add chapter_topic column
    $sql = "ALTER TABLE `exam_questions` ADD COLUMN `chapter_topic` varchar(255) DEFAULT NULL";
    $pdo->exec($sql);
    echo "Added chapter_topic column to exam_questions table\n";
    
    // Add difficulty_level column
    $sql = "ALTER TABLE `exam_questions` ADD COLUMN `difficulty_level` enum('easy','medium','hard') DEFAULT 'medium'";
    $pdo->exec($sql);
    echo "Added difficulty_level column to exam_questions table\n";
    
    // Add is_starred column
    $sql = "ALTER TABLE `exam_questions` ADD COLUMN `is_starred` tinyint(1) DEFAULT 0";
    $pdo->exec($sql);
    echo "Added is_starred column to exam_questions table\n";
    
    echo "All columns added successfully!\n";
    
} catch (PDOException $e) {
    // Check if the error is because columns already exist
    if (strpos($e->getMessage(), 'Duplicate column name') !== false) {
        echo "Columns already exist in exam_questions table\n";
    } else {
        echo "Error: " . $e->getMessage() . "\n";
    }
}

?>