PDO::ERRMODE_EXCEPTION, ]); $pdo->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 the user already exists, we might not have permission to create a database. // Let's assume the DB is there and try to connect anyway for the next step. } // Now, connect to the database and run migrations $pdo = db(); $migrationsDir = __DIR__ . '/migrations'; $files = glob($migrationsDir . '/*.sql'); sort($files); foreach ($files as $file) { echo "Applying migration: " . basename($file) . "\n"; $sql = file_get_contents($file); try { $pdo->exec($sql); echo "Success\n"; } catch (PDOException $e) { echo "Error applying migration: " . $e->getMessage() . "\n"; exit(1); } } echo "All migrations applied successfully.\n";