/** * Migrates the database to the version specified * * @param array Configuration to use */ public function execute(array $config) { $k_config = Kohana::$config->load('minion/migration'); $groups = Arr::get($config, 'group', Arr::get($config, 'groups', NULL)); $target = Arr::get($config, 'to', NULL); $dry_run = array_key_exists('dry-run', $config); $quiet = array_key_exists('quiet', $config); $up = array_key_exists('up', $config); $down = array_key_exists('down', $config); $groups = $this->_parse_groups($groups); if ($target === NULL) { if ($down) { $target = FALSE; } else { $target = TRUE; } } $db = Database::instance(); $model = new Model_Minion_Migration($db); $model->ensure_table_exists(); $manager = new Minion_Migration_Manager($db, $model); $manager->sync_migration_files()->set_dry_run($dry_run); try { // Run migrations for specified groups & versions $manager->run_migration($groups, $target); } catch (Minion_Migration_Exception $e) { echo View::factory('minion/task/migrations/run/exception')->set('migration', $e->get_migration())->set('error', $e->getMessage()); throw $e; } $view = View::factory('minion/task/migrations/run')->set('dry_run', $dry_run)->set('quiet', $quiet)->set('dry_run_sql', $manager->get_dry_run_sql())->set('executed_migrations', $manager->get_executed_migrations())->set('group_versions', $model->get_group_statuses()); return $view; }
/** * Migrates the database to the version specified * * @param array $options Configuration to use * @throws Exception * @throws Minion_Migration_Exception * @return View */ protected function _execute(array $options) { $groups = $options['group']; $target = $options['to']; $db_conn = $options['db']; $dry_run = $options['dry-run'] !== FALSE; $quiet = $options['quiet'] !== FALSE; $up = $options['up'] !== FALSE; $down = $options['down'] !== FALSE; $groups = $this->_parse_groups($groups); if ($target === NULL) { if ($down) { $target = FALSE; } else { $target = TRUE; } } $db = Database::instance($db_conn); $model = new Model_Minion_Migration($db); $model->ensure_table_exists(); $manager = new Minion_Migration_Manager($db, $model); // Sync the available migrations with those in the db $manager->sync_migration_files()->set_dry_run($dry_run); try { // Run migrations for specified groups & versions $manager->run_migration($groups, $target); } catch (Minion_Migration_Exception $e) { echo View::factory('minion/task/db/migrate/exception')->set('migration', $e->get_migration())->set('error', $e->getMessage()); throw $e; } $view = View::factory('minion/task/db/migrate')->set('dry_run', $dry_run)->set('quiet', $quiet)->set('dry_run_sql', $manager->get_dry_run_sql())->set('executed_migrations', $manager->get_executed_migrations())->set('group_versions', $model->get_group_statuses()); return $view; }