Adds the option to run next DB migration(s) one by one
parent
b94a3df731
commit
4b330dff6c
|
|
@ -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) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue