[2.0] DDC-169 - Fix order that column and index/fk changes are applied in alter table.
This commit is contained in:
parent
58e99d39d2
commit
34119d3925
5 changed files with 24 additions and 12 deletions
|
@ -802,29 +802,35 @@ abstract class AbstractPlatform
|
||||||
*/
|
*/
|
||||||
protected function _getAlterTableIndexForeignKeySql(TableDiff $diff)
|
protected function _getAlterTableIndexForeignKeySql(TableDiff $diff)
|
||||||
{
|
{
|
||||||
|
if ($diff->newName !== false) {
|
||||||
|
$tableName = $diff->newName;
|
||||||
|
} else {
|
||||||
|
$tableName = $diff->name;
|
||||||
|
}
|
||||||
|
|
||||||
$sql = array();
|
$sql = array();
|
||||||
if ($this->supportsForeignKeyConstraints()) {
|
if ($this->supportsForeignKeyConstraints()) {
|
||||||
foreach ($diff->addedForeignKeys AS $foreignKey) {
|
foreach ($diff->addedForeignKeys AS $foreignKey) {
|
||||||
$sql[] = $this->getCreateForeignKeySql($foreignKey, $diff->name);
|
$sql[] = $this->getCreateForeignKeySql($foreignKey, $tableName);
|
||||||
}
|
}
|
||||||
foreach ($diff->removedForeignKeys AS $foreignKey) {
|
foreach ($diff->removedForeignKeys AS $foreignKey) {
|
||||||
$sql[] = $this->getDropForeignKeySql($foreignKey, $diff->name);
|
$sql[] = $this->getDropForeignKeySql($foreignKey, $tableName);
|
||||||
}
|
}
|
||||||
foreach ($diff->changedForeignKeys AS $foreignKey) {
|
foreach ($diff->changedForeignKeys AS $foreignKey) {
|
||||||
$sql[] = $this->getDropForeignKeySql($foreignKey, $diff->name);
|
$sql[] = $this->getDropForeignKeySql($foreignKey, $tableName);
|
||||||
$sql[] = $this->getCreateForeignKeySql($foreignKey, $diff->name);
|
$sql[] = $this->getCreateForeignKeySql($foreignKey, $tableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($diff->addedIndexes AS $index) {
|
foreach ($diff->addedIndexes AS $index) {
|
||||||
$sql[] = $this->getCreateIndexSql($index, $diff->name);
|
$sql[] = $this->getCreateIndexSql($index, $tableName);
|
||||||
}
|
}
|
||||||
foreach ($diff->removedIndexes AS $index) {
|
foreach ($diff->removedIndexes AS $index) {
|
||||||
$sql[] = $this->getDropIndexSql($index, $diff->name);
|
$sql[] = $this->getDropIndexSql($index, $tableName);
|
||||||
}
|
}
|
||||||
foreach ($diff->changedIndexes AS $index) {
|
foreach ($diff->changedIndexes AS $index) {
|
||||||
$sql[] = $this->getDropIndexSql($index, $diff->name);
|
$sql[] = $this->getDropIndexSql($index, $tableName);
|
||||||
$sql[] = $this->getCreateIndexSql($index, $diff->name);
|
$sql[] = $this->getCreateIndexSql($index, $tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
|
|
|
@ -125,10 +125,11 @@ class MsSqlPlatform extends AbstractPlatform
|
||||||
. $this->getColumnDeclarationSql($column->getName(), $column->toArray());
|
. $this->getColumnDeclarationSql($column->getName(), $column->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = $this->_getAlterTableIndexForeignKeySql($diff);
|
$sql = array();
|
||||||
if (count($queryParts) > 0) {
|
if (count($queryParts) > 0) {
|
||||||
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
|
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
|
||||||
}
|
}
|
||||||
|
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -620,10 +620,11 @@ class MySqlPlatform extends AbstractPlatform
|
||||||
. $this->getColumnDeclarationSql($column->getName(), $column->toArray());
|
. $this->getColumnDeclarationSql($column->getName(), $column->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = $this->_getAlterTableIndexForeignKeySql($diff);
|
$sql = array();
|
||||||
if (count($queryParts) > 0) {
|
if (count($queryParts) > 0) {
|
||||||
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
|
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
|
||||||
}
|
}
|
||||||
|
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -477,7 +477,7 @@ END;';
|
||||||
*/
|
*/
|
||||||
public function getAlterTableSql(TableDiff $diff)
|
public function getAlterTableSql(TableDiff $diff)
|
||||||
{
|
{
|
||||||
$sql = $this->_getAlterTableIndexForeignKeySql($diff);
|
$sql = array();
|
||||||
|
|
||||||
$fields = array();
|
$fields = array();
|
||||||
foreach ($diff->addedColumns AS $column) {
|
foreach ($diff->addedColumns AS $column) {
|
||||||
|
@ -512,6 +512,8 @@ END;';
|
||||||
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
|
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -493,7 +493,7 @@ class PostgreSqlPlatform extends AbstractPlatform
|
||||||
*/
|
*/
|
||||||
public function getAlterTableSql(TableDiff $diff)
|
public function getAlterTableSql(TableDiff $diff)
|
||||||
{
|
{
|
||||||
$sql = $this->_getAlterTableIndexForeignKeySql($diff);
|
$sql = array();
|
||||||
|
|
||||||
foreach ($diff->addedColumns as $column) {
|
foreach ($diff->addedColumns as $column) {
|
||||||
$query = 'ADD ' . $this->getColumnDeclarationSql($column->getName(), $column->toArray());
|
$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[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue