<?php
require_once __DIR__ . '/config.php';
$db = db();

try {
    // Create faction_alliances table
    $db->exec("CREATE TABLE IF NOT EXISTS faction_alliances (
        id INT AUTO_INCREMENT PRIMARY KEY,
        faction_id_1 INT NOT NULL,
        faction_id_2 INT NOT NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        UNIQUE KEY unique_alliance (faction_id_1, faction_id_2),
        FOREIGN KEY (faction_id_1) REFERENCES factions(id) ON DELETE CASCADE,
        FOREIGN KEY (faction_id_2) REFERENCES factions(id) ON DELETE CASCADE
    )");
    echo "Table 'faction_alliances' created or already exists.\n";
} catch (PDOException $e) {
    die("Migration failed: " . $e->getMessage());
}

