migrates item down to the given version

@param string
@param string
181228
protected static function _down($name, $type)
	{
		// -v or --version
		$version = \Cli::option('v', \Cli::option('version', null));

		// if version has a value, make sure only 1 item was passed
		if ($version and (static::$default + static::$module_count + static::$package_count > 1))
		{
			\Cli::write('Migration: version only accepts 1 item.');
			return;
		}

		$migrations = \Migrate::down($version, $name, $type);

		if ($migrations)
		{
			\Cli::write('Reverted migrations for '.$type.':'.$name.':', 'green');
			foreach ($migrations as $migration)
			{
				\Cli::write('- '.$migration);
			}
		}
		else
		{
			// there is no 'down'...
			\Cli::write('There are no migrations installed to revert for '.$type.':'.$name.'.');
		}
	}
94402
public function move(string $old, string $new){
    if (
      !empty($old) &&
      !empty($new) &&
      ($old = $this->checkFilePath($old)) &&
      ftp_rename($this->cn, $old, $new)
    ){
      return true;
    }
    return false;
  }
789015
public function rollback($version)
    {
        $files = $this->getMigrationsFiles();
        $lastMigration = null;

        arsort($files);

        foreach ($files as $key => $value) {
            if ($key < $version) continue;
            include $this->migrateManager->storagePath . '/' . $value;
            $className = "Migration_$key";
            $class = new $className();
            $class->down();
            $lastMigration = $key;
            unset($class);
        }

        if (!is_null($lastMigration)) {
            $this->setVersion($lastMigration - 1);
            echo Utils::colorize("Done!", "SUCCESS");
        } else {
            echo Utils::colorize("The latest version is already installed.", "NOTE");
        }
    }
1082978
public function upgrade( $version ) {

		if ( $version < 1 ) {
			// Upgrade from version 0 (closed source service) to version 1 (initial open source offering)
			$this->upgradeEcommerce();
			$this->upgradeBookInformation();
			$this->upgradeBook();
		}
		if ( $version < 3 ) {
			\Pressbooks\CustomCss::upgradeCustomCss();
		}
		if ( $version < 4 ) {
			$this->fixDoubleSlashBug();
		}
		if ( $version < 5 ) {
			$this->changeDefaultBookCover();
		}
		if ( $version < 6 || $version < 7 ) {
			$this->makeThumbnailsForBookCover();
		}
		if ( $version < 8 ) {
			$this->resetLandingPage();
		}
		if ( $version < 10 ) {
			$taxonomy = Taxonomy::init();
			$taxonomy->insertTerms();
			flush_rewrite_rules( false );
		}
		if ( $version < 11 ) {
			$this->migratePartContentToEditor();
		}
		if ( $version < 12 ) {
			Container::get( 'Styles' )->initPosts();
		}
		if ( $version < 13 ) {
			$this->upgradeToPressbooksFive();
		}
	}
202341
protected function _migrateFile($version, $filePath, $direction = 'up')
    {
        $classVersion = preg_replace('/[^0-9A-Za-z]/', '', $version);
        $className = 'Migration_' . $classVersion;
        if (file_exists($filePath)) {
            require_once $filePath;
            if (class_exists($className)) {
                $migration = new $className($this->config, $version);
                if ($direction === 'up') {
                    $migration->up();
                    if (method_exists($migration, 'afterUp')) {
                        $migration->afterUp();
                    }
                    print PHP_EOL . Color::success('Upgrade Version ' . $version . ' was successfully migrated') . PHP_EOL;
                } elseif ($direction === 'down') {
                    $migration->down();
                    if (method_exists($migration, 'afterDown')) {
                        $migration->afterDown();
                    }
                    print PHP_EOL . Color::info('Downgrade Version ' . $version . ' was successfully migrated') . PHP_EOL;
                }
            }
        } else {
            throw new CommandsException('Migration class cannot be found ' . $className . ' at ' . $filePath);
        }
    }
773964
public static function isValidProtocolVersion($version)
    {
        if (!is_string($version) || empty($version)) {
            return false;
        }

        return (bool) preg_match('#^(1\.[01]|2)$#', $version);
    }
