36766-vm/db/migration_012_create_notifications_table.php
Flatlogic Bot 6c14b2436f 2.0
2025-12-18 09:40:37 +00:00

23 lines
703 B
PHP

<?php
require_once __DIR__ . '/config.php';
try {
$pdo = db();
$sql = <<<SQL
CREATE TABLE IF NOT EXISTS notifications (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
service_request_id INT NOT NULL,
message VARCHAR(255) NOT NULL,
is_read BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (service_request_id) REFERENCES service_requests(id) ON DELETE CASCADE
);
SQL;
$pdo->exec($sql);
echo "Migration for notifications table applied successfully." . PHP_EOL;
} catch (PDOException $e) {
die("Migration failed: " . $e->getMessage());
}