-- Script to add missing UUID foreign key columns
-- This is the first part of the final cleanup

-- Add UUID foreign key column to market_items table
DO $$ 
BEGIN
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'market_items' AND column_name = 'market_uuid_fk') THEN
        ALTER TABLE market_items ADD COLUMN market_uuid_fk UUID;
    END IF;
END $$;

-- Add UUID foreign key columns to bookings table
DO $$ 
BEGIN
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'bookings' AND column_name = 'user_uuid_fk') THEN
        ALTER TABLE bookings ADD COLUMN user_uuid_fk UUID;
    END IF;
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'bookings' AND column_name = 'beach_place_uuid_fk') THEN
        ALTER TABLE bookings ADD COLUMN beach_place_uuid_fk UUID;
    END IF;
END $$;

-- Add UUID foreign key columns to reviews table
DO $$ 
BEGIN
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'reviews' AND column_name = 'user_uuid_fk') THEN
        ALTER TABLE reviews ADD COLUMN user_uuid_fk UUID;
    END IF;
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'reviews' AND column_name = 'beach_place_uuid_fk') THEN
        ALTER TABLE reviews ADD COLUMN beach_place_uuid_fk UUID;
    END IF;
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'reviews' AND column_name = 'booking_uuid_fk') THEN
        ALTER TABLE reviews ADD COLUMN booking_uuid_fk UUID;
    END IF;
END $$;