@@ -17,34 +17,33 @@ trait GrammarTypes
17
17
*/
18
18
public function compileChange (BaseBlueprint $ blueprint , Fluent $ command , Connection $ connection ): array
19
19
{
20
- $ queries = [];
21
-
22
20
// The table prefix is accessed differently based on Laravel version. In old version the $prefix was public,
23
21
// while with new ones the $blueprint->prefix() method should be used. The issue is solved by invading the
24
22
// object and getting the property directly.
25
23
$ prefix = (fn () => $ this ->prefix )->call ($ blueprint );
26
24
27
- foreach ($ blueprint ->getChangedColumns () as $ changedColumn ) {
28
- $ blueprintColumn = new BaseBlueprint ($ blueprint ->getTable (), null , $ prefix );
29
- $ blueprintColumn ->addColumn (
30
- $ changedColumn ['type ' ],
31
- $ changedColumn ['name ' ],
32
- Arr::except ($ changedColumn ->toArray (), ['compression ' ]),
33
- );
34
-
35
- // Remove Compression modifier because Laravel 11 won't work correctly with it (migrator builts incorrectly SQL).
36
- $ _modifiers = $ this ->modifiers ;
37
- $ this ->modifiers = array_filter ($ this ->modifiers , fn ($ str ) => !\in_array ($ str , ['Compression ' ]));
38
- $ changes = Arr::wrap (parent ::compileChange ($ blueprintColumn , $ command , $ connection ));
39
- $ this ->modifiers = $ _modifiers ;
40
-
41
- foreach ($ changes as $ sql ) {
25
+ // In Laravel 11.15.0 the logic was changed that compileChange is only for one column (the one in the command)
26
+ // of the blueprint and not all ones of the blueprint as before.
27
+ /** @var \Illuminate\Database\Schema\ColumnDefinition[] $columns */
28
+ $ columns = isset ($ command ['column ' ]) ? [$ command ['column ' ]] : $ blueprint ->getChangedColumns ();
29
+
30
+ $ queries = [];
31
+ foreach ($ columns as $ column ) {
32
+ $ modifierCompression = $ column ['compression ' ];
33
+ $ modifierUsing = $ column ['using ' ];
34
+ unset($ column ['compression ' ], $ column ['using ' ]);
35
+
36
+ $ blueprintColumnExtract = new BaseBlueprint ($ blueprint ->getTable (), null , $ prefix );
37
+ $ blueprintColumnExtract ->addColumn ($ column ['type ' ], $ column ['name ' ], $ column ->toArray ());
38
+ $ blueprintColumnExtractQueries = Arr::wrap (parent ::compileChange ($ blueprint , $ command , $ connection ));
39
+
40
+ foreach ($ blueprintColumnExtractQueries as $ sql ) {
42
41
$ regex = Regex::match ('/^ALTER table (?P<table>.*?) alter (column )?(?P<column>.*?) type (?P<type>\w+)(?P<modifiers>,.*)?/i ' , $ sql );
43
42
44
- if (filled ($ changedColumn [ ' using ' ] ) && $ regex ->hasMatch ()) {
45
- $ using = match ($ connection ->getSchemaGrammar ()->isExpression ($ changedColumn [ ' using ' ] )) {
46
- true => $ connection ->getSchemaGrammar ()->getValue ($ changedColumn [ ' using ' ] ),
47
- false => $ changedColumn [ ' using ' ] ,
43
+ if (filled ($ modifierUsing ) && $ regex ->hasMatch ()) {
44
+ $ using = match ($ connection ->getSchemaGrammar ()->isExpression ($ modifierUsing )) {
45
+ true => $ connection ->getSchemaGrammar ()->getValue ($ modifierUsing ),
46
+ false => $ modifierUsing ,
48
47
};
49
48
50
49
$ queries [] = match (filled ($ modifiers = $ regex ->groupOr ('modifiers ' , '' ))) {
@@ -56,13 +55,8 @@ public function compileChange(BaseBlueprint $blueprint, Fluent $command, Connect
56
55
}
57
56
}
58
57
59
- if (filled ($ changedColumn ['compression ' ])) {
60
- $ queries [] = sprintf (
61
- 'alter table %s alter %s set compression %s ' ,
62
- $ this ->wrapTable ($ blueprint ->getTable ()),
63
- $ this ->wrap ($ changedColumn ['name ' ]),
64
- $ this ->wrap ($ changedColumn ['compression ' ]),
65
- );
58
+ if (filled ($ modifierCompression )) {
59
+ $ queries [] = "alter table {$ this ->wrapTable ($ blueprint )} alter {$ this ->wrap ($ column ['name ' ])} set compression {$ this ->wrap ($ modifierCompression )}" ;
66
60
}
67
61
}
68
62
0 commit comments