35251-vm/db/migrate.php
Flatlogic Bot c1d245a403 1
2025-10-26 16:30:02 +00:00

32 lines
736 B
PHP

<?php
require_once __DIR__ . '/config.php';
function run_migrations() {
$pdo = db();
$migrationsDir = __DIR__ . '/migrations';
$files = glob($migrationsDir . '/*.sql');
if (empty($files)) {
echo "No migration files found.\n";
return;
}
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 running migration " . basename($file) . ": " . $e->getMessage() . "\n";
// Exit on first error
exit(1);
}
}
}
run_migrations();