-- Add Blind Tasting support to Sessions ALTER TABLE public.tasting_sessions ADD COLUMN IF NOT EXISTS is_blind BOOLEAN DEFAULT false, ADD COLUMN IF NOT EXISTS is_revealed BOOLEAN DEFAULT false; -- Add Guessing fields to Tastings ALTER TABLE public.tastings ADD COLUMN IF NOT EXISTS blind_label TEXT, ADD COLUMN IF NOT EXISTS guess_abv DECIMAL, ADD COLUMN IF NOT EXISTS guess_age INTEGER, ADD COLUMN IF NOT EXISTS guess_region TEXT, ADD COLUMN IF NOT EXISTS guess_points INTEGER; -- Update RLS Policies for blind sessions -- Guests should only see bottle details if NOT blind OR revealed -- This is a complex policy update, we'll refine the existing tastings_select_policy DROP POLICY IF EXISTS "tastings_select_policy" ON public.tastings; CREATE POLICY "tastings_select_policy" ON public.tastings FOR SELECT USING ( -- You can see your own tastings auth.uid() = user_id OR -- You can see tastings in a session you participate in EXISTS ( SELECT 1 FROM public.session_participants sp JOIN public.buddies b ON b.id = sp.buddy_id WHERE sp.session_id = public.tastings.session_id AND b.buddy_profile_id = auth.uid() ) ); -- Note: The logic for hiding bottle details will be handled in the UI/API layer -- as the RLS here still needs to allow access to the tasting record itself. -- Hiding 'bottle_id' content for blind tastings will be done in the frontend -- based on session.is_blind and session.is_revealed.