/** * @brief Check if this version is less than an other one. * @param SchemaVersion $other The other version to compare at. */ public function isLess($other) { if ($this->getMajor() < $other->getMajor()) { return true; } if ($this->getMajor() == $other->getMajor() && $this->getMinor() < $other->getMinor()) { return true; } return false; }
require_once_dir(Config::get('migr_dir')); // init default tables require_once dirname(__FILE__) . '/install.php'; // init $INTEND_VERSION = isset($argv[1]) ? $argv[1] : '99991231235959'; // functions function print_migration_status($direction, $classname, $version) { echonl('================================================================================'); echonl($classname . '.' . strtolower($direction) . '() is executed.'); echonl('Schema version is ' . $version . ' now.'); } // connect db connection $db = Context::get('db'); $db->connect(); $schema_version = new SchemaVersion(); if ($schema_version->count() == 0) { $schema_version->version = 0; $schema_version->save(); } $schema_version = $schema_version->find(); // read migration files... $files = get_files(Config::get('migr_dir')); if ($INTEND_VERSION >= $schema_version->version) { sort($files); $direction = 'UP'; } else { rsort($files); $direction = 'DOWN'; } for ($i = 0; $i < count($files); $i++) {
/** * Checks wheter a migration has to be invoked, that is if the migration's * version is included in the interval between current and target schema * version. * * @access private * * @param int the migration's version to check for inclusion * * @return bool TRUE if included, FALSE otherwise */ function relevant_migration($version) { $current_version = $this->schema_version->get(); if ($this->is_up()) { return $current_version < $version && $version <= $this->target_version; } else { if ($this->is_down()) { return $current_version >= $version && $version > $this->target_version; } } }