feat(revisions): auto-create revision on item metadata changes #177

Merged
forbes merged 1 commits from feat/auto-revision-on-update into main 2026-03-04 20:08:43 +00:00

1 Commits

Author SHA1 Message Date
Forbes
563eae4892 feat(revisions): auto-create revision on item metadata changes
When updating an item via PUT /api/items/{partNumber}, any change to
metadata fields (part_number, item_type, description, sourcing_type,
long_description) now creates a new revision for audit trail.

Previously, revisions were only created when the 'properties' JSONB
field was explicitly included in the request body. Metadata-only changes
were invisible in revision history.

New behavior:
- Detect which metadata fields actually changed vs current values
- If metadata changed without properties, carry forward properties from
  the latest revision and auto-generate a comment (e.g. 'updated description')
- If properties changed, use the provided properties (existing behavior)
- If both changed, create a single revision capturing both
- If nothing actually changed (identical values), skip revision creation
- Publish revision.created SSE event and trigger auto-jobs

Also adds GetLatestRevision() to ItemRepository for efficiently fetching
the current revision's properties without loading all revisions.

Closes #173
2026-03-04 13:59:24 -06:00