-- Script to populate UUID foreign key columns with data
-- This is the third part of step 5

-- Populate foreign keys in restaurant_items table
UPDATE restaurant_items ri SET restaurant_uuid_fk = (SELECT restaurant_id FROM restaurants WHERE restaurant_id::text = ri.restaurant_id::text);

-- Populate foreign keys in markets table
UPDATE markets m SET company_uuid_fk = (SELECT company_id FROM companies WHERE company_id::text = m.company_id::text);
UPDATE markets m SET beach_place_uuid_fk = (SELECT beach_place_id FROM beach_places WHERE beach_place_id::text = m.beach_place_id::text);

-- Populate foreign keys in restaurants table
UPDATE restaurants r SET company_uuid_fk = (SELECT company_id FROM companies WHERE company_id::text = r.company_id::text);
UPDATE restaurants r SET beach_place_uuid_fk = (SELECT beach_place_id FROM beach_places WHERE beach_place_id::text = r.beach_place_id::text);

-- Populate foreign keys in adventures table
UPDATE adventures a SET company_uuid_fk = (SELECT company_id FROM companies WHERE company_id::text = a.company_id::text);
UPDATE adventures a SET beach_place_uuid_fk = (SELECT beach_place_id FROM beach_places WHERE beach_place_id::text = a.beach_place_id::text);