Skip to content

Commit 0b5517f

Browse files
committed
chore: add delete user notification
1 parent 58c6e60 commit 0b5517f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Create the trigger function
2+
CREATE OR REPLACE FUNCTION workspace_deleted_trigger_function()
3+
RETURNS trigger AS
4+
$$
5+
DECLARE
6+
payload jsonb;
7+
BEGIN
8+
payload := jsonb_build_object(
9+
'workspace_id', OLD.workspace_id,
10+
'owner_id', OLD.owner_uid
11+
);
12+
13+
PERFORM pg_notify('af_workspace_deleted', payload::text);
14+
RETURN OLD;
15+
END;
16+
$$ LANGUAGE plpgsql;
17+
18+
-- Create the trigger that calls the function after deleting a workspace
19+
CREATE TRIGGER on_workspace_delete
20+
AFTER DELETE ON public.af_workspace
21+
FOR EACH ROW
22+
EXECUTE FUNCTION workspace_deleted_trigger_function();

0 commit comments

Comments
 (0)