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

function run_migrations() {
    $pdo = db();
    $migrationsDir = __DIR__ . '/migrations';
    $files = glob($migrationsDir . '/*.sql');
    sort($files);

    foreach ($files as $file) {
        echo "Running migration: " . basename($file) . "\n";
        $sql = file_get_contents($file);
        try {
            $pdo->exec($sql);
            echo "Success.\n";
        } catch (PDOException $e) {
            echo "Error: " . $e->getMessage() . "\n";
            // A simple way to track which migrations have been run is needed
            // For now, we'll just stop on error.
            exit(1);
        }
    }
}

run_migrations();

