-- Fix: Remove SECURITY DEFINER from notification_health_dashboard view

-- Drop and recreate view without SECURITY DEFINER
DROP VIEW IF EXISTS public.notification_health_dashboard;

CREATE VIEW public.notification_health_dashboard 
WITH (security_invoker = true) AS
SELECT
  date,
  total_attempts,
  duplicates_prevented,
  prevention_rate,
  CASE 
    WHEN prevention_rate > 10 THEN 'critical'
    WHEN prevention_rate > 5 THEN 'warning'
    ELSE 'healthy'
  END as health_status
FROM public.notification_duplicate_stats
ORDER BY date DESC
LIMIT 30;