Example #1
0
 /**
  * get difference between two schemes of tables
  * @param $table
  * @param $tblCurrentCols
  * @param $tblPublishedCols
  */
 protected function createDifferenceInsideTable($table, $tblCurrentCols, $tblPublishedCols)
 {
     foreach ($tblCurrentCols as $currCol) {
         $colForCompare = $this->checkColumnExists($currCol, $tblPublishedCols);
         if (!$colForCompare) {
             $this->up(Database::addColumn($table, $currCol));
             $this->down(Database::dropColumn($table, $currCol));
         } else {
             if ($currCol === $colForCompare) {
                 continue;
             }
             $sql = Database::changeColumn($table, $currCol);
             $this->up($sql);
             $sql = Database::changeColumn($table, $colForCompare);
             $this->down($sql);
         }
     }
     foreach ($tblPublishedCols as $publishedColumn) {
         $has = $this->checkColumnExists($publishedColumn, $tblCurrentCols);
         if (!$has) {
             $constraint = $this->getConstraintForColumn($table, $publishedColumn['COLUMN_NAME']);
             if (count($constraint)) {
                 $this->down(Database::addConstraint(array('constraint' => $constraint)));
                 $this->up(Database::dropConstraint(array('constraint' => $constraint)));
             }
             $this->down(Database::addColumn($table, $publishedColumn));
             $this->up(Database::dropColumn($table, $publishedColumn));
         }
     }
 }