35604-vm/db/migrate.php
Flatlogic Bot 24d0513664 2
2025-11-09 21:38:45 +00:00

27 lines
687 B
PHP

<?php
require_once __DIR__ . '/config.php';
function run_migrations() {
$pdo = db();
$migrationsDir = __DIR__ . '/migrations';
$files = glob($migrationsDir . '/*.sql');
sort($files);
foreach ($files as $file) {
echo "Running migration: " . basename($file) . "\n";
$sql = file_get_contents($file);
try {
$pdo->exec($sql);
echo "Success.\n";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage() . "\n";
// A simple way to track which migrations have been run is needed
// For now, we'll just stop on error.
exit(1);
}
}
}
run_migrations();