/**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $constraints = parent::getConstraints();
     if (!empty($this->enumConstraint)) {
         $constraints[] = $this->enumConstraint;
     }
     return $constraints;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 protected function doColumnChange(AbstractColumn $column, AbstractColumn $dbColumn)
 {
     /**
      * @var ColumnSchema $column
      * @var ColumnSchema $dbColumn
      */
     //Renaming is separate operation
     if ($column->getName() != $dbColumn->getName()) {
         $this->driver->statement("sp_rename ?, ?, 'COLUMN'", [$this->getName() . '.' . $dbColumn->getName(), $column->getName()]);
         $column->setName($dbColumn->getName());
     }
     //In SQLServer we have to drop ALL related indexes and foreign keys while
     //applying type change... yeah...
     $indexesBackup = [];
     $foreignBackup = [];
     foreach ($this->indexes as $index) {
         if (in_array($column->getName(), $index->getColumns())) {
             $indexesBackup[] = $index;
             $this->doIndexDrop($index);
         }
     }
     foreach ($this->references as $foreign) {
         if ($foreign->getColumn() == $column->getName()) {
             $foreignBackup[] = $foreign;
             $this->doForeignDrop($foreign);
         }
     }
     //Column will recreate needed constraints
     foreach ($column->getConstraints() as $constraint) {
         $this->doConstraintDrop($constraint);
     }
     foreach ($column->alterOperations($dbColumn) as $operation) {
         $query = \Spiral\interpolate('ALTER TABLE {table} {operation}', ['table' => $this->getName(true), 'operation' => $operation]);
         $this->driver->statement($query);
     }
     //Recreating indexes
     foreach ($indexesBackup as $index) {
         $this->doIndexAdd($index);
     }
     foreach ($foreignBackup as $foreign) {
         $this->doForeignAdd($foreign);
     }
 }
示例#3
0
 /**
  * Driver specific column remove (drop) command.
  *
  * @param AbstractColumn $column
  */
 protected function doColumnDrop(AbstractColumn $column)
 {
     //We have to erase all associated constraints
     foreach ($column->getConstraints() as $constraint) {
         $this->doConstraintDrop($constraint);
     }
     if ($this->hasForeign($column->getName())) {
         $this->doForeignDrop($this->foreign($column->getName()));
     }
     $this->driver->statement("ALTER TABLE {$this->getName(true)} DROP COLUMN {$column->getName(true)}");
 }
示例#4
0
 /**
  * Driver specific column remove (drop) command.
  *
  * @param AbstractTable  $table
  * @param AbstractColumn $column
  * @return self
  */
 public function dropColumn(AbstractTable $table, AbstractColumn $column)
 {
     foreach ($column->getConstraints() as $constraint) {
         //We have to erase all associated constraints
         $this->dropConstrain($table, $constraint);
     }
     $this->run("ALTER TABLE {$table->getName(true)} DROP COLUMN {$column->getName(true)}");
     return $this;
 }