Пример #1
0
 /**
  * Executes the specified migration on this environment.
  *
  * @param MigrationInterface $migration Migration
  * @param string $direction Direction
  * @return void
  */
 public function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP)
 {
     $startTime = time();
     $direction = $direction == MigrationInterface::UP ? MigrationInterface::UP : MigrationInterface::DOWN;
     $migration->setAdapter($this->getAdapter());
     // begin the transaction if the adapter supports it
     if ($this->getAdapter()->hasTransactions()) {
         $this->getAdapter()->beginTransaction();
     }
     // Run the migration
     if (method_exists($migration, MigrationInterface::CHANGE)) {
         if ($direction == MigrationInterface::DOWN) {
             // Create an instance of the ProxyAdapter so we can record all
             // of the migration commands for reverse playback
             $proxyAdapter = AdapterFactory::instance()->getWrapper('proxy', $this->getAdapter());
             $migration->setAdapter($proxyAdapter);
             /** @noinspection PhpUndefinedMethodInspection */
             $migration->change();
             $proxyAdapter->executeInvertedCommands();
             $migration->setAdapter($this->getAdapter());
         } else {
             /** @noinspection PhpUndefinedMethodInspection */
             $migration->change();
         }
     } else {
         $migration->{$direction}();
     }
     // commit the transaction if the adapter supports it
     if ($this->getAdapter()->hasTransactions()) {
         $this->getAdapter()->commitTransaction();
     }
     // Record it in the database
     $this->getAdapter()->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time()));
 }
Пример #2
0
 /**
  * Executes the specified migration on this environment.
  *
  * @param MigrationInterface $migration Migration
  * @param string $direction Direction
  * @return void
  */
 public function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP)
 {
     $startTime = time();
     $direction = $direction == MigrationInterface::UP ? MigrationInterface::UP : MigrationInterface::DOWN;
     $migration->setAdapter($this->getAdapter());
     // begin the transaction if the adapter supports it
     if ($this->getAdapter()->hasTransactions()) {
         $this->getAdapter()->beginTransaction();
     }
     // force UTF-8 encoding for MySQL
     // TODO - this code will need to be abstracted when we support other db vendors
     //$this->getAdapter()->execute('SET NAMES UTF8');
     // Run the migration
     if (method_exists($migration, MigrationInterface::CHANGE)) {
         if ($direction == MigrationInterface::DOWN) {
             // Create an instance of the ProxyAdapter so we can record all
             // of the migration commands for reverse playback
             $proxyAdapter = new ProxyAdapter($this->getAdapter(), $this->getOutput());
             $migration->setAdapter($proxyAdapter);
             $migration->change();
             $proxyAdapter->executeInvertedCommands();
             $migration->setAdapter($this->getAdapter());
         } else {
             $migration->change();
         }
     } else {
         $migration->{$direction}();
     }
     // commit the transaction if the adapter supports it
     if ($this->getAdapter()->hasTransactions()) {
         $this->getAdapter()->commitTransaction();
     }
     // Record it in the database
     $this->getAdapter()->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time()));
 }
Пример #3
0
 /**
  * Execute a migration against the specified Environment.
  *
  * @param string $name Environment Name
  * @param MigrationInterface $migration Migration
  * @param string $direction Direction
  * @return void
  */
 public function executeMigration($name, MigrationInterface $migration, $direction = MigrationInterface::UP)
 {
     $this->getOutput()->writeln('');
     $this->getOutput()->writeln(' ==' . ' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' . ' <comment>' . ($direction == 'up' ? 'migrating' : 'reverting') . '</comment>');
     // Execute the migration and log the time elapsed.
     $start = microtime(true);
     $this->getEnvironment($name)->executeMigration($migration, $direction);
     $end = microtime(true);
     $this->getOutput()->writeln(' ==' . ' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' . ' <comment>' . ($direction == 'up' ? 'migrated' : 'reverted') . ' ' . sprintf('%.4fs', $end - $start) . '</comment>');
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime)
 {
     if (strtolower($direction) == 'up') {
         // up
         $sql = sprintf('INSERT INTO %s (' . 'version, start_time, end_time' . ') VALUES (' . '"%s",' . '"%s",' . '"%s"' . ');', $this->getSchemaTableName(), $migration->getVersion(), $startTime, $endTime);
         $this->query($sql);
     } else {
         // down
         $sql = sprintf("DELETE FROM %s WHERE version = '%s'", $this->getSchemaTableName(), $migration->getVersion());
         $this->query($sql);
     }
     return $this;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime)
 {
     if (strcasecmp($direction, MigrationInterface::UP) === 0) {
         // up
         $sql = sprintf("INSERT INTO %s ([version], [start_time], [end_time]) VALUES ('%s', '%s', '%s');", $this->getSchemaTableName(), $migration->getVersion(), $startTime, $endTime);
         $this->query($sql);
     } else {
         // down
         $sql = sprintf("DELETE FROM %s WHERE [version] = '%s'", $this->getSchemaTableName(), $migration->getVersion());
         $this->query($sql);
     }
     return $this;
 }
Пример #6
0
 /**
  * @inheritDoc
  */
 public function toggleBreakpoint(MigrationInterface $migration)
 {
     $this->query(sprintf('UPDATE %s SET breakpoint = CASE breakpoint WHEN 1 THEN 0 ELSE 1 END WHERE version = \'%s\';', $this->getSchemaTableName(), $migration->getversion()));
     return $this;
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime)
 {
     if (strcasecmp($direction, MigrationInterface::UP) === 0) {
         // up
         $sql = sprintf("INSERT INTO %s (version, migration_name, start_time, end_time, breakpoint) VALUES ('%s', '%s', '%s', '%s', 0);", $this->getSchemaTableName(), $migration->getVersion(), substr($migration->getName(), 0, 100), $startTime, $endTime);
         $this->query($sql);
     } else {
         // down
         $sql = sprintf("DELETE FROM %s WHERE version = '%s'", $this->getSchemaTableName(), $migration->getVersion());
         $this->query($sql);
     }
     return $this;
 }
Пример #8
0
 /**
  * @inheritDoc
  */
 public function toggleBreakpoint(MigrationInterface $migration)
 {
     $this->query(sprintf('UPDATE %1$s SET %2$s = CASE %2$s WHEN %3$s THEN %4$s ELSE %3$s END WHERE %5$s = \'%6$s\';', $this->getSchemaTableName(), $this->quoteColumnName('breakpoint'), $this->castToBool(true), $this->castToBool(false), $this->quoteColumnName('version'), $migration->getVersion()));
     return $this;
 }