CREATE TABLE public.email_dispatch_rules
(
    id integer NOT NULL DEFAULT nextval('email_dispatch_rules_id_seq'::regclass),
    event_type character varying(50) NOT NULL,
    template_key character varying(50) NOT NULL,
    email_field character varying(50) NOT NULL,
    name_field character varying(50) NOT NULL,
    language character varying(5) NOT NULL DEFAULT 'es'::character varying,
    active boolean NOT NULL DEFAULT true,
    mandatory boolean NOT NULL DEFAULT false,
    CONSTRAINT fk_dispatch_template FOREIGN KEY (template_key, language) REFERENCES email_templates(template_key, language),
    CONSTRAINT email_dispatch_rules_pkey PRIMARY KEY (id),
    CONSTRAINT uq_dispatch_rule UNIQUE (event_type, template_key, language)
);
