/** * Execute the task * * @param array $options Config for the task */ protected function _execute(array $options) { $model = new Model_Migration(); $view = new View('minion/db/status'); $view->groups = $model->get_group_statuses(); echo $view; }
/** * Migrates the database to the version specified * * @param array $options Configuration to use */ protected function _execute(array $options) { $groups = $options['group']; $target = $options['to']; $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; } } $model = new Model_Migration(); $model->ensure_table_exists(); $manager = new Migration(NULL, $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 (Migration_Exception $e) { echo View::factory('minion/db/exception')->set('migration', $e->get_migration())->set('error', $e->getMessage()); throw $e; } $view = View::factory('minion/db/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; }
/** * * * */ public function action_migrate() { // only accessible via the command line if (!Kohana::$is_cli) { throw new HTTP_Exception_403('Access via CLI only'); } // try and ensure the cache and log dirs are writeable @chmod(APPPATH.'/cache', 0777); @chmod(APPPATH.'/logs', 0777); // get the parameters $connection = $this->request->param('connection', NULL); $to_version = $this->request->param('to_version', NULL); $from_version = $this->request->param('from_version', NULL); $migration = new Model_Migration($connection); if($from_version === NULL) { $from_version = $this->get_schema_version(); } $migration->set_schema_version($from_version); if ($to_version === NULL) { $to_version = $this->get_app_version(); } if($migration->migrate_to($to_version)) { $this->after_migrate($migration); } }
/** * implementation of after_migrate method that updates the migration log * * @param Model_Migration $migration the migration object that represents the data * migration task that has just run */ protected function after_migrate(Model_Migration $migration) { $migration_log = ORM::factory('migration_log'); $migration_log->add_entry( $migration->get_schema_version(), $migration->get_to_version(), $migration->get_status() ); }