/** * @param int $version target migration version, if not set all not applied available migrations will be applied * @param bool $force force apply migration * @param bool $down rollback migration * @throws \Exception */ public function migrate($version = null, $force = false, $down = false) { $migrations = $this->versionResolver->getAll($force); if (!is_null($version) && !$this->hasMigrationVersions($migrations, $version)) { throw new \Exception(sprintf('Migration version %s is not found!', $version)); } $currentMigrationVersion = $this->versionTable->getCurrentVersion(); if (!is_null($version) && $version == $currentMigrationVersion && !$force) { throw new \Exception(sprintf('Migration version %s is current version!', $version)); } if ($version && $force) { foreach ($migrations as $migration) { if ($migration['version'] == $version) { // if existing migration is forced to apply - delete its information from migrated // to avoid duplicate key error if (!$down) { $this->versionTable->delete($migration['version']); } $this->applyMigration($migration, $down); break; } } return; } foreach ($this->versionResolver->getAll() as $migration) { $this->applyMigration($migration, false); } }
public function onDispatch(MvcEvent $e) { if (!$e->getRequest() instanceof ConsoleRequest) { throw new RuntimeException('You can only use this action from a console!'); } $response = sprintf("Current version %s\n", $this->table->getCurrentVersion()); $e->setResult($response); return $response; }
public function testGetCurrentVersion() { $result = $this->prophesize('Zend\\Db\\ResultSet\\ResultSet'); $version = $this->prophesize('T4web\\Migrations\\Version\\Version'); $this->tableGataway->select(Argument::type('callable'))->willReturn($result); $result->count()->willReturn(1); $result->current()->willReturn($version->reveal()); $version->getVersion()->willReturn(2); $result = $this->table->getCurrentVersion(); $this->assertEquals(2, $result); }