Skip to content

Commit

Permalink
chore: create trigger for workspace delete action
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed Mar 5, 2025
1 parent 0b5517f commit 336815b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions migrations/20250305082545_workspace_delete_trigger.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
-- Create the trigger function
CREATE TABLE IF NOT EXISTS af_workspace_deleted (
id serial PRIMARY KEY,
workspace_id uuid NOT NULL,
owner_id BIGINT NOT NULL,
deleted_at timestamp with time zone DEFAULT now()
);

CREATE OR REPLACE FUNCTION workspace_deleted_trigger_function()
RETURNS trigger AS
$$
Expand All @@ -9,13 +15,13 @@ BEGIN
'workspace_id', OLD.workspace_id,
'owner_id', OLD.owner_uid
);

INSERT INTO af_workspace_deleted (workspace_id, owner_id, deleted_at)
VALUES (OLD.workspace_id, OLD.owner_uid, now());
PERFORM pg_notify('af_workspace_deleted', payload::text);
RETURN OLD;
END;
$$ LANGUAGE plpgsql;

-- Create the trigger that calls the function after deleting a workspace
CREATE TRIGGER on_workspace_delete
AFTER DELETE ON public.af_workspace
FOR EACH ROW
Expand Down

0 comments on commit 336815b

Please sign in to comment.