CREATE OR REPLACE FUNCTION room_message_tsv_trigger() RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN NEW.content_tsv := to_tsvector('english', NEW.content); RETURN NEW; END; $function$; CREATE OR REPLACE TRIGGER room_message_tsv_update BEFORE INSERT OR UPDATE ON room_message FOR EACH ROW EXECUTE PROCEDURE room_message_tsv_trigger(); DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'notification_type' AND typtype = 'e') THEN CREATE TYPE notification_type AS ENUM ( 'mention', 'invitation', 'role_change', 'room_created', 'room_deleted', 'system_announcement' ); END IF; END $$;