Skip to content

Commit 75db3b2

Browse files
authored
Merge pull request #230 from fleetbase/hotfix/orchestrator-priority-nullable-migration
hotfix: replace ->change() with raw ALTER TABLE in nullable migration
2 parents 8988629 + fc78b33 commit 75db3b2

5 files changed

Lines changed: 1738 additions & 13 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fleetbase/fleetops-api",
3-
"version": "0.6.41",
3+
"version": "0.6.42",
44
"description": "Fleet & Transport Management Extension for Fleetbase",
55
"keywords": [
66
"fleetbase-extension",

extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Fleet-Ops",
3-
"version": "0.6.41",
3+
"version": "0.6.42",
44
"description": "Fleet & Transport Management Extension for Fleetbase",
55
"repository": "https://github.com/fleetbase/fleetops",
66
"license": "AGPL-3.0-or-later",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fleetbase/fleetops-engine",
3-
"version": "0.6.41",
3+
"version": "0.6.42",
44
"description": "Fleet & Transport Management Extension for Fleetbase",
55
"fleetbase": {
66
"route": "fleet-ops"
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22

33
use Illuminate\Database\Migrations\Migration;
4-
use Illuminate\Database\Schema\Blueprint;
5-
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Support\Facades\DB;
65

76
/**
87
* Make `orchestrator_priority` nullable on the orders table.
@@ -20,24 +19,32 @@
2019
* application layer (Order model + controllers) already coerces null to 50,
2120
* so NULL values will not appear in practice; the nullable flag is a
2221
* 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.
2330
*/
2431
return new class extends Migration {
2532
public function up(): void
2633
{
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+
);
3037
}
3138

3239
public function down(): void
3340
{
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')
3643
->whereNull('orchestrator_priority')
3744
->update(['orchestrator_priority' => 50]);
3845

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+
);
4249
}
4350
};

0 commit comments

Comments
 (0)