28 lines
804 B
PHP
28 lines
804 B
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
try {
|
|
// Connect to MySQL server without specifying a database
|
|
$pdo = 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->exec('CREATE DATABASE IF NOT EXISTS `'.DB_NAME.'`');
|
|
|
|
// Now connect to the specific database
|
|
$pdo = db();
|
|
|
|
$migrations = glob(__DIR__ . '/migrations/*.sql');
|
|
sort($migrations);
|
|
|
|
foreach ($migrations as $migration) {
|
|
$sql = file_get_contents($migration);
|
|
$pdo->exec($sql);
|
|
echo "Executed migration: " . basename($migration) . "\n";
|
|
}
|
|
|
|
echo "Migrations completed successfully.\n";
|
|
} catch (PDOException $e) {
|
|
die("Migration failed: " . $e->getMessage());
|
|
} |