exec($sql); $appliedMigrations[] = $fileName; } catch (PDOException $e) { echo "Error applying migration {$fileName}: " . $e->getMessage() . "\n"; return false; // Stop on first error } } else { echo "Migration already applied: {$fileName}\n"; } } file_put_contents($appliedMigrationsFile, json_encode($appliedMigrations)); echo "Migrations finished.\n"; return true; } // Run migrations if this script is executed directly if (realpath($argv[0]) === realpath(__FILE__)) { try { $pdo = db(); // Get PDO connection from config.php runMigrations($pdo); } catch (PDOException $e) { echo "Database connection error: " . $e->getMessage() . "\n"; } }