32 lines
709 B
PHP
32 lines
709 B
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
function run_migrations() {
|
|
$pdo = db();
|
|
$migrations_dir = __DIR__ . '/migrations';
|
|
$files = glob($migrations_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: " . $e->getMessage() . "\n";
|
|
// Exit on first error
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
run_migrations();
|
|
|