mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add SQL queries for v2 PG Coordinator (#10572)
re #10528 Adds SQL queries to support Tailnet v2 API in the PG Coordinator
This commit is contained in:
@@ -121,3 +121,81 @@ RETURNING *;
|
||||
DELETE
|
||||
FROM tailnet_coordinators
|
||||
WHERE heartbeat_at < now() - INTERVAL '24 HOURS';
|
||||
|
||||
-- name: UpsertTailnetPeer :one
|
||||
INSERT INTO
|
||||
tailnet_peers (
|
||||
id,
|
||||
coordinator_id,
|
||||
node,
|
||||
status,
|
||||
updated_at
|
||||
)
|
||||
VALUES
|
||||
($1, $2, $3, $4, now() at time zone 'utc')
|
||||
ON CONFLICT (id, coordinator_id)
|
||||
DO UPDATE SET
|
||||
id = $1,
|
||||
coordinator_id = $2,
|
||||
node = $3,
|
||||
status = $4,
|
||||
updated_at = now() at time zone 'utc'
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteTailnetPeer :one
|
||||
DELETE
|
||||
FROM tailnet_peers
|
||||
WHERE id = $1 and coordinator_id = $2
|
||||
RETURNING id, coordinator_id;
|
||||
|
||||
-- name: GetTailnetPeers :many
|
||||
SELECT * FROM tailnet_peers WHERE id = $1;
|
||||
|
||||
-- name: UpsertTailnetTunnel :one
|
||||
INSERT INTO
|
||||
tailnet_tunnels (
|
||||
coordinator_id,
|
||||
src_id,
|
||||
dst_id,
|
||||
updated_at
|
||||
)
|
||||
VALUES
|
||||
($1, $2, $3, now() at time zone 'utc')
|
||||
ON CONFLICT (coordinator_id, src_id, dst_id)
|
||||
DO UPDATE SET
|
||||
coordinator_id = $1,
|
||||
src_id = $2,
|
||||
dst_id = $3,
|
||||
updated_at = now() at time zone 'utc'
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteTailnetTunnel :one
|
||||
DELETE
|
||||
FROM tailnet_tunnels
|
||||
WHERE coordinator_id = $1 and src_id = $2 and dst_id = $3
|
||||
RETURNING coordinator_id, src_id, dst_id;
|
||||
|
||||
-- name: DeleteAllTailnetTunnels :exec
|
||||
DELETE
|
||||
FROM tailnet_tunnels
|
||||
WHERE coordinator_id = $1 and src_id = $2;
|
||||
|
||||
-- name: GetTailnetTunnelPeerIDs :many
|
||||
SELECT dst_id as peer_id, coordinator_id, updated_at
|
||||
FROM tailnet_tunnels
|
||||
WHERE tailnet_tunnels.src_id = $1
|
||||
UNION
|
||||
SELECT src_id as peer_id, coordinator_id, updated_at
|
||||
FROM tailnet_tunnels
|
||||
WHERE tailnet_tunnels.dst_id = $1;
|
||||
|
||||
-- name: GetTailnetTunnelPeerBindings :many
|
||||
SELECT tailnet_tunnels.dst_id as peer_id, tailnet_peers.coordinator_id, tailnet_peers.updated_at, tailnet_peers.node
|
||||
FROM tailnet_tunnels
|
||||
INNER JOIN tailnet_peers ON tailnet_tunnels.dst_id = tailnet_peers.id
|
||||
WHERE tailnet_tunnels.src_id = $1
|
||||
UNION
|
||||
SELECT tailnet_tunnels.src_id as peer_id, tailnet_peers.coordinator_id, tailnet_peers.updated_at, tailnet_peers.node
|
||||
FROM tailnet_tunnels
|
||||
INNER JOIN tailnet_peers ON tailnet_tunnels.src_id = tailnet_peers.id
|
||||
WHERE tailnet_tunnels.dst_id = $1;
|
||||
|
||||
Reference in New Issue
Block a user