/** * Run migrations in the specified groups so as to reach specified targets * * * * @param array $group Set of groups to update, empty array means all * @param array $target Versions for specified groups * @return array Array of all migrations that were successfully applied */ public function run_migration($group = array(), $target = TRUE) { list($migrations, $is_up) = $this->_model->fetch_required_migrations($group, $target); $method = $is_up ? 'up' : 'down'; foreach ($migrations as $migration) { $migration['id'] = $this->_model->get_migration_id($migration); if ($method == 'down' and $migration['timestamp'] <= Kohana::$config->load('minion/database')->lowest_migration) { Minion_CLI::write('You\'ve reached the lowest migration allowed by your config: ' . Kohana::$config->load('minion/database')->lowest_migration, 'red'); return; } $filename = $this->_model->get_filename_from_migration($migration); if (!($file = Kohana::find_file('database/migrations', $filename, FALSE))) { throw new Kohana_Exception('Cannot load migration :migration (:file)', array(':migration' => $migration['id'], ':file' => $filename)); } $class = $this->_model->get_class_from_migration($migration); include_once $file; $instance = new $class($migration); $db = $this->_get_db_instance($instance->get_database_connection()); try { $instance->{$method}($db); } catch (Database_Exception $e) { throw new Minion_Migration_Exception($e->getMessage(), $migration); } if ($this->_dry_run) { $this->_dry_run_sql[$migration['group']][$migration['timestamp']] = $db->reset_query_stack(); } else { $this->_model->mark_migration($migration, $is_up); } $this->_executed_migrations[] = $migration; } }