37338-vm/db/migrations/016_create_calendar_event_groups_table.php
2026-01-10 09:20:40 +00:00

31 lines
1.0 KiB
PHP

<?php
require_once __DIR__ . '/../../db/config.php';
try {
$pdo = db();
// Check if table calendar_event_groups already exists
$stmt = $pdo->query("SHOW TABLES LIKE 'calendar_event_groups'");
$table_exists = $stmt->rowCount() > 0;
if (!$table_exists) {
$pdo->exec("
CREATE TABLE `calendar_event_groups` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`calendar_event_id` INT NOT NULL,
`bni_group_id` INT NOT NULL,
FOREIGN KEY (`calendar_event_id`) REFERENCES `calendar_events`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`bni_group_id`) REFERENCES `bni_groups`(`id`) ON DELETE CASCADE,
UNIQUE KEY `unique_event_group` (`calendar_event_id`, `bni_group_id`)
)
");
echo "Table 'calendar_event_groups' created successfully.\n";
} else {
echo "Table 'calendar_event_groups' already exists.\n";
}
} catch (PDOException $e) {
die("Migration failed: " . $e->getMessage() . "\n");
}