31 lines
1.0 KiB
PHP
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");
|
|
}
|
|
|