Give custom fields a public id - #254
Merged
Merged
Conversation
Every other resource in the platform is addressed by a prefixed public id; a custom field was addressed by its uuid, so any API handing one out exposed an internal identifier. FleetOps' inspection API is the case in point — a submission names the field each answer belongs to, and had nothing but a uuid to name it with. Existing rows are backfilled, and the column is nullable and indexed rather than unique-and-required so the migration is safe on a table that is already populated. A field created on the fly through setCustomField() is saved quietly, which skips the hook that mints the id, so that path mints its own.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/v1.6.62 #254 +/- ##
===================================================
Coverage 100.00% 100.00%
Complexity 6750 6750
===================================================
Files 398 398
Lines 22502 22505 +3
===================================================
+ Hits 22502 22505 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every other resource in the platform is addressed by a prefixed public id. A custom field was addressed by its uuid, so any API that hands one out exposes an internal identifier.
FleetOps' inspection API is the case in point: a submission names the field each answer belongs to, and until now had nothing but a uuid to name it with.
Fleetbase\Http\Resources\v1\InspectionForm::fieldToArray()carries the comment "A custom field has no public id, so the uuid is the id on both sides" — this removes that compromise.What changed
CustomFieldtakesHasPublicIdwith$publicIdType = 'custom_field', andpublic_idjoins$fillable.nullable()->index()rather than unique-and-required, following thegroupsprecedent, so it is safe on an already-populated table.HasCustomFields::setCustomField()creates a field withsaveQuietly(), which skips thecreatinghook that mints the id — so that path now mints its own. Without this, a field created on the fly would be the only one without a public id.Scope
CustomFieldis platform-wide, so this gives every custom field a public id — orders, vendors, drivers, not only inspections. Nothing reads the new column yet;withCustomFields()'s public projection emits field names and is unchanged.Checks
vendor/bin/pest— 1434 passed, 0 failed.php-cs-fixer --dry-run— clean.generates custom field public idsintests/Unit/Models/RecordModelsTest.php.Targeted at
release/v1.6.62, cut frommainfor this change. Left for review — not merging.