-- Slice 8Z-i · Procurement Batch 3 · RFQ shortlist seeding.
--
-- When a Client PO is on Path A (Product Discovery) AND the retirement is APPROVED, the RFQ
-- workspace pre-invites suppliers marked SHORTLIST in the discovery findings. To keep the seed
-- idempotent (so re-opening the RFQ doesn't duplicate invites), we tag each seeded goods_rfq_quotes
-- row with the source lpo_retirement_findings.c0d.
--
-- Also adds one perm: the "Send to RFQ" gate uses the existing GoodsRfq/fromClientPo action,
-- which is already permissioned — nothing new needed there.

SET @sch := DATABASE();
SET @tbl := 'goods_rfq_quotes';

SET @c := (SELECT COUNT(*) FROM information_schema.columns
           WHERE table_schema=@sch AND table_name=@tbl AND column_name='discovery_finding_id');
SET @sql := IF(@c=0,
    'ALTER TABLE goods_rfq_quotes ADD COLUMN discovery_finding_id INT UNSIGNED NULL AFTER awarded_lpo_id, ADD INDEX idx_disc_find (discovery_finding_id)',
    'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
