wavelength_server/drizzle/0000_warm_edwin_jarvis.sql

21 lines
457 B
MySQL
Raw Normal View History

2024-10-22 16:38:45 -05:00
CREATE OR REPLACE FUNCTION notify_new_message()
RETURNS trigger LANGUAGE plpgsql AS $$
BEGIN
PERFORM pg_notify(
'new_message',
json_build_object(
'id', NEW.id,
'text', NEW.text,
'senderId', NEW.senderId,
'receiverId', NEW.receiverId,
'createdAt', NEW.createdAt
)::text
);
RETURN NEW;
END;
$$;
CREATE TRIGGER message_insert_trigger
AFTER INSERT ON messages
FOR EACH ROW EXECUTE FUNCTION notify_new_message();