Skip to content

Commit fabe2d1

Browse files
committed
add pubsub to dbmem
1 parent 28942f0 commit fabe2d1

File tree

5 files changed

+2
-138
lines changed

5 files changed

+2
-138
lines changed

cli/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,8 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
691691
var pubsubWatchdogTimeout <-chan struct{}
692692
if vals.InMemoryDatabase {
693693
// This is only used for testing.
694-
options.Database = dbmem.New()
695694
options.Pubsub = pubsub.NewInMemory()
695+
options.Database = dbmem.New()
696696
} else {
697697
sqlDB, dbURL, err := getPostgresDB(ctx, logger, vals.PostgresURL.String(), codersdk.PostgresAuth(vals.PostgresAuth), sqlDriver)
698698
if err != nil {

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7776,7 +7776,7 @@ func (q *FakeQuerier) InsertWorkspace(_ context.Context, arg database.InsertWork
77767776
return workspace, nil
77777777
}
77787778

7779-
func (q *FakeQuerier) InsertWorkspaceAgent(_ context.Context, arg database.InsertWorkspaceAgentParams) (database.WorkspaceAgent, error) {
7779+
func (q *FakeQuerier) InsertWorkspaceAgent(ctx context.Context, arg database.InsertWorkspaceAgentParams) (database.WorkspaceAgent, error) {
77807780
if err := validateDatabaseType(arg); err != nil {
77817781
return database.WorkspaceAgent{}, err
77827782
}

coderd/database/dump.sql

Lines changed: 0 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
11
DROP TYPE agent_id_name_pair;
2-
3-
DROP TRIGGER IF EXISTS new_workspace_notify ON workspaces;
4-
DROP FUNCTION IF EXISTS new_workspace_notify;
5-
6-
DROP TRIGGER IF EXISTS new_agent_notify ON workspace_agents;
7-
DROP FUNCTION IF EXISTS new_agent_notify;

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

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

0 commit comments

Comments
 (0)