-- Migration 031: customer_name on iace_projects + reuse-helper index -- ========================================================================== -- The IACE module is operated by a single Maschinenhersteller (the SDK -- user), but their plants land at many different end customers. A safety -- expert who commissions the second or third plant at the same customer -- often finds that whole classes of mitigations are already in place -- there (company-wide PPE rules, locked-out energy isolation, customer- -- standard signage, etc.). Today, this expert knowledge is rediscovered -- per project. -- -- This migration introduces a plain customer_name field on the project -- (no separate customer table yet — Option A from the design discussion; -- normalised iace_customers can come later when a real customer-management -- screen is built). The field is optional so existing projects without a -- customer remain valid. -- -- The partial index makes the customer-standards lookup cheap: only -- projects with a non-empty customer_name participate, since reuse is -- meaningless without it. -- ========================================================================== ALTER TABLE iace_projects ADD COLUMN IF NOT EXISTS customer_name TEXT; CREATE INDEX IF NOT EXISTS idx_iace_projects_customer_name ON iace_projects(customer_name) WHERE customer_name IS NOT NULL AND customer_name <> '';