Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
> v0.7.2 ~ "Foreign keys point at unique keys"
> v0.7.2 ~ "Foreign keys point at unique keys, and Passenger for everyone"

---
## Highlights

- **Fleet-Ops tables that foreign keys point at can be altered on MySQL 8.4 with `restrict_fk_on_non_standard_key` on.** MySQL 8.4 refuses any change to a table that a foreign key points at through a non-unique key, with `1553 Cannot drop index '<unknown key name>'`. v0.7.1 worked around this for one migration. This release removes the cause: `uuid` is now unique on `devices`, `inspection_forms`, `inspection_submissions`, `order_configs`, `telematics`, `warranties` and `work_orders`. Each column's old index is replaced, so it is not indexed twice. A column that already has a unique or primary key is left alone. A table with duplicate values is skipped and reported, and the migration can be run again once they are removed. Runs on the main and sandbox databases. Storefront's foreign keys to `order_configs` are covered too.
- **Every organization gets the Passenger order config.** It sits next to **Transport**, so the Passenger app works without running `fleetops:create-order-config passenger` first. New organizations get it when they're created. The migration `2026_11_18_000001_create_passenger_order_configs` adds it to every existing organization; one that already made it with the command keeps the config it has. Like Transport, it can't be deleted and its flow is read-only, while its policies and triggers can be edited.

---
## Upgrading
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Fleetbase\FleetOps\Support\FleetOps;
use Fleetbase\Models\Company;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Log;

/**
* Gives every existing organization the system Passenger order config, as new organizations
* get it when they are created. A company that already has it (from
* `fleetops:create-order-config passenger`) keeps the one it has.
*/
return new class extends Migration {
public function up(): void
{
Company::query()->select(['id', 'uuid', 'name'])->chunkById(200, function ($companies) {
foreach ($companies as $company) {
try {
FleetOps::createPassengerConfig($company);
} catch (Throwable $e) {
Log::warning('Could not create the passenger order config for company ' . $company->uuid . ': ' . $e->getMessage());
}
}
}, 'id');
}

public function down(): void
{
// The configs may already have orders, so they stay.
}
};
8 changes: 7 additions & 1 deletion server/src/Observers/CompanyObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ class CompanyObserver
*/
public function created(Company $company)
{
// Add the default transport order config
// Add the default order configs: transport and passenger
$this->createTransportConfig($company);
$this->createPassengerConfig($company);
}

protected function createTransportConfig(Company $company): void
{
FleetOps::createTransportConfig($company);
}

protected function createPassengerConfig(Company $company): void
{
FleetOps::createPassengerConfig($company);
}
}
10 changes: 10 additions & 0 deletions server/src/Support/FleetOps.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ public static function createTransportConfig(Company $company): OrderConfig
{
return OrderConfigTemplates::create('transport', $company);
}

/**
* Creates or retrieves the company's passenger configuration, from the `passenger` order
* config template. Like transport it is a system config: it can't be deleted and its flow
* is read-only.
*/
public static function createPassengerConfig(Company $company): OrderConfig
{
return OrderConfigTemplates::create('passenger', $company);
}
}
9 changes: 7 additions & 2 deletions server/tests/ObserverContractsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,12 @@ class FleetOpsCompanyObserverProbe extends CompanyObserver

protected function createTransportConfig(Company $company): void
{
$this->configs[] = $company->uuid;
$this->configs[] = 'transport:' . $company->uuid;
}

protected function createPassengerConfig(Company $company): void
{
$this->configs[] = 'passenger:' . $company->uuid;
}
}

Expand Down Expand Up @@ -977,7 +982,7 @@ protected function resolveOrder(PurchaseRate $purchaseRate): ?Order
(new PayloadObserver())->created($payload);

