|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | use Illuminate\Database\Migrations\Migration; |
4 | | -use Illuminate\Database\Schema\Blueprint; |
5 | | -use Illuminate\Support\Facades\Schema; |
| 4 | +use Illuminate\Support\Facades\DB; |
6 | 5 |
|
7 | 6 | /** |
8 | 7 | * Make `orchestrator_priority` nullable on the orders table. |
|
20 | 19 | * application layer (Order model + controllers) already coerces null to 50, |
21 | 20 | * so NULL values will not appear in practice; the nullable flag is a |
22 | 21 | * belt-and-suspenders safety net for any code path that may have been missed. |
| 22 | + * |
| 23 | + * NOTE: We use raw DB::statement() instead of Blueprint::change() because |
| 24 | + * ->change() relies on Doctrine DBAL to introspect the existing column type, |
| 25 | + * and Doctrine does not recognise MySQL's TINYINT as a mapped type |
| 26 | + * ("Unknown column type tinyinteger requested"), causing the migration to |
| 27 | + * crash on deployment. The raw ALTER TABLE statement is portable across all |
| 28 | + * MySQL/MariaDB versions supported by Fleetbase and requires no extra |
| 29 | + * dependencies. |
23 | 30 | */ |
24 | 31 | return new class extends Migration { |
25 | 32 | public function up(): void |
26 | 33 | { |
27 | | - Schema::table('orders', function (Blueprint $table) { |
28 | | - $table->unsignedTinyInteger('orchestrator_priority')->default(50)->nullable()->change(); |
29 | | - }); |
| 34 | + DB::statement( |
| 35 | + 'ALTER TABLE `orders` MODIFY COLUMN `orchestrator_priority` TINYINT UNSIGNED NULL DEFAULT 50' |
| 36 | + ); |
30 | 37 | } |
31 | 38 |
|
32 | 39 | public function down(): void |
33 | 40 | { |
34 | | - // First back-fill any NULLs so the NOT NULL constraint can be restored. |
35 | | - \Illuminate\Support\Facades\DB::table('orders') |
| 41 | + // Back-fill any NULLs before restoring the NOT NULL constraint. |
| 42 | + DB::table('orders') |
36 | 43 | ->whereNull('orchestrator_priority') |
37 | 44 | ->update(['orchestrator_priority' => 50]); |
38 | 45 |
|
39 | | - Schema::table('orders', function (Blueprint $table) { |
40 | | - $table->unsignedTinyInteger('orchestrator_priority')->default(50)->nullable(false)->change(); |
41 | | - }); |
| 46 | + DB::statement( |
| 47 | + 'ALTER TABLE `orders` MODIFY COLUMN `orchestrator_priority` TINYINT UNSIGNED NOT NULL DEFAULT 50' |
| 48 | + ); |
42 | 49 | } |
43 | 50 | }; |
0 commit comments