-- Script to clean up duplicate foreign key constraints
-- This is the final cleanup step

-- Drop duplicate foreign key constraints in bookings table
DO $$ 
BEGIN
    -- Drop duplicate foreign key constraints in bookings table
    IF EXISTS (SELECT constraint_name FROM information_schema.table_constraints WHERE table_name = 'bookings' AND constraint_name = 'bookings_user_uuid_fk_fkey') THEN
        ALTER TABLE bookings DROP CONSTRAINT bookings_user_uuid_fk_fkey;
    END IF;
    IF EXISTS (SELECT constraint_name FROM information_schema.table_constraints WHERE table_name = 'bookings' AND constraint_name = 'bookings_beach_place_uuid_fk_fkey') THEN
        ALTER TABLE bookings DROP CONSTRAINT bookings_beach_place_uuid_fk_fkey;
    END IF;
END $$;

-- Drop duplicate foreign key constraints in reviews table
DO $$ 
BEGIN
    -- Drop duplicate foreign key constraints in reviews table
    IF EXISTS (SELECT constraint_name FROM information_schema.table_constraints WHERE table_name = 'reviews' AND constraint_name = 'reviews_user_uuid_fk_fkey') THEN
        ALTER TABLE reviews DROP CONSTRAINT reviews_user_uuid_fk_fkey;
    END IF;
    IF EXISTS (SELECT constraint_name FROM information_schema.table_constraints WHERE table_name = 'reviews' AND constraint_name = 'reviews_beach_place_uuid_fk_fkey') THEN
        ALTER TABLE reviews DROP CONSTRAINT reviews_beach_place_uuid_fk_fkey;
    END IF;
    IF EXISTS (SELECT constraint_name FROM information_schema.table_constraints WHERE table_name = 'reviews' AND constraint_name = 'reviews_booking_uuid_fk_fkey') THEN
        ALTER TABLE reviews DROP CONSTRAINT reviews_booking_uuid_fk_fkey;
    END IF;
END $$;