37338-vm/db/migrations/009_create_user_roles_table.php
2026-01-10 07:48:27 +00:00

19 lines
672 B
PHP

<?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);
}