34167-vm/db/migrations/002_create_comments_table.php
Flatlogic Bot b96d6dd21e first
2025-09-18 03:57:15 +00:00

28 lines
833 B
PHP

<?php
// db/migrations/002_create_comments_table.php
if (function_exists('migrate_002_create_comments_table')) {
return;
}
function migrate_002_create_comments_table() {
require_once __DIR__ . '/../config.php';
try {
$pdo = db();
$sql = "
CREATE TABLE IF NOT EXISTS comments (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
comment TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
";
$pdo->exec($sql);
echo "Migration 002: 'comments' table created or already exists.\n";
} catch (PDOException $e) {
die("Migration 002 failed: " . $e->getMessage() . "\n");
}
}