-- Migration 024: expose mandatory flag in fn_admin_list_email_rules
-- The mandatory column already exists (migration 023). PG 9.6 requires DROP + CREATE
-- when the return type changes; function is owned by elfi1953_stc-eu.
-- Applied 2026-07-10 directly via psql (DROP FUNCTION + CREATE FUNCTION in transaction).

CREATE OR REPLACE FUNCTION public.fn_admin_list_email_rules()
 RETURNS TABLE(id integer, event_type character varying, template_key character varying, email_field character varying, name_field character varying, language character varying, active boolean, mandatory boolean)
 LANGUAGE sql
AS $function$
    SELECT id, event_type, template_key, email_field, name_field, language, active, mandatory
    FROM public.email_dispatch_rules
    ORDER BY event_type, language;
$function$;

GRANT EXECUTE ON FUNCTION public.fn_admin_list_email_rules() TO "elfi1953_stc-eu";
