24 lines
627 B
PHP
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();
|
|
}
|