{"-- First, let's see what policies exist and drop them properly
DROP POLICY IF EXISTS \"Org admins can view all subscribers\" ON public.subscribers","DROP POLICY IF EXISTS \"Org admins can update subscribers\" ON public.subscribers","-- Update is_super_admin function to handle case sensitivity
CREATE OR REPLACE FUNCTION public.is_super_admin(user_email text)
RETURNS boolean
LANGUAGE sql
SECURITY DEFINER
AS $$
  SELECT LOWER(user_email) IN ('ashraffarid@gmail.com', 'demo@beyondsenses.ai')
$$","-- Add the missing policies
CREATE POLICY \"Org admins can view all subscribers\"
ON public.subscribers
FOR SELECT
USING (
  is_current_user_super_admin() OR
  EXISTS (
    SELECT 1 FROM user_roles ur
    WHERE ur.user_id = auth.uid()
    AND ur.role IN ('admin', 'manager')
  )
)","CREATE POLICY \"Org admins can update subscribers\"
ON public.subscribers
FOR UPDATE
USING (
  is_current_user_super_admin() OR
  EXISTS (
    SELECT 1 FROM user_roles ur
    WHERE ur.user_id = auth.uid()
    AND ur.role IN ('admin', 'manager')
  )
)
WITH CHECK (
  is_current_user_super_admin() OR
  EXISTS (
    SELECT 1 FROM user_roles ur
    WHERE ur.user_id = auth.uid()
    AND ur.role IN ('admin', 'manager')
  )
)"}