Example #1
0
 /**
  * Creates schama version table if not exists
  */
 public function createSchemaTable()
 {
     if (!($suffix = $this->getTableSuffix())) {
         return parent::createSchemaTable();
     }
     // if
     $sql = "\n            CREATE TABLE IF NOT EXISTS `s_schema_version_{$suffix}` (\n            `version` int(11) NOT NULL,\n            `start_date` datetime NOT NULL,\n            `complete_date` datetime DEFAULT NULL,\n            `name` VARCHAR( 255 ) NOT NULL,\n            `error_msg` varchar(255) DEFAULT NULL,\n            PRIMARY KEY (`version`)\n            ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci\n        ";
     $this->connection->exec($sql);
 }
 /**
  * @param  int                                  $offset
  * @param  int                                  $totalCount
  * @return ErrorResult|FinishResult|ValidResult
  */
 public function run($offset, $totalCount = null)
 {
     if ($offset == 0) {
         $this->migrationManager->createSchemaTable();
     }
     $currentVersion = $this->migrationManager->getCurrentVersion();
     if (!$totalCount) {
         $totalCount = count($this->migrationManager->getMigrationsForVersion($currentVersion));
     }
     $migration = $this->migrationManager->getNextMigrationForVersion($currentVersion);
     if (null === $migration) {
         return new FinishResult($offset, $totalCount);
     }
     try {
         $this->migrationManager->apply($migration);
     } catch (\Exception $e) {
         $reflection = new \ReflectionClass(get_class($migration));
         $classFile = $reflection->getFileName();
         return new ErrorResult($e->getMessage(), $e, array('deltaFile' => $classFile, 'deltaVersion' => $migration->getVersion(), 'deltaLabel' => $migration->getLabel()));
     }
     return new ValidResult($offset + 1, $totalCount, array('deltaVersion' => $migration->getVersion(), 'deltaLabel' => $migration->getLabel()));
 }