yii\console\controllers\BaseMigrateController::migrateToVersion PHP Method

migrateToVersion() protected method

Migrates to the certain version.
protected migrateToVersion ( string $version ) : integer
$version string name in the full format.
return integer CLI exit code
    protected function migrateToVersion($version)
    {
        $originalVersion = $version;
        // try migrate up
        $migrations = $this->getNewMigrations();
        foreach ($migrations as $i => $migration) {
            if (strpos($migration, $version) === 0) {
                $this->actionUp($i + 1);
                return self::EXIT_CODE_NORMAL;
            }
        }
        // try migrate down
        $migrations = array_keys($this->getMigrationHistory(null));
        foreach ($migrations as $i => $migration) {
            if (strpos($migration, $version) === 0) {
                if ($i === 0) {
                    $this->stdout("Already at '{$originalVersion}'. Nothing needs to be done.\n", Console::FG_YELLOW);
                } else {
                    $this->actionDown($i);
                }
                return self::EXIT_CODE_NORMAL;
            }
        }
        throw new Exception("Unable to find the version '{$originalVersion}'.");
    }