33 lines
840 B
PHP
33 lines
840 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);
|
|
if ($sql === false) {
|
|
echo "Error: Could not read file " . basename($file) . ".\n";
|
|
continue;
|
|
}
|
|
try {
|
|
$pdo->exec($sql);
|
|
echo "Success.\n";
|
|
} catch (PDOException $e) {
|
|
echo "Error executing migration " . basename($file) . ": " . $e->getMessage() . "\n";
|
|
// Exit on first error
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
if (php_sapi_name() === 'cli') {
|
|
run_migrations();
|
|
}
|
|
|
|
?>
|