@@ 722-738 (lines=17) @@ | ||
719 | $tableName = $diff->getName($this)->getQuotedName($this); |
|
720 | ||
721 | // Dropping primary keys requires to unset autoincrement attribute on the particular column first. |
|
722 | foreach ($index->getColumns() as $columnName) { |
|
723 | if (! $diff->fromTable->hasColumn($columnName)) { |
|
724 | continue; |
|
725 | } |
|
726 | ||
727 | $column = $diff->fromTable->getColumn($columnName); |
|
728 | ||
729 | if ($column->getAutoincrement() === true) { |
|
730 | $column->setAutoincrement(false); |
|
731 | ||
732 | $sql[] = 'ALTER TABLE ' . $tableName . ' MODIFY ' . |
|
733 | $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); |
|
734 | ||
735 | // original autoincrement information might be needed later on by other parts of the table alteration |
|
736 | $column->setAutoincrement(true); |
|
737 | } |
|
738 | } |
|
739 | ||
740 | return $sql; |
|
741 | } |
|
@@ 756-772 (lines=17) @@ | ||
753 | foreach ($diff->changedIndexes as $changedIndex) { |
|
754 | // Changed primary key |
|
755 | if ($changedIndex->isPrimary() && $diff->fromTable instanceof Table) { |
|
756 | foreach ($diff->fromTable->getPrimaryKeyColumns() as $columnName) { |
|
757 | $column = $diff->fromTable->getColumn($columnName); |
|
758 | ||
759 | // Check if an autoincrement column was dropped from the primary key. |
|
760 | if ($column->getAutoincrement() && ! in_array($columnName, $changedIndex->getColumns())) { |
|
761 | // The autoincrement attribute needs to be removed from the dropped column |
|
762 | // before we can drop and recreate the primary key. |
|
763 | $column->setAutoincrement(false); |
|
764 | ||
765 | $sql[] = 'ALTER TABLE ' . $table . ' MODIFY ' . |
|
766 | $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); |
|
767 | ||
768 | // Restore the autoincrement attribute as it might be needed later on |
|
769 | // by other parts of the table alteration. |
|
770 | $column->setAutoincrement(true); |
|
771 | } |
|
772 | } |
|
773 | } |
|
774 | } |
|
775 |