35539-vm/db/migrations/001_create_messages_table.php
Flatlogic Bot ca7f5831fa Contacts
2025-11-07 06:42:26 +00:00

22 lines
655 B
PHP

<?php
require_once __DIR__ . '/../config.php';
try {
$pdo = db();
$sql = "
CREATE TABLE IF NOT EXISTS messages (
id INT AUTO_INCREMENT PRIMARY KEY,
sender_id INT NOT NULL,
receiver_id INT NOT NULL,
message TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE
);";
$pdo->exec($sql);
echo "Table 'messages' created successfully (if it didn't exist).\n";
} catch (PDOException $e) {
die("DB MIGRATION ERROR: " . $e->getMessage());
}