37254-vm/migrate.php
Flatlogic Bot 6908213cbc init
2026-02-15 21:17:22 +00:00

24 lines
627 B
PHP

<?php
require_once __DIR__ . '/db/config.php';
function runMigrations() {
$pdo = db();
$migrationsDir = __DIR__ . '/db/migrations';
$files = glob($migrationsDir . '/*.sql');
sort($files);
foreach ($files as $file) {
$sql = file_get_contents($file);
try {
$pdo->exec($sql);
echo "Successfully ran migration: " . basename($file) . "\n";
} catch (PDOException $e) {
echo "Error running migration " . basename($file) . ": " . $e->getMessage() . "\n";
}
}
}
if (php_sapi_name() === 'cli' || isset($_GET['run'])) {
runMigrations();
}