-- Bridge the earliest QuoteJudge schema and the current typed schema without
-- dropping data or weakening historical NOT NULL constraints.
ALTER TABLE quote_comparisons
    ADD COLUMN IF NOT EXISTS recommendation_vendor TEXT,
    ADD COLUMN IF NOT EXISTS weighted_score NUMERIC(10,4);

UPDATE quote_comparisons
SET recommendation_vendor = COALESCE(recommendation_vendor, recommended_vendor),
    weighted_score = COALESCE(weighted_score, score)
WHERE recommendation_vendor IS NULL OR weighted_score IS NULL;

ALTER TABLE quote_execution_receipts
    ADD COLUMN IF NOT EXISTS tool_name TEXT,
    ADD COLUMN IF NOT EXISTS ok BOOLEAN;

UPDATE quote_execution_receipts
SET tool_name = COALESCE(tool_name, skill_name),
    ok = COALESCE(ok, status = 'ok')
WHERE tool_name IS NULL OR ok IS NULL;
