From f2e8c59d9f2942962b3262c3ed84516ea9e5a9d5 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 31 Aug 2022 19:29:45 -0700 Subject: [PATCH] Do not use ColumnDiff::$changedProperties in SQLServerPlatform::getAlterTableSQL() --- src/Platforms/SQLServerPlatform.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Platforms/SQLServerPlatform.php b/src/Platforms/SQLServerPlatform.php index cfb7c260314..1b5c4ff85f4 100644 --- a/src/Platforms/SQLServerPlatform.php +++ b/src/Platforms/SQLServerPlatform.php @@ -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; @@ -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; } @@ -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; }