-- Migration 023: add mandatory column to email_dispatch_rules
-- Mandatory events cannot be disabled per course.

ALTER TABLE public.email_dispatch_rules
  ADD COLUMN IF NOT EXISTS mandatory boolean NOT NULL DEFAULT false;

-- These 5 event types are always sent regardless of course configuration
UPDATE public.email_dispatch_rules
SET mandatory = true
WHERE event_type IN (
  'ENROLLMENT_ACTIVE',
  'ENROLLMENT_PENDING',
  'ENROLLMENT_REJECTED',
  'TUTOR_REGISTERED',
  'STUDENT_CONFLICT'
);
