Beispiel #1
0
 /**
  * Down
  *
  * @param Migration $migration
  * @return AdapterInterface
  */
 public function down(Migration $migration)
 {
     $versions = $this->fetchAll();
     if (!in_array($migration->getVersion(), $versions)) {
         return;
     }
     unset($versions[array_search($migration->getVersion(), $versions)]);
     $this->write($versions);
     return $this;
 }
Beispiel #2
0
 /**
  * Run a migration in a particular direction
  *
  * @param Migration $migration
  * @param string $direction
  * @return void
  */
 protected function run(Migration $migration, $direction = 'up')
 {
     $direction = $direction == 'down' ? 'down' : 'up';
     $this->getOutput()->writeln(sprintf(' == <info>' . $migration->getVersion() . ' ' . $migration->getName() . '</info> ' . '<comment>' . ($direction == 'up' ? 'migrating' : 'reverting') . '</comment>'));
     $start = microtime(1);
     $migration->setContainer($this->getContainer());
     $migration->init();
     $migration->{$direction}();
     $this->getAdapter()->{$direction}($migration);
     $end = microtime(1);
     $this->getOutput()->writeln(sprintf(' == <info>' . $migration->getVersion() . ' ' . $migration->getName() . '</info> ' . '<comment>' . ($direction == 'up' ? 'migrated ' : 'reverted ') . sprintf("%.4fs", $end - $start) . '</comment>'));
 }
 /**
  * Down
  *
  * @param \Phpmig\Migration\Migration $migration
  * @return \Phpmig\Adapter\AdapterInterface
  */
 public function down(\Phpmig\Migration\Migration $migration)
 {
     if (!$this->_hasSchema()) {
         $this->_createSchema();
     }
     $versions = $this->fetchAll();
     if (!in_array($migration->getVersion(), $versions)) {
         return $this;
     }
     unset($versions[array_search($migration->getVersion(), $versions)]);
     $this->write($versions);
     return $this;
 }
Beispiel #4
0
    /**
     * @param  Migration $migration
     * @return fluent
     */
    public function down(Migration $migration)
    {
        $version = $migration->getVersion();
        $sql = <<<SQL
SELECT *
FROM migrations.migrations
WHERE version = :version
ORDER BY version
SQL;
        $version_row = $this->yo_pdo->query($sql, ['version' => $version])->fetch();
        if (!$version_row) {
            throw new Exception("Migration '{$version}' cannot be rolled back because it is not currently applied.");
        }
        $migration_reflection = new ReflectionClass(get_class($migration));
        $this->yo_pdo->insert('migrations.rollbacks', ['version' => $version_row['version'], 'migrated_at' => $version_row['migrated_at'], 'migration_hash' => $version_row['migration_hash'], 'rollback_hash' => hash_file('sha256', $migration_reflection->getFileName())]);
        $this->yo_pdo->delete('migrations.migrations', 'version = :version', ['version' => $migration->getVersion()]);
        return $this;
    }
 public function setContainer(\ArrayAccess $container)
 {
     $this->_container = $container;
     return parent::setContainer($container);
 }
Beispiel #6
0
 /**
  * Down
  *
  * @param Migration $migration
  * @return self
  */
 public function down(Migration $migration)
 {
     $sql = $this->getQuery('down');
     $this->connection->prepare($sql)->execute(array(':version' => $migration->getVersion()));
     return $this;
 }
Beispiel #7
0
 /**
  * Down
  *
  * @param Migration $migration
  * @return self
  */
 public function down(Migration $migration)
 {
     $sql = "DELETE from {$this->quotedTableName()} where version = :version";
     $this->connection->prepare($sql)->execute(array(':version' => $migration->getVersion()));
     return $this;
 }
Beispiel #8
0
 /**
  * Down
  *
  * @param Migration $migration
  * @return AdapterInterface
  */
 public function down(Migration $migration)
 {
     $this->adapter->delete($this->tableName, $this->adapter->quoteInto('version = ?', $migration->getVersion()));
     return $this;
 }
 /**
  * @test
  */
 public function shouldRetrieveServices()
 {
     $this->migration->setContainer(new \ArrayObject(array('service' => 123)));
     $this->assertEquals(123, $this->migration->get('service'));
 }
Beispiel #10
0
 /**
  * Down
  *
  * @param Migration $migration
  * @return DBAL
  */
 public function down(Migration $migration)
 {
     $this->connection->delete($this->tableName, array('version' => $migration->getVersion()));
     return $this;
 }
Beispiel #11
0
 /**
  * Down
  *
  * @param Migration $migration
  * @return AdapterInterface
  */
 public function down(Migration $migration)
 {
     $this->tableGateway()->delete(['version' => $migration->getVersion()]);
     return $this;
 }
Beispiel #12
0
 /**
  * Down
  *
  * @param Migration $migration
  * @return self
  */
 public function down(Migration $migration)
 {
     $this->connection->selectCollection($this->tableName)->remove(array('version' => $migration->getVersion()));
     return $this;
 }
Beispiel #13
0
 public function testMigrationVersion()
 {
     $this->assertEquals(1, $this->migration->getVersion());
 }
 /**
  * Down
  *
  * @param Migration $migration
  *
  * @return AdapterInterface
  */
 public function down(Migration $migration)
 {
     $helper = $this->helper;
     $this->db->queryExecute(sprintf('DELETE FROM %s WHERE %s = \'%s\'', $helper->quote($this->tableName), $helper->quote('version'), $helper->forSql($migration->getVersion())));
     return $this;
 }
Beispiel #15
0
 public function down(Migration $migration)
 {
     $this->connection->where('version', $migration->getVersion());
     $this->connection->delete($this->tableName);
     return $this;
 }
Beispiel #16
0
 /**
  * Down
  *
  * @param Migration $migration
  * @return AdapterInterface
  */
 public function down(Migration $migration)
 {
     $this->adapter->table($this->tableName)->where('version', $migration->getVersion())->delete();
     return $this;
 }
Beispiel #17
0
 /**
  * Down
  *
  * @param Migration $migration
  *
  * @return self
  */
 public function down(Migration $migration)
 {
     $sql = 'DELETE from "' . $this->tableName . '" where "version" = :version';
     $this->connection->prepare($sql)->execute(array(':version' => $migration->getVersion()));
     return $this;
 }