22
22
use function array_merge ;
23
23
use function array_unique ;
24
24
use function array_values ;
25
- use function count ;
26
25
use function crc32 ;
27
26
use function dechex ;
28
27
use function explode ;
@@ -415,8 +414,15 @@ public function getAlterTableSQL(TableDiff $diff): array
415
414
$ commentsSql [] = $ this ->getCreateColumnCommentSQL ($ diff ->name , $ column ->getQuotedName ($ this ), $ comment );
416
415
}
417
416
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 ) {
420
426
continue ;
421
427
}
422
428
@@ -429,14 +435,13 @@ public function getAlterTableSQL(TableDiff $diff): array
429
435
);
430
436
}
431
437
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
+ }
436
441
437
442
if (
438
- ! isset ( $ columnDef [ ' default ' ])
439
- || (! $ requireDropDefaultConstraint && ! $ columnDiff -> hasChanged ( ' default ' ) )
443
+ $ column -> getDefault () === null
444
+ || (! $ requireDropDefaultConstraint && ! $ defaultChanged )
440
445
) {
441
446
continue ;
442
447
}
0 commit comments