38458-vm/migrate.php
2026-02-15 19:49:48 +00:00

24 lines
667 B
PHP

<?php
require_once __DIR__ . '/db/config.php';
try {
$pdo = db();
$migrationFiles = glob(__DIR__ . '/db/migrations/*.sql');
sort($migrationFiles);
foreach ($migrationFiles as $file) {
$sql = file_get_contents($file);
$statements = explode(';', $sql);
foreach ($statements as $statement) {
$statement = trim($statement);
if ($statement) {
$pdo->exec($statement);
}
}
echo "Executed: " . basename($file) . "\n";
}
echo "All migrations completed successfully!\n";
} catch (Exception $e) {
echo "Migration failed: " . $e->getMessage() . "\n";
}