コード例 #1
0
ファイル: Table.php プロジェクト: rimantoro/mysql-diff
 protected function addForeignKeyField(Table $target, ForeignKey $fk)
 {
     $field = $target->getField($fk->getKey());
     $parts = [sprintf('ADD COLUMN %s', $field->getDefinitionString())];
     $this->fields[$fk->getKey()] = $field;
     //add field
     /** @var Index $idx */
     foreach ($target->getIndexesWithField($field->getName()) as $name => $idx) {
         /*if ($this->hasIndex($name)) {
               //perhaps redefine indexes
               $parts[] = sprintf(
                   'DROP INDEX `%s`',
                   $name
               );
           }*/
         if (!$this->hasIndex($name)) {
             $parts[] = 'ADD ' . $idx->getDefinitionString();
             $this->indexes[$name] = $idx;
             //add new index
         }
     }
     return $parts;
 }