22 lines
655 B
PHP
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());
|
|
}
|
|
|