{"-- Drop the existing INSERT policy for cameras
DROP POLICY IF EXISTS \"Admins and managers can insert cameras\" ON public.cameras","-- Create a better INSERT policy
CREATE POLICY \"Admins and managers can insert cameras in their organization\"
ON public.cameras
FOR INSERT
WITH CHECK (
  EXISTS (
    SELECT 1
    FROM public.branches b
    JOIN public.user_roles ur ON ur.organization_id = b.organization_id
    WHERE b.id = branch_id
      AND ur.user_id = auth.uid()
      AND ur.role IN ('admin', 'manager')
  )
)","-- Also add super admin policy for INSERT
CREATE POLICY \"Super admin can insert cameras\"
ON public.cameras
FOR INSERT
WITH CHECK (is_current_user_super_admin())"}