1
0
mirror of synced 2024-12-12 22:36:02 +03:00

[2.0] DDC-169 - Fix order that column and index/fk changes are applied in alter table.

This commit is contained in:
beberlei 2009-12-06 13:00:49 +00:00
parent 58e99d39d2
commit 34119d3925
5 changed files with 24 additions and 12 deletions

View File

@ -802,29 +802,35 @@ abstract class AbstractPlatform
*/
protected function _getAlterTableIndexForeignKeySql(TableDiff $diff)
{
if ($diff->newName !== false) {
$tableName = $diff->newName;
} else {
$tableName = $diff->name;
}
$sql = array();
if ($this->supportsForeignKeyConstraints()) {
foreach ($diff->addedForeignKeys AS $foreignKey) {
$sql[] = $this->getCreateForeignKeySql($foreignKey, $diff->name);
$sql[] = $this->getCreateForeignKeySql($foreignKey, $tableName);
}
foreach ($diff->removedForeignKeys AS $foreignKey) {
$sql[] = $this->getDropForeignKeySql($foreignKey, $diff->name);
$sql[] = $this->getDropForeignKeySql($foreignKey, $tableName);
}
foreach ($diff->changedForeignKeys AS $foreignKey) {
$sql[] = $this->getDropForeignKeySql($foreignKey, $diff->name);
$sql[] = $this->getCreateForeignKeySql($foreignKey, $diff->name);
$sql[] = $this->getDropForeignKeySql($foreignKey, $tableName);
$sql[] = $this->getCreateForeignKeySql($foreignKey, $tableName);
}
}
foreach ($diff->addedIndexes AS $index) {
$sql[] = $this->getCreateIndexSql($index, $diff->name);
$sql[] = $this->getCreateIndexSql($index, $tableName);
}
foreach ($diff->removedIndexes AS $index) {
$sql[] = $this->getDropIndexSql($index, $diff->name);
$sql[] = $this->getDropIndexSql($index, $tableName);
}
foreach ($diff->changedIndexes AS $index) {
$sql[] = $this->getDropIndexSql($index, $diff->name);
$sql[] = $this->getCreateIndexSql($index, $diff->name);
$sql[] = $this->getDropIndexSql($index, $tableName);
$sql[] = $this->getCreateIndexSql($index, $tableName);
}
return $sql;

View File

@ -125,10 +125,11 @@ class MsSqlPlatform extends AbstractPlatform
. $this->getColumnDeclarationSql($column->getName(), $column->toArray());
}
$sql = $this->_getAlterTableIndexForeignKeySql($diff);
$sql = array();
if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
return $sql;
}

View File

@ -620,10 +620,11 @@ class MySqlPlatform extends AbstractPlatform
. $this->getColumnDeclarationSql($column->getName(), $column->toArray());
}
$sql = $this->_getAlterTableIndexForeignKeySql($diff);
$sql = array();
if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
return $sql;
}

View File

@ -477,7 +477,7 @@ END;';
*/
public function getAlterTableSql(TableDiff $diff)
{
$sql = $this->_getAlterTableIndexForeignKeySql($diff);
$sql = array();
$fields = array();
foreach ($diff->addedColumns AS $column) {
@ -512,6 +512,8 @@ END;';
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
return $sql;
}

View File

@ -493,7 +493,7 @@ class PostgreSqlPlatform extends AbstractPlatform
*/
public function getAlterTableSql(TableDiff $diff)
{
$sql = $this->_getAlterTableIndexForeignKeySql($diff);
$sql = array();
foreach ($diff->addedColumns as $column) {
$query = 'ADD ' . $this->getColumnDeclarationSql($column->getName(), $column->toArray());
@ -534,6 +534,8 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
return $sql;
}