/** * 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; }
/** * Execute the task * * @param array $options Config for the task */ protected function _execute(array $options) { $model = new Model_Minion_Migration(Database::instance()); $view = new View('minion/task/db/status'); $view->groups = $model->get_group_statuses(); echo $view; }
/** * Execute the task * * @param array Config for the task */ public function execute(array $config) { $db = Database::instance(); $model = new Model_Minion_Migration($db); $view = new View('minion/task/migrations/status'); $view->groups = $model->get_group_statuses(); echo $view; }
/** * Syncs all available migration files with the database * * @chainable * @return Minion_Migration_Manager Chainable instance */ public function sync_migration_files() { // Get array of installed migrations with the id as key $installed = $this->_model->installed_migrations(); $available = $this->_model->available_migrations(); $all_migrations = array_merge(array_keys($installed), array_keys($available)); foreach ($all_migrations as $migration) { // If this migration has since been deleted if (isset($installed[$migration]) and !isset($available[$migration])) { // We should only delete a record of this migration if it does // not exist in the "real world" if ($installed[$migration]['applied'] === '0') { $this->_model->delete_migration($installed[$migration]); } } elseif (!isset($installed[$migration]) and isset($available[$migration])) { $this->_model->add_migration($available[$migration]); } elseif ($installed[$migration]['description'] !== $available[$migration]['description']) { $this->_model->update_migration($installed[$migration], $available[$migration]); } } return $this; }
/** * Get an instance of the migration model, pre-loaded with a connection to * the test database * * @return Model_Minion_Migration */ public function getModel() { $model = new Model_Minion_Migration($this->getKohanaConnection()); return $model->table('test_minion_migrations'); }