PDO::ERRMODE_EXCEPTION, ]); $pdo_admin->exec("CREATE DATABASE IF NOT EXISTS `".DB_NAME."`"); echo "Database `".DB_NAME."` created or already exists.\n"; } catch (PDOException $e) { echo "Error creating database: " . $e->getMessage() . "\n"; // If we can't create the DB, we probably can't do anything else. exit(1); } // 2. Now connect to the database and run migrations $pdo = db(); $migrations_dir = __DIR__ . '/migrations'; $files = glob($migrations_dir . '/*.sql'); sort($files); foreach ($files as $file) { echo "Running migration: " . basename($file) . "\n"; try { $sql = file_get_contents($file); $pdo->exec($sql); echo "Success.\n"; } catch (PDOException $e) { echo "Error: " . $e->getMessage() . "\n"; // Exit on first error exit(1); } } echo "All migrations completed.\n"; ?>