-- Script to add UUID columns to remaining tables
-- This is the first part of step 5

-- Add UUID column to restaurants table
DO $$ 
BEGIN
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'restaurants' AND column_name = 'restaurant_uuid') THEN
        ALTER TABLE restaurants ADD COLUMN restaurant_uuid UUID DEFAULT uuid_generate_v4();
    END IF;
    IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'restaurants_restaurant_uuid_key') THEN
        ALTER TABLE restaurants ADD CONSTRAINT restaurants_restaurant_uuid_key UNIQUE (restaurant_uuid);
    END IF;
END $$;

-- Add UUID column to beach_places table
DO $$ 
BEGIN
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'beach_places' AND column_name = 'beach_place_uuid') THEN
        ALTER TABLE beach_places ADD COLUMN beach_place_uuid UUID DEFAULT uuid_generate_v4();
    END IF;
    IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'beach_places_beach_place_uuid_key') THEN
        ALTER TABLE beach_places ADD CONSTRAINT beach_places_beach_place_uuid_key UNIQUE (beach_place_uuid);
    END IF;
END $$;