1100796
@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		ApptentiveLog.d(DATABASE, "Upgrade database from %d to %d", oldVersion, newVersion);
		try {
			DatabaseMigrator migrator = createDatabaseMigrator(oldVersion, newVersion);
			if (migrator != null) {
				migrator.onUpgrade(db, oldVersion, newVersion);
			}
		} catch (Exception e) {
			ApptentiveLog.e(DATABASE, e, "Exception while trying to migrate database from %d to %d", oldVersion, newVersion);
			logException(e);

			// if migration failed - create new table
			db.execSQL(SQL_DELETE_PAYLOAD_TABLE);
			onCreate(db);
		}
	}
1304343
public function getMigrationSql($version, $increment)
    {
        // I could use the GLOB_BRACE but it is not supported on ALPINE distros.
        // So, I have to call multiple times to simulate the braces.

        if (intval($version) != $version) {
            throw new \InvalidArgumentException("Version '$version' should be a integer number");
        }
        $version = intval($version);

        $filePattern = $this->folder
            . "/migrations"
            . "/" . ($increment < 0 ? "down" : "up")
            . "/*.sql";

        $result = array_filter(glob($filePattern), function ($file) use ($version) {
            return preg_match("/^0*$version(-dev)?\.sql$/", basename($file));
        });

        // Valid values are 0 or 1
        if (count($result) > 1) {
            throw new InvalidMigrationFile("You have two files with the same version number '$version'");
        }

        foreach ($result as $file) {
            if (intval(basename($file)) === $version) {
                return $file;
            }
        }
        return null;
    }
1235761
public function to($version) {
        $this->out(sprintf('<success>Upgrading to %s...</success>', $version));

        $schema = sprintf('%s/Config/Schema/Upgrade/%s.sql', CakePlugin::path($this->plugin), $version);

        if (!file_exists($schema)) {
            $this->err(sprintf('<error>Upgrade schema %s does not exist</error>', basename($schema)));
            return false;
        }

        // Trigger any migration changes
        $method = 'to_' . preg_replace('/[^0-9]+/', '', $version);

        if (method_exists($this, $method)) {
            call_user_func(array($this, $method));
        }

        // Execute the schema
        if ($this->executeSchema($schema, false)) {
            $this->complete[] = $version;

            $this->out(sprintf('<success>Upgrade to %s complete</success>', $version));
            $this->versions();
        }

        return true;
    }
253399
public function setVersion($version)
    {
        if ($version == self::VERSION_3 || $version == self::VERSION_3_1_1) {
            $this->version = $version;
        } else {
            throw new Exception('Invalid version');
        }
    }
1256017
private function hasUnmigratedVersions()
    {
        $needsToRun = false;

        foreach ($this->availableVersions as $migration) {
            $isTargetMigrated = in_array($migration->getVersion(), $this->migratedVersions);

            if ($isTargetMigrated) {
                continue;
            }

            $needsToRun = true;
            break;
        }

        return $needsToRun;
    }
1337974
function lookup(version, migrations) {
  var regex = RegExp('^' + version + '.*$');
  for (var m in migrations)
    if (migrations.hasOwnProperty(m) && m.match(regex)) return m;
  return null;
}
1227237
public static function setApplicationVersion(string $version): void
    {
        if (self::isCliApp()) {
            self::$APPLICATION_VERSION = $version;
        } else {
            MSession::set(MCoreApplication::APPLICATION_VERSION, $version);
        }
    }
106350
private function executeMigrations()
    {
        if ($this->migrator->needsToRun()) {
            $latestVersion = $this->migrator->migrate();
            $this->logger->info('Migrate all migrations up to version ' . $latestVersion . '.');
        }
    }
537493
public function migrateUp()
    {
        try {
            $this->builder->table(
                $this->table,
                function ($table) {
                    $table->string('value')->nullable()->change();
                }
            );
        } catch (\Exception $e) {
            dd($e->getMessage());
        }
    }
849190
public function setVersion(string $version)
    {
        if (Validation::isValidVersionRegex($version)) {
            $this->version = $version;
        } else {
            throw new CustomException('Malformed version');
        }
    }
1016471
public function importVersion($version)
    {
        return $this
            ->setMajor($version->getMajor())
            ->setMinor($version->getMinor())
            ->setPatch($version->getPatch())
            ->setPreRelease($version->getPreRelease())
            ->setBuild($version->getBuild());
    }