<?php
require_once 'config.php';
require_once 'includes/Database.php';

$db = new Database();

$migrationFile = 'migrations/add_criteria_history.sql';

if (!file_exists($migrationFile)) {
    die("Migration file not found: $migrationFile\n");
}

$sql = file_get_contents($migrationFile);

// SQL'i noktalı virgüle göre ayır ve çalıştır
$queries = array_filter(array_map('trim', explode(';', $sql)));

foreach ($queries as $query) {
    // Boş ve yorum satırlarını atla
    if (empty($query) || stripos($query, '--') === 0) {
        continue;
    }

    try {
        $db->query($query);
        echo "✓ Executed: " . substr(str_replace("\n", " ", $query), 0, 80) . "...\n";
    } catch (Exception $e) {
        echo "✗ Error: " . $e->getMessage() . "\n";
        echo "  Query: " . substr($query, 0, 100) . "...\n";
    }
}

echo "\nMigration completed!\n";
