public function version(string $targetVersion, string $namespace = null, string $group = null)
	{
		if (! $this->enabled)
		{
			throw ConfigException::forDisabledMigrations();
		}

		$this->ensureTable();

		// Set Namespace if not null
		if (! is_null($namespace))
		{
			$this->setNamespace($namespace);
		}

		// Set database group if not null
		if (! is_null($group))
		{
			$this->setGroup($group);
		}

		// Sequential versions need adjusting to 3 places so they can be found later.
		if ($this->type === 'sequential')
		{
			$targetVersion = str_pad($targetVersion, 3, '0', STR_PAD_LEFT);
		}

		$migrations = $this->findMigrations();

		if (empty($migrations))
		{
			return true;
		}

		// Get Namespace current version
		// Note: We use strings, so that timestamp versions work on 32-bit systems
		$currentVersion = $this->getVersion();
		if ($targetVersion > $currentVersion)
		{
			// Moving Up
			$method = 'up';
			ksort($migrations);
		}
		else
		{
			// Moving Down, apply in reverse order
			$method = 'down';
			krsort($migrations);
		}

		// Check Migration consistency
		$this->checkMigrations($migrations, $method, $targetVersion);

		// loop migration for each namespace (module)

		$migrationStatus = false;
		foreach ($migrations as $version => $migration)
		{
			// Only include migrations within the scoop
			if (($method === 'up' && $version > $currentVersion && $version <= $targetVersion) || ( $method === 'down' && $version <= $currentVersion && $version > $targetVersion))
			{
				$migrationStatus = false;
				include_once $migration->path;
				// Get namespaced class name
				$class = $this->namespace . '\Database\Migrations\Migration_' . ($migration->name);

				$this->setName($migration->name);

				// Validate the migration file structure
				if (! class_exists($class, false))
				{
					throw new \RuntimeException(sprintf(lang('Migrations.classNotFound'), $class));
				}

				// Forcing migration to selected database group
				$instance = new $class(\Config\Database::forge($this->group));

				if (! is_callable([$instance, $method]))
				{
					throw new \RuntimeException(sprintf(lang('Migrations.missingMethod'), $method));
				}

				$instance->{$method}();
				if ($method === 'up')
				{
					$this->addHistory($migration->version);
				}
				elseif ($method === 'down')
				{
					$this->removeHistory($migration->version);
				}

				$migrationStatus = true;
			}
		}

		return ($migrationStatus) ? $targetVersion : false;
	}
public function version(string $targetVersion, string $namespace = null, string $group = null)
	{
		if (! $this->enabled)
		{
			throw ConfigException::forDisabledMigrations();
		}

		$this->ensureTable();

		// Set Namespace if not null
		if (! is_null($namespace))
		{
			$this->setNamespace($namespace);
		}

		// Set database group if not null
		if (! is_null($group))
		{
			$this->setGroup($group);
		}

		// Sequential versions need adjusting to 3 places so they can be found later.
		if ($this->type === 'sequential')
		{
			$targetVersion = str_pad($targetVersion, 3, '0', STR_PAD_LEFT);
		}

		$migrations = $this->findMigrations();

		if (empty($migrations))
		{
			return true;
		}

		// Get Namespace current version
		// Note: We use strings, so that timestamp versions work on 32-bit systems
		$currentVersion = $this->getVersion();
		if ($targetVersion > $currentVersion)
		{
			// Moving Up
			$method = 'up';
			ksort($migrations);
		}
		else
		{
			// Moving Down, apply in reverse order
			$method = 'down';
			krsort($migrations);
		}

		// Check Migration consistency
		$this->checkMigrations($migrations, $method, $targetVersion);

		// loop migration for each namespace (module)

		$migrationStatus = false;
		foreach ($migrations as $version => $migration)
		{
			// Only include migrations within the scoop
			if (($method === 'up' && $version > $currentVersion && $version <= $targetVersion) || ( $method === 'down' && $version <= $currentVersion && $version > $targetVersion))
			{
				$migrationStatus = false;
				include_once $migration->path;
				// Get namespaced class name
				$class = $this->namespace . '\Database\Migrations\Migration_' . ($migration->name);

				$this->setName($migration->name);

				// Validate the migration file structure
				if (! class_exists($class, false))
				{
					throw new \RuntimeException(sprintf(lang('Migrations.classNotFound'), $class));
				}

				// Forcing migration to selected database group
				$instance = new $class(\Config\Database::forge($this->group));

				if (! is_callable([$instance, $method]))
				{
					throw new \RuntimeException(sprintf(lang('Migrations.missingMethod'), $method));
				}

				$instance->{$method}();
				if ($method === 'up')
				{
					$this->addHistory($migration->version);
				}
				elseif ($method === 'down')
				{
					$this->removeHistory($migration->version);
				}

				$migrationStatus = true;
			}
		}

		return ($migrationStatus) ? $targetVersion : false;
	}
