-- Add deal_id to reviews (deal-scoped reviews refactor)
ALTER TABLE reviews ADD COLUMN deal_id uuid REFERENCES deals(id);
UPDATE reviews SET deal_id = p.deal_id FROM purchases p WHERE reviews.purchase_id = p.id;
CREATE INDEX reviews_deal_visible_idx ON reviews(deal_id, is_visible);
ALTER TABLE reviews ALTER COLUMN deal_id SET NOT NULL;
