Esempio n. 1
0
 public function setup()
 {
     require_once "src/globals.php";
     ClearIce::setOutputLevel(ClearIce::OUTPUT_LEVEL_1);
     $GLOBALS['DRIVER'] = getenv('YENTU_DRIVER');
     $GLOBALS['DB_DSN'] = getenv('YENTU_BASE_DSN');
     if (getenv('YENTU_FILE') === false) {
         $GLOBALS['DB_FULL_DSN'] = "{$GLOBALS['DB_DSN']};dbname={$this->testDatabase}";
         $GLOBALS['DB_NAME'] = $this->testDatabase;
         $GLOBALS['DEFAULT_SCHEMA'] = (string) getenv('YENTU_DEFAULT_SCHEMA') == '' ? $this->testDatabase : (string) getenv('YENTU_DEFAULT_SCHEMA');
         $GLOBALS['DB_FILE'] = '';
     } else {
         $GLOBALS['DB_FULL_DSN'] = $GLOBALS['DB_DSN'];
         $GLOBALS['DB_FILE'] = getenv('YENTU_FILE');
         $GLOBALS['DB_NAME'] = '';
         $GLOBALS['DEFAULT_SCHEMA'] = '';
     }
     $GLOBALS['DB_USER'] = (string) getenv('YENTU_USER');
     $GLOBALS['DB_PASSWORD'] = (string) getenv('YENTU_PASSWORD');
     $GLOBALS['DB_HOST'] = (string) getenv('YENTU_HOST');
     $timer = $this->getMockBuilder("\\yentu\\Timer")->setMethods(array('stopInstance', 'startInstance'))->getMock();
     $timer->method('stopInstance')->willReturn(10.0);
     \yentu\Timer::setInstance($timer);
 }
Esempio n. 2
0
 public function run($options = array())
 {
     global $migrateCommand;
     global $migrateVariables;
     self::fillOptions($options);
     $migrateCommand = $this;
     if ($options['dump-queries'] !== true) {
         Yentu::greet();
     }
     $this->driver = ChangeLogger::wrap(DatabaseManipulator::create());
     $this->driver->setDumpQueriesOnly($options['dump-queries']);
     $this->driver->setDryRun($options['dry']);
     $totalOperations = 0;
     $filter = self::FILTER_UNRUN;
     $this->setupOptions($options, $filter);
     DatabaseItem::setDriver($this->driver);
     \yentu\Timer::start();
     $migrationPaths = Yentu::getMigrationPathsInfo();
     foreach ($migrationPaths as $path) {
         $this->setDefaultSchema($path);
         $migrateVariables = $path['variables'];
         $migrations = $this->filter(Yentu::getMigrations($path['home']), $filter);
         $this->announceMigration($migrations, $path);
         $this->currentPath = $path;
         foreach ($migrations as $migration) {
             $this->countOperations("{$path['home']}/{$migration['file']}");
             $this->driver->setVersion($migration['timestamp']);
             $this->driver->setMigration($migration['migration']);
             ClearIce::output("\nApplying '{$migration['migration']}' migration\n");
             require "{$path['home']}/{$migration['file']}";
             DatabaseItem::purge();
             ClearIce::output("\n");
             $totalOperations += $this->driver->resetOperations();
         }
     }
     if ($this->driver->getChanges()) {
         $elapsed = \yentu\Timer::stop();
         ClearIce::output("\nMigration took " . \yentu\Timer::pretty($elapsed) . "\n");
         ClearIce::output($this->driver->getChanges() . " operations performed\n");
         ClearIce::output($totalOperations - $this->driver->getChanges() . " operations skipped\n");
     }
     $this->driver->disconnect();
 }