Adds the option to run next DB migration(s) one by one

main
Yasen Pramatarov 2025-11-21 11:03:58 +02:00
parent b94a3df731
commit 4b330dff6c
1 changed files with 15 additions and 2 deletions

View File

@ -127,16 +127,29 @@ class MigrationRunner
} }
public function applyPendingMigrations(): array public function applyPendingMigrations(): array
{
return $this->runMigrations($this->listPendingMigrations());
}
public function applyNextMigration(): array
{ {
$pending = $this->listPendingMigrations(); $pending = $this->listPendingMigrations();
$appliedNow = [];
if (empty($pending)) { if (empty($pending)) {
return [];
}
return $this->runMigrations([reset($pending)]);
}
private function runMigrations(array $migrations): array
{
$appliedNow = [];
if (empty($migrations)) {
return $appliedNow; return $appliedNow;
} }
try { try {
$this->pdo->beginTransaction(); $this->pdo->beginTransaction();
foreach ($pending as $migration) { foreach ($migrations as $migration) {
$path = $this->migrationsDir . '/' . $migration; $path = $this->migrationsDir . '/' . $migration;
$sql = file_get_contents($path); $sql = file_get_contents($path);
if ($sql === false) { if ($sql === false) {