public function version ( string $ targetVersion , string $ namespace = null , string $ group = null ) { if ( ! $ this -> enabled ) { throw ConfigException :: forDisabledMigrations ( ) ; } $ this -> ensureTable ( ) ; // Set Namespace if not null if ( ! is_null ( $ namespace ) ) { $ this -> setNamespace ( $ namespace ) ; } // Set database group if not null if ( ! is_null ( $ group ) ) { $ this -> setGroup ( $ group ) ; } // Sequential versions need adjusting to 3 places so they can be found later. if ( $ this -> type === 'sequential' ) { $ targetVersion = str_pad ( $ targetVersion , 3 , '0' , STR_PAD_LEFT ) ; } $ migrations = $ this -> findMigrations ( ) ; if ( empty ( $ migrations ) ) { return true ; } // Get Namespace current version // Note: We use strings, so that timestamp versions work on 32-bit systems $ currentVersion = $ this -> getVersion ( ) ; if ( $ targetVersion > $ currentVersion ) { // Moving Up $ method = 'up' ; ksort ( $ migrations ) ; } else { // Moving Down, apply in reverse order $ method = 'down' ; krsort ( $ migrations ) ; } // Check Migration consistency $ this -> checkMigrations ( $ migrations , $ method , $ targetVersion ) ; // loop migration for each namespace (module) $ migrationStatus = false ; foreach ( $ migrations as $ version => $ migration ) { // Only include migrations within the scoop if ( ( $ method === 'up' && $ version > $ currentVersion && $ version <= $ targetVersion ) || ( $ method === 'down' && $ version <= $ currentVersion && $ version > $ targetVersion ) ) { $ migrationStatus = false ; include_once $ migration -> path ; // Get namespaced class name $ class = $ this -> namespace . '\Database\Migrations\Migration_' . ( $ migration -> name ) ; $ this -> setName ( $ migration -> name ) ; // Validate the migration file structure if ( ! class_exists ( $ class , false ) ) { throw new \ RuntimeException ( sprintf ( lang ( 'Migrations.classNotFound' ) , $ class ) ) ; } // Forcing migration to selected database group $ instance = new $ class ( \ Config \ Database :: forge ( $ this -> group ) ) ; if ( ! is_callable ( [ $ instance , $ method ] ) ) { throw new \ RuntimeException ( sprintf ( lang ( 'Migrations.missingMethod' ) , $ method ) ) ; } $ instance -> { $ method } ( ) ; if ( $ method === 'up' ) { $ this -> addHistory ( $ migration -> version ) ; } elseif ( $ method === 'down' ) { $ this -> removeHistory ( $ migration -> version ) ; } $ migrationStatus = true ; } } return ( $ migrationStatus ) ? $ targetVersion : false ; }
Migrate to a schema version

Calls each migration step required to get to the schema version of
choice

@param string      $targetVersion Target schema version
@param string|null $namespace
@param string|null $group

@return mixed Current version string on success, FALSE on failure or no migrations are found
@throws ConfigException
Migrate to a schema version