expect($categoryObserver->deleted)->toBe(['category-uuid'])
->and($companyObserver->configs)->toBe(['company-uuid'])
->and($companyObserver->configs)->toBe(['transport:company-uuid', 'passenger:company-uuid'])
->and($userObserver->deleted)->toBe(['user-uuid'])
->and($payload->updates)->toBe(1);
});
Expand Down
21 changes: 18 additions & 3 deletions server/tests/Unit/Observers/ObserverHelperExecutionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function connection(): SQLiteConnection
function fleetopsObserverHelperConnection(): SQLiteConnection
{
$connection = new SQLiteConnection(new PDO('sqlite::memory:'));
$connection->statement('create table custom_fields (uuid varchar(64) primary key, category_uuid varchar(64) null, company_uuid varchar(64) null, deleted_at datetime null, created_at datetime null, updated_at datetime null)');
$connection->statement('create table custom_fields (uuid varchar(64) primary key, category_uuid varchar(64) null, company_uuid varchar(64) null, subject_uuid varchar(64) null, subject_type varchar(255) null, public_id varchar(64) null, name varchar(255) null, label varchar(255) null, type varchar(64) null, component varchar(64) null, default_value text null, required tinyint null, editable tinyint null, validation_rules text null, help_text text null, description text null, options text null, meta text null, "order" integer null, deleted_at datetime null, created_at datetime null, updated_at datetime null)');
$connection->statement('create table users (uuid varchar(64) primary key, company_uuid varchar(64) null, public_id varchar(64) null, avatar_uuid varchar(64) null, name varchar(255) null, phone varchar(64) null, email varchar(255) null, type varchar(64) null, status varchar(64) null, last_login datetime null, deleted_at datetime null, created_at datetime null, updated_at datetime null)');
$connection->statement('create table drivers (uuid varchar(64) primary key, user_uuid varchar(64) null, company_uuid varchar(64) null, deleted_at datetime null, created_at datetime null, updated_at datetime null)');
$connection->statement('create table order_configs (id integer primary key autoincrement, uuid varchar(64) null, public_id varchar(64) null, company_uuid varchar(64) null, author_uuid varchar(64) null, category_uuid varchar(64) null, icon_uuid varchar(64) null, name varchar(255) null, namespace varchar(255) null, description text null, key varchar(255) null, status varchar(64) null, version varchar(64) null, core_service tinyint null, flow text null, entities text null, tags text null, meta text null, deleted_at datetime null, created_at datetime null, updated_at datetime null)');
$connection->statement('create table order_configs (id integer primary key autoincrement, uuid varchar(64) null, public_id varchar(64) null, company_uuid varchar(64) null, author_uuid varchar(64) null, category_uuid varchar(64) null, icon_uuid varchar(64) null, name varchar(255) null, namespace varchar(255) null, description text null, key varchar(255) null, status varchar(64) null, version varchar(64) null, core_service tinyint null, flow text null, entities text null, tags text null, meta text null, policies text null, triggers text null, deleted_at datetime null, created_at datetime null, updated_at datetime null)');

$resolver = new ConnectionResolver([
'default' => $connection,
Expand Down Expand Up @@ -88,7 +88,7 @@ function fleetopsCallObserverHelper(object $observer, string $method, mixed ...$
->and(Driver::withTrashed()->withoutGlobalScopes()->where('user_uuid', 'other-user')->whereNull('deleted_at')->count())->toBe(1);
});

test('company observer creates the default transport order config', function () {
test('company observer creates the default transport and passenger order configs', function () {
fleetopsObserverHelperConnection();

$company = new Company();
Expand All @@ -107,6 +107,21 @@ function fleetopsCallObserverHelper(object $observer, string $method, mixed ...$
->and($transport->core_service)->toBe(1)
->and($transport->tags)->toBe(['transport', 'delivery'])
->and($transport->flow)->toHaveKeys(['created', 'enroute', 'started', 'completed', 'dispatched']);

$passenger = OrderConfig::where([
'company_uuid' => 'company-uuid',
'key' => 'passenger',
'namespace' => 'system:order-config:passenger',
])->first();

expect($passenger)->toBeInstanceOf(OrderConfig::class)
->and($passenger->name)->toBe('Passenger')
->and($passenger->core_service)->toBe(1)
->and($passenger->flow)->toHaveKeys(['created', 'dispatched', 'started', 'arrived', 'in_progress', 'completed', 'no_show']);

(new CompanyObserver())->created($company);

expect(OrderConfig::where('company_uuid', 'company-uuid')->where('key', 'passenger')->count())->toBe(1);
});

test('zone observer invalidates service area cache only when a service area is present', function () {
Expand Down
Loading