@@ -324,43 +324,56 @@ public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Conne
324
324
325
325
if (($ connection ->isMaria () && version_compare ($ version , '10.5.2 ' , '< ' )) ||
326
326
(! $ connection ->isMaria () && version_compare ($ version , '8.0.3 ' , '< ' ))) {
327
- $ column = collect ($ connection ->getSchemaBuilder ()->getColumns ($ blueprint ->getTable ()))
328
- ->firstWhere ('name ' , $ command ->from );
329
-
330
- $ modifiers = $ this ->addModifiers ($ column ['type ' ], $ blueprint , new ColumnDefinition ([
331
- 'change ' => true ,
332
- 'type ' => match ($ column ['type_name ' ]) {
333
- 'bigint ' => 'bigInteger ' ,
334
- 'int ' => 'integer ' ,
335
- 'mediumint ' => 'mediumInteger ' ,
336
- 'smallint ' => 'smallInteger ' ,
337
- 'tinyint ' => 'tinyInteger ' ,
338
- default => $ column ['type_name ' ],
339
- },
340
- 'nullable ' => $ column ['nullable ' ],
341
- 'default ' => $ column ['default ' ] && str_starts_with (strtolower ($ column ['default ' ]), 'current_timestamp ' )
342
- ? new Expression ($ column ['default ' ])
343
- : $ column ['default ' ],
344
- 'autoIncrement ' => $ column ['auto_increment ' ],
345
- 'collation ' => $ column ['collation ' ],
346
- 'comment ' => $ column ['comment ' ],
347
- 'virtualAs ' => ! is_null ($ column ['generation ' ]) && $ column ['generation ' ]['type ' ] === 'virtual '
348
- ? $ column ['generation ' ]['expression ' ] : null ,
349
- 'storedAs ' => ! is_null ($ column ['generation ' ]) && $ column ['generation ' ]['type ' ] === 'stored '
350
- ? $ column ['generation ' ]['expression ' ] : null ,
351
- ]));
352
-
353
- return sprintf ('alter table %s change %s %s %s ' ,
354
- $ this ->wrapTable ($ blueprint ),
355
- $ this ->wrap ($ command ->from ),
356
- $ this ->wrap ($ command ->to ),
357
- $ modifiers
358
- );
327
+ return $ this ->compileLegacyRenameColumn ($ blueprint , $ command , $ connection );
359
328
}
360
329
361
330
return parent ::compileRenameColumn ($ blueprint , $ command , $ connection );
362
331
}
363
332
333
+ /**
334
+ * Compile a rename column command for legacy versions of MySQL.
335
+ *
336
+ * @param \Illuminate\Database\Schema\Blueprint $blueprint
337
+ * @param \Illuminate\Support\Fluent $command
338
+ * @param \Illuminate\Database\Connection $connection
339
+ * @return string
340
+ */
341
+ protected function compileLegacyRenameColumn (Blueprint $ blueprint , Fluent $ command , Connection $ connection )
342
+ {
343
+ $ column = collect ($ connection ->getSchemaBuilder ()->getColumns ($ blueprint ->getTable ()))
344
+ ->firstWhere ('name ' , $ command ->from );
345
+
346
+ $ modifiers = $ this ->addModifiers ($ column ['type ' ], $ blueprint , new ColumnDefinition ([
347
+ 'change ' => true ,
348
+ 'type ' => match ($ column ['type_name ' ]) {
349
+ 'bigint ' => 'bigInteger ' ,
350
+ 'int ' => 'integer ' ,
351
+ 'mediumint ' => 'mediumInteger ' ,
352
+ 'smallint ' => 'smallInteger ' ,
353
+ 'tinyint ' => 'tinyInteger ' ,
354
+ default => $ column ['type_name ' ],
355
+ },
356
+ 'nullable ' => $ column ['nullable ' ],
357
+ 'default ' => $ column ['default ' ] && str_starts_with (strtolower ($ column ['default ' ]), 'current_timestamp ' )
358
+ ? new Expression ($ column ['default ' ])
359
+ : $ column ['default ' ],
360
+ 'autoIncrement ' => $ column ['auto_increment ' ],
361
+ 'collation ' => $ column ['collation ' ],
362
+ 'comment ' => $ column ['comment ' ],
363
+ 'virtualAs ' => ! is_null ($ column ['generation ' ]) && $ column ['generation ' ]['type ' ] === 'virtual '
364
+ ? $ column ['generation ' ]['expression ' ] : null ,
365
+ 'storedAs ' => ! is_null ($ column ['generation ' ]) && $ column ['generation ' ]['type ' ] === 'stored '
366
+ ? $ column ['generation ' ]['expression ' ] : null ,
367
+ ]));
368
+
369
+ return sprintf ('alter table %s change %s %s %s ' ,
370
+ $ this ->wrapTable ($ blueprint ),
371
+ $ this ->wrap ($ command ->from ),
372
+ $ this ->wrap ($ command ->to ),
373
+ $ modifiers
374
+ );
375
+ }
376
+
364
377
/**
365
378
* Compile a change column command into a series of SQL statements.
366
379
*
0 commit comments