-- Remove redundant restaurant_uuid column from restaurants table
-- The restaurant_id (UUID) is already the primary key, making restaurant_uuid redundant

-- Step 1: Drop the unique constraint on restaurant_uuid
DO $$ 
BEGIN
    IF EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'restaurants_restaurant_uuid_key') THEN
        ALTER TABLE restaurants DROP CONSTRAINT restaurants_restaurant_uuid_key;
        RAISE NOTICE 'Dropped constraint: restaurants_restaurant_uuid_key';
    ELSE
        RAISE NOTICE 'Constraint restaurants_restaurant_uuid_key does not exist';
    END IF;
END $$;

-- Step 2: Drop the restaurant_uuid column
DO $$ 
BEGIN
    IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_name = 'restaurants' AND column_name = 'restaurant_uuid') THEN
        ALTER TABLE restaurants DROP COLUMN restaurant_uuid;
        RAISE NOTICE 'Dropped column: restaurant_uuid from restaurants table';
    ELSE
        RAISE NOTICE 'Column restaurant_uuid does not exist in restaurants table';
    END IF;
END $$;

-- Step 3: Verify the final table structure
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns 
WHERE table_name = 'restaurants' 
ORDER BY ordinal_position;