-- Fix security warning: Set search_path for rate limit alert function
-- Drop trigger first, then function, then recreate with proper search_path

DROP TRIGGER IF EXISTS update_rate_limit_alert_config_updated_at ON public.rate_limit_alert_config;
DROP FUNCTION IF EXISTS update_rate_limit_alert_config_updated_at();

CREATE OR REPLACE FUNCTION update_rate_limit_alert_config_updated_at()
RETURNS TRIGGER
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = public
AS $$
BEGIN
  NEW.updated_at = now();
  RETURN NEW;
END;
$$;

CREATE TRIGGER update_rate_limit_alert_config_updated_at
BEFORE UPDATE ON public.rate_limit_alert_config
FOR EACH ROW
EXECUTE FUNCTION update_rate_limit_alert_config_updated_at();