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()); }