-- Add new type to contact enum

DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM pg_type t
        INNER JOIN pg_namespace p ON t.typnamespace=p.oid
        INNER JOIN pg_enum e ON e.enumtypid = t.oid
        WHERE t.typname='contact_protocol' AND p.nspname='auth' AND e.enumlabel = 'email'
    ) THEN
        ALTER TYPE auth.contact_protocol ADD VALUE 'email'; 
    END IF;
END
$$;