35682-vm/db/migrate.php
2025-11-13 12:17:45 +00:00

25 lines
592 B
PHP

<?php
require_once __DIR__ . '/config.php';
function run_migrations() {
$pdo = db();
$migrations_dir = __DIR__ . '/migrations';
$files = glob($migrations_dir . '/*.sql');
sort($files);
foreach ($files as $file) {
$sql = file_get_contents($file);
if ($sql) {
try {
$pdo->exec($sql);
echo "Migration from $file ran successfully.\n";
} catch (PDOException $e) {
echo "Error running migration from $file: " . $e->getMessage() . "\n";
}
}
}
}
run_migrations();