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

try {
    $pdo = db();
    $migrationFiles = glob(__DIR__ . '/db/migrations/*.sql');
    sort($migrationFiles);
    
    foreach ($migrationFiles as $file) {
        $sql = file_get_contents($file);
        $statements = explode(';', $sql);
        foreach ($statements as $statement) {
            $statement = trim($statement);
            if ($statement) {
                $pdo->exec($statement);
            }
        }
        echo "Executed: " . basename($file) . "\n";
    }
    echo "All migrations completed successfully!\n";
} catch (Exception $e) {
    echo "Migration failed: " . $e->getMessage() . "\n";
}
