|
@@ 66-89 (lines=24) @@
|
| 63 |
|
return $executedMigrations; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
private function migrateUp(int $version = null): MigrationList |
| 67 |
|
{ |
| 68 |
|
$migrationList = $this->getMigrationList(); |
| 69 |
|
$pendingMigrations = $migrationList->getPendingMigrations(); |
| 70 |
|
$executedMigrations = $migrationList->getExecutedMigrations(); |
| 71 |
|
|
| 72 |
|
if ($version && !$pendingMigrations->containsVersion($version)) { |
| 73 |
|
throw new MigrationException(sprintf('Target version %s not found in pending migrations.', $version)); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
$completedMigrations = []; |
| 77 |
|
$connector = $this->migrationAdapter->getConnector(); |
| 78 |
|
foreach ($pendingMigrations as $migration) { |
| 79 |
|
$migration->execute($connector, MigrationInterface::MIGRATE_UP); |
| 80 |
|
$executedMigrations = $executedMigrations->push($migration); |
| 81 |
|
$this->migrationAdapter->write($this->name, $executedMigrations); |
| 82 |
|
$completedMigrations[] = $migration; |
| 83 |
|
if ($version && $migration->getVersion() === $version) { |
| 84 |
|
break; |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
return new MigrationList($completedMigrations); |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
private function migrateDown(int $version = null): MigrationList |
| 92 |
|
{ |
|
@@ 91-119 (lines=29) @@
|
| 88 |
|
return new MigrationList($completedMigrations); |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
private function migrateDown(int $version = null): MigrationList |
| 92 |
|
{ |
| 93 |
|
$migrationList = $this->getMigrationList(); |
| 94 |
|
$executedMigrations = $migrationList->getExecutedMigrations(); |
| 95 |
|
|
| 96 |
|
if ($version && !$executedMigrations->containsVersion($version)) { |
| 97 |
|
throw new MigrationException(sprintf('Target version %s not found in executed migrations.', $version)); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
$completedMigrations = []; |
| 101 |
|
$connector = $this->migrationAdapter->getConnector(); |
| 102 |
|
foreach ($executedMigrations->reverse() as $migration) { |
| 103 |
|
if ($version && $migration->getVersion() === $version) { |
| 104 |
|
break; |
| 105 |
|
} |
| 106 |
|
$migration->execute($connector, MigrationInterface::MIGRATE_DOWN); |
| 107 |
|
$executedMigrations = $executedMigrations->remove($migration); |
| 108 |
|
if ($executedMigrations->count() > 0) { |
| 109 |
|
/* |
| 110 |
|
* Do not write version info after reversing initial migration since we have |
| 111 |
|
* an assumption that the database was deleted! |
| 112 |
|
*/ |
| 113 |
|
$this->migrationAdapter->write($this->name, $executedMigrations); |
| 114 |
|
} |
| 115 |
|
$completedMigrations[] = $migration; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
return new MigrationList($completedMigrations); |
| 119 |
|
} |
| 120 |
|
} |
| 121 |
|
|