ALTER TABLE mail_rules
    ADD COLUMN IF NOT EXISTS rule_kind TEXT NOT NULL DEFAULT 'rule';

ALTER TABLE mail_rules
    ADD COLUMN IF NOT EXISTS workflow JSONB;

CREATE INDEX IF NOT EXISTS idx_mail_rules_kind
    ON mail_rules(user_id, rule_kind);

COMMENT ON COLUMN mail_rules.rule_kind IS 'rule = triggered automation, function = reusable subroutine';
COMMENT ON COLUMN mail_rules.workflow IS 'Graphical workflow definition (triggers, nodes, edges, variables)';
