Skip to content

Commit 336815b

Browse files
committed
chore: create trigger for workspace delete action
1 parent 0b5517f commit 336815b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

migrations/20250305082545_workspace_delete_trigger.sql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
-- Create the trigger function
1+
CREATE TABLE IF NOT EXISTS af_workspace_deleted (
2+
id serial PRIMARY KEY,
3+
workspace_id uuid NOT NULL,
4+
owner_id BIGINT NOT NULL,
5+
deleted_at timestamp with time zone DEFAULT now()
6+
);
7+
28
CREATE OR REPLACE FUNCTION workspace_deleted_trigger_function()
39
RETURNS trigger AS
410
$$
@@ -9,13 +15,13 @@ BEGIN
915
'workspace_id', OLD.workspace_id,
1016
'owner_id', OLD.owner_uid
1117
);
12-
18+
INSERT INTO af_workspace_deleted (workspace_id, owner_id, deleted_at)
19+
VALUES (OLD.workspace_id, OLD.owner_uid, now());
1320
PERFORM pg_notify('af_workspace_deleted', payload::text);
1421
RETURN OLD;
1522
END;
1623
$$ LANGUAGE plpgsql;
1724

18-
-- Create the trigger that calls the function after deleting a workspace
1925
CREATE TRIGGER on_workspace_delete
2026
AFTER DELETE ON public.af_workspace
2127
FOR EACH ROW

0 commit comments

Comments
 (0)