35530-vm/db/migrate.php
Flatlogic Bot 02f1818a16 3
2025-11-07 17:13:42 +00:00

20 lines
695 B
PHP

<?php
require_once __DIR__ . '/config.php';
try {
// Connect without specifying a database
$pdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
$pdo->exec("CREATE DATABASE IF NOT EXISTS ".DB_NAME);
echo "Database created successfully (if it didn't exist).\n";
// Now connect to the database and run migrations
$pdo = db();
$sql = file_get_contents(__DIR__ . '/migrations/001_create_users_table.sql');
$pdo->exec($sql);
echo "Migration successful!\n";
} catch (PDOException $e) {
die("Migration failed: " . $e->getMessage() . "\n");
}