Commit 02114bfc authored by Steve Müller's avatar Steve Müller

move pre alter table alter index SQL to private method

parent 14b54bb2
......@@ -657,28 +657,6 @@ class MySqlPlatform extends AbstractPlatform
}
}
// handle columns that are removed from changed indexes
foreach ($diff->changedIndexes as $chgKey => $chgIndex) {
// Dropping primary keys requires to unset autoincrement attribute on the particular column first
if ($chgIndex->isPrimary() && $diff->fromTable instanceof Table) {
// when chgIndex->isPrimary we can be sure fromTable->hasPrimaryKey is true
foreach ($diff->fromTable->getPrimaryKeyColumns() as $columnName) {
$column = $diff->fromTable->getColumn($columnName);
if ($column->getAutoincrement() === true && in_array($columnName, $chgIndex->getColumns()) === false) {
$column->setAutoincrement(false);
$sql[] = 'ALTER TABLE ' . $table . ' MODIFY ' .
$this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
// original autoincrement information might be needed later on by other parts of the table alteration
$column->setAutoincrement(true);
}
}
}
}
$engine = 'INNODB';
if ($diff->fromTable instanceof Table && $diff->fromTable->hasOption('engine')) {
......@@ -694,6 +672,7 @@ class MySqlPlatform extends AbstractPlatform
$sql = array_merge(
$sql,
$this->getPreAlterTableAlterIndexForeignKeySQL($diff),
parent::getPreAlterTableIndexForeignKeySQL($diff),
$this->getPreAlterTableRenameIndexForeignKeySQL($diff)
);
......@@ -701,6 +680,42 @@ class MySqlPlatform extends AbstractPlatform
return $sql;
}
/**
* @param TableDiff $diff The table diff to gather the SQL for.
*
* @return array
*/
private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff)
{
$sql = array();
$table = $diff->getName($this)->getQuotedName($this);
foreach ($diff->changedIndexes as $changedIndex) {
// Changed primary key
if ($changedIndex->isPrimary() && $diff->fromTable instanceof Table) {
foreach ($diff->fromTable->getPrimaryKeyColumns() as $columnName) {
$column = $diff->fromTable->getColumn($columnName);
// Check if an autoincrement column was dropped from the primary key.
if ($column->getAutoincrement() && ! in_array($columnName, $changedIndex->getColumns())) {
// The autoincrement attribute needs to be removed from the dropped column
// before we can drop and recreate the primary key.
$column->setAutoincrement(false);
$sql[] = 'ALTER TABLE ' . $table . ' MODIFY ' .
$this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
// Restore the autoincrement attribute as it might be needed later on
// by other parts of the table alteration.
$column->setAutoincrement(true);
}
}
}
}
return $sql;
}
/**
* @param TableDiff $diff The table diff to gather the SQL for.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment