version() public method

Calls each migration step required to get to the schema version of choice
public version ( $version ) : void
$version integer Target schema version
return void Outputs a report of the migration
Esempio n. 1
0
 public static function down()
 {
     \Config::load('migrate', true);
     $version = \Config::get('migrate.version') - 1;
     if (\Migrate::version($version)) {
         static::_update_version($version);
     }
 }
Esempio n. 2
0
 public static function down()
 {
     \Config::load('migrate', true);
     $version = \Config::get('migrate.version') - 1;
     if (\Migrate::version($version)) {
         static::_update_version($version);
         \Cli::write('Migrated to version: ' . $version . '.', 'green');
     }
 }
Esempio n. 3
0
 public static function down()
 {
     \Config::load('migrations', true);
     if (($version = \Config::get('migrations.version') - 1) < 0) {
         throw new \Oil\Exception('You are already on the first migration.');
     }
     if (\Migrate::version($version)) {
         static::_update_version($version);
         \Cli::write("Migrated to version: {$version}.", 'green');
     } else {
         throw new \Oil\Exception("Migration {$version} does not exist. How did you get here?");
     }
 }
Esempio n. 4
0
 /**
  * migrates to the latest version unless -version is specified
  *
  * @param string	name of the type (in case of app, it's 'default')
  * @param string	type (app, module or package)
  * @param string	direction of migration (up or down)
  */
 protected static function _run($name, $type)
 {
     // -v or --version
     $version = \Cli::option('v', \Cli::option('version', ''));
     // version is used as a flag, so show it
     if ($version === true) {
         \Cli::write('Currently installed migrations for ' . $type . ':' . $name . ':', 'green');
         foreach (\Config::get('migrations.version.' . $type . '.' . $name, array()) as $version) {
             \Cli::write('- ' . $version);
         }
         return;
     } elseif ($version !== '') {
         // if version has a value, make sure only 1 item was passed
         if (static::$default + static::$module_count + static::$package_count > 1) {
             \Cli::write('Migration: version only accepts 1 item.');
             return;
         }
         $migrations = \Migrate::version($version, $name, $type, \Cli::option('catchup', false));
     } else {
         $migrations = \Migrate::latest($name, $type, \Cli::option('catchup', false));
     }
     // any migrations executed?
     if ($migrations) {
         \Cli::write('Performed migrations for ' . $type . ':' . $name . ':', 'green');
         foreach ($migrations as $migration) {
             \Cli::write($migration);
         }
     } else {
         if ($migrations === false) {
             \Cli::write('Some migrations where skipped for ' . $type . ':' . $name . '. Please re-run the migrations.', 'cyan');
         } elseif ($version !== '') {
             \Cli::write('No migrations were found for ' . $type . ':' . $name . '.');
         } else {
             \Cli::write('Already on the latest migration for ' . $type . ':' . $name . '.');
         }
     }
 }
Esempio n. 5
0
 /**
  * Migrates item down 1 version
  *
  * @param string
  * @param string
  */
 private static function _down($name, $type)
 {
     // if version - 1 is less than 0
     if (($version = \Config::get('migrations.version.' . $type . '.' . $name) - 1) < 0) {
         // already on first/lowest migration
         \Cli::write('You are already on the first migration for ' . $type . ':' . $name . '.');
         return;
     }
     if (\Migrate::version($version, $name, $type) !== false) {
         // update config and output a notice to console
         static::_update_version($version, $name, $type);
         \Cli::write('Migrated to version: ' . $version . ' for ' . $type . ':' . $name . '.', 'green');
     } else {
         // migration doesn't exist
         \Cli::write('Migration ' . $version . ' does not exist for ' . $type . ':' . $name . '. How did you get here?');
     }
 }
Esempio n. 6
0
 /**
  * Resets the application database structure and content.
  *
  * @return void
  */
 public static function reset()
 {
     // Revert to app default (sans migrations).
     \Migrate::version(0);
     \Cli::write('Database Reset', 'green');
     $migration_config = APPPATH . DS . 'config' . DS . 'development' . DS . 'migrations.php';
     if (file_exists($migration_config)) {
         \File::delete($migration_config);
         \Cli::write('Migration Config Removed', 'green');
     }
     // Truncate sessions table.
     \Oil\Refine::run('session:clear');
     // Rerun setup.
     \Oil\Refine::run('setup');
 }