Example #1
0
 /**
  * Get difference between table indexes
  *
  * @param $table
  */
 protected function createIndexDifference($table)
 {
     $currentIndexes = $this->currentDb->getIndexList($table);
     $publishedIndexes = $this->publishedDb->getIndexList($table);
     foreach ($currentIndexes as $curIndex) {
         $indexForCompare = $this->findIndex($curIndex, $publishedIndexes);
         if (!$indexForCompare) {
             $this->up(Database::addIndex($curIndex));
             $this->up(Database::addConstraint($curIndex));
             $this->down(Database::dropConstraint($curIndex));
             $this->down(Database::dropIndex($curIndex));
         } elseif ($indexForCompare !== $curIndex) {
             $this->up(Database::dropConstraint($curIndex));
             $this->up(Database::dropIndex($curIndex));
             $this->down(Database::dropConstraint($curIndex));
             $this->down(Database::dropIndex($curIndex));
             $this->down(Database::addIndex($indexForCompare));
             $this->down(Database::addConstraint($indexForCompare));
         }
     }
     //For creating deleted indexes
     $deletedIndexes = $this->getDeletedIndexes($currentIndexes, $publishedIndexes);
     if ($deletedIndexes) {
         foreach ($deletedIndexes as $deletedIndex) {
             //Create deleted index
             $this->up(Database::dropConstraint($deletedIndex));
             $this->up(Database::dropIndex($deletedIndex));
             //Delete index
             $this->down(Database::addConstraint($deletedIndex));
             $this->down(Database::addIndex($deletedIndex));
         }
     }
 }