コード例 #1
0
ファイル: TableSchema.php プロジェクト: jwdeitch/components
 /**
  * {@inheritdoc}
  */
 protected function doColumnChange(AbstractColumn $column, AbstractColumn $dbColumn)
 {
     /**
      * @var ColumnSchema $column
      */
     //Rename is separate operation
     if ($column->getName() != $dbColumn->getName()) {
         $this->driver->statement(\Spiral\interpolate('ALTER TABLE {table} RENAME COLUMN {original} TO {column}', ['table' => $this->getName(true), 'column' => $column->getName(true), 'original' => $dbColumn->getName(true)]));
         $column->setName($dbColumn->getName());
     }
     //Postgres columns should be altered using set of operations
     if (!($operations = $column->alterOperations($dbColumn))) {
         return;
     }
     //Postgres columns should be altered using set of operations
     $query = \Spiral\interpolate('ALTER TABLE {table} {operations}', ['table' => $this->getName(true), 'operations' => trim(join(', ', $operations), ', ')]);
     $this->driver->statement($query);
 }
コード例 #2
0
ファイル: TableSchema.php プロジェクト: jwdeitch/components
 /**
  * {@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);
     }
 }