Skip to content

Commit 22ece36

Browse files
committed
send events on ownership transfer
1 parent 959f6c1 commit 22ece36

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

coderd/database/dump.sql

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000260_workspace_updates.down.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ DROP TRIGGER IF EXISTS new_workspace_notify ON workspaces;
44
DROP FUNCTION IF EXISTS new_workspace_notify;
55

66
DROP TRIGGER IF EXISTS new_agent_notify ON workspace_agents;
7-
DROP FUNCTION new_agent_notify;
7+
DROP FUNCTION IF EXISTS new_agent_notify;

coderd/database/migrations/000260_workspace_updates.up.sql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ CREATE FUNCTION new_workspace_notify() RETURNS trigger
88
AS $$
99
DECLARE
1010
BEGIN
11-
-- Write to the notification channel `new_workspace:owner_id`
12-
-- with the workspace id as the payload.
13-
PERFORM pg_notify('new_workspace:' || NEW.owner_id, NEW.id::text);
11+
-- Notify for new workspaces & ownership transfers
12+
IF TG_OP = 'INSERT' OR (TG_OP = 'UPDATE' AND NEW.owner_id <> OLD.owner_id) THEN
13+
-- Write to the notification channel `new_workspace:owner_id`
14+
-- with the workspace id as the payload.
15+
PERFORM pg_notify('new_workspace:' || NEW.owner_id, NEW.id::text);
16+
END IF;
1417
RETURN NEW;
1518
END;
1619
$$;
1720

1821
CREATE TRIGGER new_workspace_notify
19-
AFTER INSERT ON workspaces
22+
AFTER INSERT OR UPDATE ON workspaces
2023
FOR EACH ROW
2124
EXECUTE FUNCTION new_workspace_notify();
2225

@@ -68,4 +71,3 @@ CREATE TRIGGER new_agent_notify
6871
AFTER INSERT ON workspace_agents
6972
FOR EACH ROW
7073
EXECUTE FUNCTION new_agent_notify();
71-

0 commit comments

Comments
 (0)