<?php
// Script to create learning_materials_specific_students table
require_once 'config/database.php';

try {
    // Create learning_materials_specific_students table
    $sql = "
    CREATE TABLE IF NOT EXISTS learning_materials_specific_students (
        id INT(11) NOT NULL AUTO_INCREMENT,
        material_id INT(11) NOT NULL,
        student_id INT(11) NOT NULL,
        created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (id),
        FOREIGN KEY (material_id) REFERENCES learning_materials(id) ON DELETE CASCADE,
        FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE,
        UNIQUE KEY unique_material_student (material_id, student_id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
    ";
    
    $pdo->exec($sql);
    
    echo "Learning materials specific students table created successfully!\n";
    
} catch (Exception $e) {
    echo "Error creating table: " . $e->getMessage() . "\n";
}
?>