Add metadata support for incidents, schedules and components#385
Open
jbrooksuk wants to merge 3 commits into
Open
Add metadata support for incidents, schedules and components#385jbrooksuk wants to merge 3 commits into
jbrooksuk wants to merge 3 commits into
Conversation
Introduce a shared, filterable metadata capability, backed by the existing polymorphic `meta` table, for incidents, schedules, components, component groups and subscribers. - Add a `Meta` model and a `HasMeta` concern (with a `Metable` contract) exposing a `meta()` morph relation, `metaValues()` and `syncMeta()`. Values are cast to JSON so they retain their original type when read back. - Register the metadata-aware models in the morph map and migrate the existing `components.meta` JSON column into the polymorphic `meta` table, then drop the column. The `meta.value` column is widened to nullable text. - Persist metadata from the Filament resources via a `KeyValue` field and a shared page concern. - Accept `meta` on the create/update request data and sync it in the actions. - Expose `meta` as an optional API include (`?include=meta`) that renders the metadata as a key/value object, rather than always loading it. - Add a reusable `MetaFilter` so the API endpoints can filter by metadata (e.g. `?filter[meta][region]=eu-west`). - Document the metadata filter and include on the relevant API endpoints. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SjXufhWofngDAxRAgsxzyN
Address the highest-severity review findings on the metadata feature: - `MetaFilter` now matches typed metadata values: query-string input is compared against every plausible JSON encoding (string, integer, float and boolean), so `?filter[meta][priority]=3` matches an integer 3 as well as the string "3". Boolean values already converted by the query builder are handled too. - `HasMeta` purges a model's metadata when it is hard or force deleted (soft-deleted models keep their metadata for restores), and the demo seeder truncates the `meta` table, so orphaned rows can no longer attach to unrelated records that reuse an id. - `syncMeta()` casts keys to strings before pruning, avoiding MySQL's numeric coercion matching every key against integer array keys. - The component meta migration logs a warning instead of silently skipping payloads that do not decode to an array, batch-inserts each component's rows, hardcodes the morph aliases so the frozen migration no longer depends on the runtime morph map, and `down()` now restores the original `meta.value` string column definition after removing the rows this feature wrote. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SjXufhWofngDAxRAgsxzyN
PHPStan analyses the HasMeta trait once per consuming model, so the method_exists() probe for isForceDeleting() was reported as always-true on soft-deleting models. Checking $model->exists expresses the same rule directly: soft-deleted models still exist and keep their metadata, while hard and force deleted models are gone and have their metadata purged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SjXufhWofngDAxRAgsxzyN
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.
Introduce a shared, filterable metadata capability, backed by the existing
polymorphic
metatable, for incidents, schedules, components, componentgroups and subscribers.
Metamodel and aHasMetaconcern (with aMetablecontract)exposing a
meta()morph relation,metaValues()andsyncMeta(). Valuesare cast to JSON so they retain their original type when read back.
components.metaJSON column into the polymorphicmetatable, then dropthe column. The
meta.valuecolumn is widened to nullable text.KeyValuefield and ashared page concern.
metaon the create/update request data and sync it in the actions.metaas an optional API include (?include=meta) that renders themetadata as a key/value object, rather than always loading it.
MetaFilterso the API endpoints can filter by metadata(e.g.
?filter[meta][region]=eu-west).Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01SjXufhWofngDAxRAgsxzyN