/** * The migrate command. * * @return bool */ public function migrate() { $options = array('direction' => $this->args[0], 'scope' => 'app'); if (isset($this->params['plugin']) && CakePlugin::loaded($this->params['plugin'])) { $options['scope'] = $this->params['plugin']; } if (isset($this->args[1])) { $options['steps'] = (int) $this->args[1]; } try { $migrations = new Migrations($this->params['connection']); $migrations->migrate($options); } catch (Exception $e) { $this->out(__d('migration_shell', 'An error occured during the migration.')); $this->err($e->getMessage()); return false; } $this->out(__d('migration_shell', 'The migration was successful.')); /** @var SchemaMigration $sm */ $sm = ClassRegistry::init('Migrations.SchemaMigration'); $sm->setDataSource($this->params['connection']); $this->out(__d('migration_shell', 'Current Migration version: %s', array($sm->getCurrentVersion($options['scope'])))); $migrations->clearCache(); return true; }
public function execute(array $options) { if ($options['force'] === NULL or 'yes' === Minion_CLI::read('This will destroy all data in the current database. Are you sure? [yes/NO]')) { Minion_CLI::write('Dropping Tables', 'green'); $migrations = new Migrations(array('log' => 'Minion_CLI::write')); $migrations->clear_all(); Minion_Task::factory('db:migrate')->execute($options); } else { Minion_CLI::write('Nothing done', 'brown'); } }
public static function migrations() { $current = Config::meta('current_migration'); $migrate_to = Config::migrations('current'); $migrations = new Migrations($current); $table = Base::table('meta'); if (is_null($current)) { $number = $migrations->up($migrate_to); Query::table($table)->insert(array('key' => 'current_migration', 'value' => $number)); } else { if ($current < $migrate_to) { $number = $migrations->up($migrate_to); Query::table($table)->where('key', '=', 'current_migration')->update(array('value' => $number)); } } }
function setup() { if (!empty($this->data)) { $data = $this->data; $install_files_path = CONFIGS . 'install' . DS; $connection = array(); foreach (array('driver', 'host', 'login', 'password', 'database', 'prefix') as $k) { $connection[$k] = $data[$k]; } $this->_writeDBConfig($connection); uses('model' . DS . 'connection_manager'); $db = ConnectionManager::getInstance(); $connection = $db->getDataSource('default'); if ($connection->isConnected()) { App::import('vendor', 'migrations'); $oMigrations = new Migrations(); $oMigrations->load($install_files_path . 'schema.yml'); $dbRes = $oMigrations->up(); if (is_array($dbRes)) { $error_string = ''; foreach ($dbRes as $error) { $error_string .= $error['error'] . '<br />'; } $this->Session->setFlash(__('There were some errors during the creation of your db tables', true) . ':<br />' . $error_string); } elseif ($dbRes == true) { //add admin to the users table App::import('model', array('User', 'Site')); $User = new User(); $User->save(array('username' => $data['admin_username'], 'password' => sha1(Configure::read('Security.salt') . $data['admin_password']), 'group_id' => 1)); /*$Site = new Site(); $Site->save( array( 'user_id' => $User->getInsertID(), 'domain' => Configure::read( 'CMS.Site.Domain' ) ) );*/ App::import('vendor', 'fixtures'); $oFixtures = new Fixtures(); if ($oFixtures->import($install_files_path . 'fixtures.yml') === true) { $this->flash('Congratulations, you have successfully installed Pagebakery!', '/'); } else { $this->Session->setFlash(__('Sorry, there was an error adding initial data', true)); } } } else { $this->Session->setFlash('I could not connect to the DataBase. Please check the setup details again.'); } } $this->set('DBDrivers', $this->_getDBDrivers()); }
public function stage1() { if (Input::method() == 'POST') { // run patch containing the changes require PATH . 'upgrade/patch.php'; Migrations::apply(); Config::write(PATH . 'config.php', Config::get()); return redirect('complete'); } render('stage1'); }
$posts_page = Db::query("select `value` from meta where `key` = 'show_posts'")->fetchColumn(); $sql = "insert into `meta` (`key`, `value`) values ('home_page', '" . $posts_page . "')"; $migration->query($sql); } // [BUGFIX] make sure the password field is big enough $sql = "alter table `users` change `password` `password` text character set utf8 COLLATE utf8_general_ci not null"; $migration->query($sql); // apply changes $migration->apply(); // update config Config::set('application.admin_folder', 'admin'); Config::set('application.key', random(32)); /* 0.5 --> 0.6 */ $migration = new Migrations(); $sql = "create table if not exists `sessions` (\n\t`id` char( 32 ) not null ,\n\t`date` datetime not null ,\n\t`ip` varchar( 15 ) not null ,\n\t`ua` varchar( 140 ) not null ,\n\t`data` text not null\n) engine=innodb charset=utf8 collate=utf8_general_ci;"; $migration->query($sql); // comments auto published option if (Schema::has('meta', 'key', 'auto_published_comments') === false) { $sql = "insert into `meta` (`key`, `value`) values ('auto_published_comments', '0')"; $migration->query($sql); } // pagination if (Schema::has('meta', 'key', 'posts_per_page') === false) { $sql = "insert into `meta` (`key`, `value`) values ('posts_per_page', '10')"; $migration->query($sql); } // apply changes $migration->apply(); // update config
/** * Determine which version of the database table for migrations is currently * in use. * * This function does not currently help in determining the constraint on * the 'type' column (the difference between versions 2 and 3 is whether the * constraint is 20 or 40), as the db drivers don't currently return this * information for all databases. * * @return int A number indicating the version of the table in use, or 0 * if the version could not be determined. 1 is returned for the "old" * version, 3 is returned for the "new" version. */ private function getLibraryVersion() { if (self::$migrationsSchemaVersion) { return self::$migrationsSchemaVersion; } $row = $this->_ci->db->get($this->migrationsTable, 1)->row(); // Given no definite way to check between versions 2 and 3, we'll assume // version 3 if the type column is available if (isset($row->type)) { self::$migrationsSchemaVersion = self::MAX_SCHEMA_VERSION; } elseif (isset($row->app_version)) { // If the type column is unavailable, check for the app_version column self::$migrationsSchemaVersion = 1; } else { // If neither column is available, who knows? self::$migrationsSchemaVersion = 0; } return self::$migrationsSchemaVersion; }
public function rebuild_db($projectId = null) { if (!$projectId || !($project = $this->Project->find('first', array('conditions' => array('Project.id' => $projectId), 'contain' => array())))) { $this->Session->setFlash(__('Please do following links in the page')); } else { require_once VENDORS . 'migrations/migrations.php'; $db = new ConnectionManager(); $db->create('olc_baker-dev', array('datasource' => 'Database/Mysql', 'host' => $project['Project']['db_host'], 'login' => $project['Project']['db_login'], 'password' => $project['Project']['db_password'], 'database' => $project['Project']['db_name'], 'encoding' => 'utf8', 'persistent' => false)); $dbn = $db->getDataSource('olc_baker-dev'); $sqlPath = $project['Project']['app_path'] . DS . 'Config' . DS . 'schema'; $dbn->execute('CREATE DATABASE IF NOT EXISTS `' . $project['Project']['db_name'] . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;'); $dbn->execute('USE `' . $project['Project']['db_name'] . '`;'); $migrations = new Migrations('olc_baker-dev'); $migrations->load($sqlPath . DS . 'schema.yaml'); $migrations->down(); $migrations->up(); $this->Session->setFlash(__('Database was rebuilt')); } $this->redirect(array('action' => 'index')); }
public function execute(array $options) { $migrations = new Migrations(array('log' => 'Minion_CLI::write')); $migration = $migrations->generate_new_migration_file($options['name'], $options['template']); Minion_CLI::write(Minion_CLI::color($migration, 'green') . Minion_CLI::color(' Migration File Generated', 'brown')); }
public function execute(array $options) { $migrations = new Migrations(array('log' => 'Minion_CLI::write')); $executed_migrations = $migrations->get_executed_migrations(); Minion_CLI::write('Current Version: ' . end($executed_migrations)); }
#!/usr/bin/php -q <?php include "Migrations.php"; $migrate = new Migrations(); switch ($argv[1]) { case 'install': $migrate->install(); break; case 'generate': if (!isset($argv[2])) { die("\nPlease specify a name for the migration\n"); } else { $migrate->generate($argv[2]); } break; case 'g': if (!isset($argv[2])) { die("\nPlease specify a name for the migration\n"); } else { $migrate->generate($argv[2]); } break; case 'run': if (isset($argv[2])) { $migrate->run($argv[2]); } else { $migrate->run(); } break; case 'rm': if (isset($argv[2])) {