37 lines
811 B
PHP
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();
|
|
|