29 lines
918 B
PHP
29 lines
918 B
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
try {
|
|
// Connect without specifying a database
|
|
$pdo_admin = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS, [
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
]);
|
|
// Create the database if it doesn't exist
|
|
$pdo_admin->exec("CREATE DATABASE IF NOT EXISTS " . DB_NAME);
|
|
echo "Database '" . DB_NAME . "' created or already exists.\n";
|
|
|
|
// Now connect to the created database
|
|
$pdo = db();
|
|
$migrations = glob(__DIR__ . '/migrations/*.sql');
|
|
sort($migrations);
|
|
|
|
foreach ($migrations as $migration) {
|
|
echo "Running migration: " . basename($migration) . "...\n";
|
|
$sql = file_get_contents($migration);
|
|
$pdo->exec($sql);
|
|
echo "Migration successful.\n";
|
|
}
|
|
|
|
echo "\nAll migrations completed successfully.\n";
|
|
|
|
} catch (PDOException $e) {
|
|
die("Database migration failed: " . $e->getMessage());
|
|
} |