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

Commitcac29e0

Browse files
authored
feat: add tables for PGCoordinator v2 (#10442)
Adds tables for a simplified PG Coordinator that only considers Peers and Tunnels, rather than agent/client distinctions we have today.
1 parent95ce697 commitcac29e0

File tree

7 files changed

+248
-0
lines changed

7 files changed

+248
-0
lines changed

‎coderd/database/dump.sql

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

‎coderd/database/foreign_key_constraint.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
BEGIN;
2+
3+
DROPTRIGGER IF EXISTS tailnet_notify_tunnel_changeON tailnet_tunnels;
4+
DROPFUNCTION IF EXISTS tailnet_notify_tunnel_change;
5+
DROPTABLE IF EXISTS tailnet_tunnels;
6+
7+
DROPTRIGGER IF EXISTS tailnet_notify_peer_changeON tailnet_peers;
8+
DROPFUNCTION IF EXISTS tailnet_notify_peer_change;
9+
DROPINDEX IF EXISTS idx_tailnet_peers_coordinator;
10+
DROPTABLE IF EXISTS tailnet_peers;
11+
12+
DROPTYPE IF EXISTS tailnet_status;
13+
14+
COMMIT;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
BEGIN;
2+
3+
CREATETYPEtailnet_statusAS ENUM (
4+
'ok',
5+
'lost'
6+
);
7+
8+
CREATETABLEtailnet_peers (
9+
id uuidNOT NULL,
10+
coordinator_id uuidNOT NULL,
11+
updated_attimestamp with time zoneNOT NULL,
12+
nodebyteaNOT NULL,
13+
status tailnet_status DEFAULT'ok'::tailnet_statusNOT NULL,
14+
PRIMARY KEY (id, coordinator_id),
15+
FOREIGN KEY (coordinator_id)REFERENCES tailnet_coordinators(id)ON DELETE CASCADE
16+
);
17+
18+
-- For shutting down / GC a coordinator
19+
CREATEINDEXidx_tailnet_peers_coordinatorON tailnet_peers (coordinator_id);
20+
21+
-- Any time tailnet_peers table changes, send an update with the affected peer ID.
22+
CREATEFUNCTIONtailnet_notify_peer_change() RETURNS trigger
23+
LANGUAGE plpgsql
24+
AS $$
25+
BEGIN
26+
IF (OLDIS NOT NULL) THEN
27+
PERFORM pg_notify('tailnet_peer_update',OLD.id::text);
28+
RETURNNULL;
29+
END IF;
30+
IF (NEWIS NOT NULL) THEN
31+
PERFORM pg_notify('tailnet_peer_update',NEW.id::text);
32+
RETURNNULL;
33+
END IF;
34+
END;
35+
$$;
36+
37+
CREATETRIGGERtailnet_notify_peer_change
38+
AFTER INSERTORUPDATEORDELETEON tailnet_peers
39+
FOR EACH ROW
40+
EXECUTE PROCEDURE tailnet_notify_peer_change();
41+
42+
CREATETABLEtailnet_tunnels (
43+
coordinator_id uuidNOT NULL,
44+
-- we don't keep foreign keys for src_id and dst_id because the coordinator doesn't
45+
-- strictly order creating the peers and creating the tunnels
46+
src_id uuidNOT NULL,
47+
dst_id uuidNOT NULL,
48+
updated_attimestamp with time zoneNOT NULL,
49+
PRIMARY KEY (coordinator_id, src_id, dst_id),
50+
FOREIGN KEY (coordinator_id)REFERENCES tailnet_coordinators (id)ON DELETE CASCADE
51+
);
52+
53+
CREATEFUNCTIONtailnet_notify_tunnel_change() RETURNS trigger
54+
LANGUAGE plpgsql
55+
AS $$
56+
BEGIN
57+
IF (NEWIS NOT NULL) THEN
58+
PERFORM pg_notify('tailnet_tunnel_update',NEW.src_id||','||NEW.dst_id);
59+
RETURNNULL;
60+
ELSIF (OLDIS NOT NULL) THEN
61+
PERFORM pg_notify('tailnet_tunnel_update',OLD.src_id||','||OLD.dst_id);
62+
RETURNNULL;
63+
END IF;
64+
END;
65+
$$;
66+
67+
CREATETRIGGERtailnet_notify_tunnel_change
68+
AFTER INSERTORUPDATEORDELETEON tailnet_tunnels
69+
FOR EACH ROW
70+
EXECUTE PROCEDURE tailnet_notify_tunnel_change();
71+
72+
COMMIT;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
INSERT INTO tailnet_peers
2+
(id, coordinator_id, updated_at, node, status)
3+
VALUES (
4+
'c0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
5+
'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
6+
'2023-06-15 10:23:54+00',
7+
'a fake protobuf byte string',
8+
'ok'
9+
);
10+
11+
INSERT INTO tailnet_tunnels
12+
(coordinator_id, src_id, dst_id, updated_at)
13+
VALUES (
14+
'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
15+
'c0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
16+
'b0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
17+
'2023-06-15 10:23:54+00'
18+
);

‎coderd/database/models.go

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

‎coderd/database/unique_constraint.go

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp