Example #1
0
 public function add(AbstractMigration $migration)
 {
     $version = $migration->getVersion();
     if (array_key_exists($version, $this->migrations)) {
         throw new InvalidStateException("2 migrations with same version '{$version}' detected");
     }
     $this->migrations[$version] = $migration;
     ksort($this->migrations);
 }
Example #2
0
 public function migrate(AbstractMigration $migration)
 {
     $this->connection->begin();
     try {
         if (!$this->hasSchemaTable()) {
             $this->getAdapter()->createSchemaTable();
             $this->hasSchemaTable = true;
         }
         $migration->run();
         $this->getAdapter()->log($migration, time());
     } catch (\Exception $e) {
         $this->connection->rollback();
         throw $e;
     }
     $this->connection->commit();
 }
Example #3
0
 public final function run()
 {
     $this->dibiConnection->begin();
     try {
         parent::run();
     } catch (\Exception $e) {
         $this->dibiConnection->rollback();
         throw $e;
     }
     $this->dibiConnection->commit();
 }
Example #4
0
 public function log(AbstractMigration $migration, $timestamp)
 {
     $datetime = new \DateTime();
     $this->connection->insert($this->table, ['version' => $migration->getVersion(), 'executed' => $datetime->setTimestamp($timestamp)])->execute();
 }