DB: Add source column to relationships table #44
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add a dedicated
sourcecolumn to therelationshipstable to distinguish assembly-derived BOM entries from manually-added ones. This is required by the BOM merge feature — the merge endpoint needs to know which entries came from an assembly commit (and can be auto-updated) vs. which were added manually via the web UI or CSV import (and must never be auto-deleted).Current State
The
sourcefield is currently stored inside themetadataJSONB column on therelationshipstable. The BOM CSV import writes it asmetadata["source"], and the frontend BOMTab reads/displaysm.source. This is a free-form text field with no enforced values.Migration
All existing entries default to
manual. The BOM merge endpoint will setsource = 'assembly'for entries it creates.Code Changes
internal/db/relationships.goSource stringfield toRelationshipstructSource stringfield toBOMEntrystructCreate()to includesourcein INSERTGetBOM(),GetWhereUsed(),GetExpandedBOM()queries to SELECTsourceinternal/api/bom_handlers.goSource stringtoBOMEntryResponse(json:"source")Source stringtoAddBOMEntryRequest(json:"source,omitempty") — defaults tomanualif omittedsourcecolumn instead ofmetadata["source"]sourcecolumnFrontend (
web/src/components/items/BOMTab.tsx)sourceas a top-level field instead of from metadataMerge Rule
The BOM merge endpoint (separate issue) relies on this column:
source = 'assembly'entries can be auto-added, quantity-updated, or flagged as unreferenced by assembly mergessource = 'manual'entries are never touched by assembly merges