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
17 lines
629 B
SQL
17 lines
629 B
SQL
-- 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';
|