Skip to content

Commit

Permalink
Merge pull request #5640 from morozov/sql-server-alter-table-cleanup
Browse files Browse the repository at this point in the history
Do not use ColumnDiff::$changedProperties in SQLServerPlatform::getAlterTableSQL()
  • Loading branch information
morozov authored Sep 1, 2022
2 parents f84b9d9 + f2e8c59 commit 2ed2ac1
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use function array_merge;
use function array_unique;
use function array_values;
use function count;
use function crc32;
use function dechex;
use function explode;
Expand Down Expand Up @@ -415,8 +414,15 @@ public function getAlterTableSQL(TableDiff $diff): array
$commentsSql[] = $this->getCreateColumnCommentSQL($diff->name, $column->getQuotedName($this), $comment);
}

// Do not add query part if only comment has changed.
if ($columnDiff->hasChanged('comment') && count($columnDiff->changedProperties) === 1) {
$columnNameSQL = $column->getQuotedName($this);

$oldDeclarationSQL = $this->getColumnDeclarationSQL($columnNameSQL, $columnDiff->fromColumn->toArray());
$newDeclarationSQL = $this->getColumnDeclarationSQL($columnNameSQL, $column->toArray());

$declarationSQLChanged = $newDeclarationSQL !== $oldDeclarationSQL;
$defaultChanged = $columnDiff->hasChanged('default');

if (! $declarationSQLChanged && ! $defaultChanged) {
continue;
}

Expand All @@ -429,14 +435,13 @@ public function getAlterTableSQL(TableDiff $diff): array
);
}

$columnDef = $column->toArray();

$queryParts[] = 'ALTER COLUMN ' .
$this->getColumnDeclarationSQL($column->getQuotedName($this), $columnDef);
if ($declarationSQLChanged) {
$queryParts[] = 'ALTER COLUMN ' . $newDeclarationSQL;
}

if (
! isset($columnDef['default'])
|| (! $requireDropDefaultConstraint && ! $columnDiff->hasChanged('default'))
$column->getDefault() === null
|| (! $requireDropDefaultConstraint && ! $defaultChanged)
) {
continue;
}
Expand Down

0 comments on commit 2ed2ac1

Please sign in to comment.