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

try {
    $pdo = db();
    $sql = "CREATE TABLE IF NOT EXISTS `user_roles` (
        `user_id` INT(11) UNSIGNED NOT NULL,
        `role_id` INT(11) UNSIGNED NOT NULL,
        PRIMARY KEY (`user_id`, `role_id`),
                FOREIGN KEY (`user_id`) REFERENCES `people`(`id`) ON DELETE CASCADE,
        FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
    $pdo->exec($sql);
    echo "Table 'user_roles' created successfully." . PHP_EOL;
} catch (PDOException $e) {
    echo "Error creating table 'user_roles': " . $e->getMessage() . PHP_EOL;
    exit(1);
}
