Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaaf8e86

Browse files
committed
add agent and workspace insert notifs
1 parentdb4f308 commitaaf8e86

File tree

5 files changed

+136
-5
lines changed

5 files changed

+136
-5
lines changed

‎coderd/database/dump.sql

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/migrations/000260_agent_id_name_pair.down.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎coderd/database/migrations/000260_agent_id_name_pair.up.sql

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DROPTYPE agent_id_name_pair;
2+
3+
DROPTRIGGER IF EXISTS new_workspace_notifyON workspaces;
4+
DROPFUNCTION IF EXISTS new_workspace_notify;
5+
6+
DROPTRIGGER IF EXISTS new_agent_notifyON workspace_agents;
7+
DROPFUNCTION new_agent_notify;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
CREATETYPEagent_id_name_pairAS (
2+
id uuid,
3+
nametext
4+
);
5+
6+
CREATEFUNCTIONnew_workspace_notify() RETURNS trigger
7+
LANGUAGE plpgsql
8+
AS $$
9+
DECLARE
10+
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);
14+
RETURN NEW;
15+
END;
16+
$$;
17+
18+
CREATETRIGGERnew_workspace_notify
19+
AFTER INSERTON workspaces
20+
FOR EACH ROW
21+
EXECUTE FUNCTION new_workspace_notify();
22+
23+
24+
CREATEFUNCTIONnew_agent_notify() RETURNS trigger
25+
LANGUAGE plpgsql
26+
AS $$
27+
DECLARE
28+
workspace_owner_id uuid;
29+
BEGIN
30+
SELECTworkspaces.owner_id
31+
INTO workspace_owner_id
32+
FROM
33+
workspaces
34+
WHERE
35+
workspaces.id= (
36+
SELECT
37+
workspace_id
38+
FROM
39+
workspace_builds
40+
WHERE
41+
workspace_builds.job_id= (
42+
SELECT
43+
job_id
44+
FROM
45+
workspace_resources
46+
WHERE
47+
workspace_resources.id= (
48+
SELECT
49+
resource_id
50+
FROM
51+
workspace_agents
52+
WHERE
53+
workspace_agents.id=NEW.id
54+
)
55+
)
56+
);
57+
-- Agents might not belong to a workspace (template imports)
58+
IF workspace_owner_idIS NOT NULL THEN
59+
-- Write to the notification channel `new_agent:workspace_owner_id`
60+
PERFORM pg_notify('new_agent:'|| workspace_owner_id,'');
61+
END IF;
62+
RETURN NEW;
63+
END;
64+
$$;
65+
66+
67+
CREATETRIGGERnew_agent_notify
68+
AFTER INSERTON workspace_agents
69+
FOR EACH ROW
70+
EXECUTE FUNCTION new_agent_notify();
71+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp