36036-vm/db/migrate.php
Flatlogic Bot e112ad7b40 Salaam 1.1
2025-11-22 16:45:55 +00:00

37 lines
811 B
PHP

<?php
require_once 'config.php';
function run_migrations() {
$pdo = db();
if (!$pdo) {
echo "Error: Unable to connect to the database.\n";
return;
}
$migration_dir = __DIR__ . '/migrations';
$files = glob($migration_dir . '/*.sql');
if (empty($files)) {
echo "No migration files found.\n";
return;
}
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 running migration " . basename($file) . ": " . $e->getMessage() . "\n";
// Stop on error
return;
}
}
}
run_migrations();