{"-- Resolve recursion in chat_thread_participants SELECT policy

-- Remove recursive policy
DROP POLICY IF EXISTS \"Participants can view participants in their threads\" ON public.chat_thread_participants","-- New non-recursive policy: org members can view participants for threads in their org
CREATE POLICY \"Org members can view participants for org threads\"
ON public.chat_thread_participants
FOR SELECT
USING (
  EXISTS (
    SELECT 1
    FROM public.chat_threads t
    JOIN public.user_roles ur ON ur.organization_id = t.organization_id
    WHERE t.id = chat_thread_participants.thread_id
      AND ur.user_id = auth.uid()
  )
)"}