Skip to content

Commit 2ed2ac1

Browse files
authored
Merge pull request #5640 from morozov/sql-server-alter-table-cleanup
Do not use ColumnDiff::$changedProperties in SQLServerPlatform::getAlterTableSQL()
2 parents f84b9d9 + f2e8c59 commit 2ed2ac1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/Platforms/SQLServerPlatform.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use function array_merge;
2323
use function array_unique;
2424
use function array_values;
25-
use function count;
2625
use function crc32;
2726
use function dechex;
2827
use function explode;
@@ -415,8 +414,15 @@ public function getAlterTableSQL(TableDiff $diff): array
415414
$commentsSql[] = $this->getCreateColumnCommentSQL($diff->name, $column->getQuotedName($this), $comment);
416415
}
417416

418-
// Do not add query part if only comment has changed.
419-
if ($columnDiff->hasChanged('comment') && count($columnDiff->changedProperties) === 1) {
417+
$columnNameSQL = $column->getQuotedName($this);
418+
419+
$oldDeclarationSQL = $this->getColumnDeclarationSQL($columnNameSQL, $columnDiff->fromColumn->toArray());
420+
$newDeclarationSQL = $this->getColumnDeclarationSQL($columnNameSQL, $column->toArray());
421+
422+
$declarationSQLChanged = $newDeclarationSQL !== $oldDeclarationSQL;
423+
$defaultChanged = $columnDiff->hasChanged('default');
424+
425+
if (! $declarationSQLChanged && ! $defaultChanged) {
420426
continue;
421427
}
422428

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

432-
$columnDef = $column->toArray();
433-
434-
$queryParts[] = 'ALTER COLUMN ' .
435-
$this->getColumnDeclarationSQL($column->getQuotedName($this), $columnDef);
438+
if ($declarationSQLChanged) {
439+
$queryParts[] = 'ALTER COLUMN ' . $newDeclarationSQL;
440+
}
436441

437442
if (
438-
! isset($columnDef['default'])
439-
|| (! $requireDropDefaultConstraint && ! $columnDiff->hasChanged('default'))
443+
$column->getDefault() === null
444+
|| (! $requireDropDefaultConstraint && ! $defaultChanged)
440445
) {
441446
continue;
442447
}

0 commit comments

Comments
 (0)