feat(db): add source column to relationships table (#44)
Promote BOM source from metadata JSONB to a dedicated VARCHAR(20)
column with CHECK constraint ('manual' or 'assembly').
- Add migration 012_bom_source.sql (column, data migration, cleanup)
- Add Source field to Relationship and BOMEntry structs
- Update all SQL queries (GetBOM, GetWhereUsed, GetExpandedBOM, Create)
- Update API response/request types with source field
- Update CSV/ODS export to read e.Source instead of metadata
- Update CSV import to set source on relationship directly
- Update frontend types and BOMTab to use top-level source field
This commit is contained in:
16
migrations/012_bom_source.sql
Normal file
16
migrations/012_bom_source.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
-- Add source column to relationships table to distinguish assembly-derived
|
||||
-- BOM entries from manually-added ones.
|
||||
ALTER TABLE relationships
|
||||
ADD COLUMN source VARCHAR(20) NOT NULL DEFAULT 'manual'
|
||||
CHECK (source IN ('manual', 'assembly'));
|
||||
|
||||
-- Migrate existing metadata.source values where they exist.
|
||||
-- The metadata field stores source as a free-form string; promote to column.
|
||||
UPDATE relationships
|
||||
SET source = 'manual'
|
||||
WHERE metadata->>'source' IS NOT NULL;
|
||||
|
||||
-- Remove the source key from metadata since it's now a dedicated column.
|
||||
UPDATE relationships
|
||||
SET metadata = metadata - 'source'
|
||||
WHERE metadata ? 'source';
|
||||
Reference in New Issue
Block a user