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

try {
    // Create result_publications table if it doesn't exist
    $pdo->exec("
        CREATE TABLE IF NOT EXISTS result_publications (
            id INT AUTO_INCREMENT PRIMARY KEY,
            session VARCHAR(10) NOT NULL,
            exam_type VARCHAR(50) NOT NULL,
            class_id INT NOT NULL,
            status ENUM('draft', 'published', 'archived') DEFAULT 'draft',
            publish_date DATETIME,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            FOREIGN KEY (class_id) REFERENCES classes(id) ON DELETE CASCADE,
            UNIQUE KEY unique_session_exam_class (session, exam_type, class_id)
        )
    ");
    
    echo "Result publications table created or already exists.\n";
} catch (PDOException $e) {
    echo "Error creating table: " . $e->getMessage() . "\n";
}
?>