35591-vm/db/setup.php
Flatlogic Bot 062a594521 1
2025-11-09 09:51:13 +00:00

31 lines
922 B
PHP

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