Exemplo n.º 1
0
 public function getSql()
 {
     $out = array();
     $executedMigrations = $this->getMigrationIdFromBase();
     $migrations = $this->_getMigrations();
     rsort($migrations);
     foreach ($migrations as $migrationId) {
         $migration = new Migration($migrationId);
         $migration->setIsExecuted(in_array($migrationId, $executedMigrations));
         $out[] = $migration;
     }
     return $out;
 }
Exemplo n.º 2
0
 protected function _getDownSql($migrationId, $checkLastMigrationId = true)
 {
     if (!$migrationId) {
         $this->_writeError('Need Migration ID');
     }
     $allMigrationId = $this->_getMigrations();
     if (!$allMigrationId) {
         $this->_writeError('No actual migrations');
     }
     if (!in_array($migrationId, $allMigrationId) && !in_array($migrationId, array_map(function ($item) {
         return substr($item, 0, 14);
     }, $allMigrationId))) {
         $this->_writeError('Wrong Migration ID: migration ' . $migrationId . ' not exist');
     }
     if ($this->getLastMigrationId()) {
         preg_match('/^(\\d{14})/', $this->getLastMigrationId(), $s);
         $lastMigrationIdOnlyDigits = $s[1];
     } else {
         $lastMigrationIdOnlyDigits = 0;
     }
     preg_match('/^(\\d{14})/', $migrationId, $s);
     $currentMigrationIdOnlyDigits = $s[1];
     $validMigrationId = array();
     if ($checkLastMigrationId) {
         foreach ($allMigrationId as $currentMigrationId) {
             preg_match('/^(\\d{14})/', $currentMigrationId, $part);
             if ($part[0] > $lastMigrationIdOnlyDigits || $part[0] < $currentMigrationIdOnlyDigits) {
                 continue;
             }
             $validMigrationId[] = $currentMigrationId;
         }
     } else {
         $validMigrationId = $allMigrationId;
     }
     if (!$validMigrationId) {
         return array();
     }
     rsort($validMigrationId);
     $out = array();
     foreach ($validMigrationId as $currentMigrationId) {
         $migration = new Migration($currentMigrationId);
         $out[] = array('migrationId' => $migration->getMigrationId(), 'sql' => $migration->getDownSql(), 'description' => $migration->getDescription());
     }
     return $out;
 }