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

try {
    $database = new Database();
    $conn = $database->getConnection();
    
    // Read and execute the schema file
    $schemaFile = __DIR__ . '/database/tasks_schema.sql';
    $schema = file_get_contents($schemaFile);
    
    if ($conn) {
        // Split by semicolons and execute each statement
        $statements = array_filter(array_map('trim', explode(';', $schema)));
        
        foreach ($statements as $statement) {
            if (!empty(trim($statement))) {
                echo "Executing: $statement\n";
                if ($conn->exec($statement)) {
                    echo "Success: $statement\n";
                } else {
                    echo "Error: $statement\n";
                }
            }
        }
        
        echo "Tasks table creation completed!\n";
        
    } else {
        echo "Database connection failed: " . $conn->errorInfo()[2] . "\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>
