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

$migrationsDir = __DIR__ . '/../database/migrations';
$files = glob($migrationsDir . '/*.sql');
sort($files);
$db = Database::getInstance();

foreach ($files as $file) {
    echo "Applying migration: " . basename($file) . PHP_EOL;
    $sql = file_get_contents($file);
    try {
        // Execute multi-statement
        $db->getConnection()->exec($sql);
        echo "Applied: " . basename($file) . PHP_EOL;
    } catch (PDOException $e) {
        echo "Error applying " . basename($file) . ": " . $e->getMessage() . PHP_EOL;
    }
}

echo "Done." . PHP_EOL;
