Files
silo/migrations/013_move_cost_sourcing_to_props.sql
forbes-0023 b3c748ef10 refactor: move sourcing_link and standard_cost from item columns to revision properties
- Add migration 013 to copy sourcing_link/standard_cost values into
  current revision properties JSONB and drop the columns from items table
- Remove SourcingLink/StandardCost from Go Item struct and all DB queries
  (items.go, audit_queries.go, projects.go)
- Remove from API request/response structs and handlers
- Update CSV/ODS/BOM export/import to read these from revision properties
- Update audit handlers to score as regular property fields
- Remove from frontend Item type and hardcoded form fields
- MainTab now reads sourcing_link/standard_cost from item.properties
- CreateItemPane/EditItemPane no longer have dedicated fields for these;
  they will be rendered as schema-driven property fields
2026-02-11 09:50:31 -06:00

26 lines
1.1 KiB
SQL

-- Migration 013: Move sourcing_link and standard_cost to revision properties
--
-- These fields are being deduplicated from the items table into revision
-- properties (JSONB). The YAML property_schemas.defaults already defines
-- them, so they belong in the properties system rather than as standalone
-- columns.
-- Step 1: Copy sourcing_link and standard_cost from items into the current
-- revision's properties JSONB for every item that has non-null values.
UPDATE revisions r
SET properties = r.properties
|| CASE WHEN i.sourcing_link IS NOT NULL
THEN jsonb_build_object('sourcing_link', i.sourcing_link)
ELSE '{}'::jsonb END
|| CASE WHEN i.standard_cost IS NOT NULL
THEN jsonb_build_object('standard_cost', i.standard_cost)
ELSE '{}'::jsonb END
FROM items i
WHERE r.item_id = i.id
AND r.revision_number = i.current_revision
AND (i.sourcing_link IS NOT NULL OR i.standard_cost IS NOT NULL);
-- Step 2: Drop the columns from the items table.
ALTER TABLE items DROP COLUMN sourcing_link;
ALTER TABLE items DROP COLUMN standard_cost;