mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
* postgres tailnet coordinator Signed-off-by: Spike Curtis <spike@coder.com> * Fix db migration; tests Signed-off-by: Spike Curtis <spike@coder.com> * Add fixture, regenerate Signed-off-by: Spike Curtis <spike@coder.com> * Fix fixtures Signed-off-by: Spike Curtis <spike@coder.com> * review comments, run clean gen Signed-off-by: Spike Curtis <spike@coder.com> * Rename waitForConn -> cleanupConn Signed-off-by: Spike Curtis <spike@coder.com> * code review updates Signed-off-by: Spike Curtis <spike@coder.com> * db migration order Signed-off-by: Spike Curtis <spike@coder.com> * fix log field name last_heartbeat Signed-off-by: Spike Curtis <spike@coder.com> * fix heartbeat_from log field Signed-off-by: Spike Curtis <spike@coder.com> * fix slog fields for linting Signed-off-by: Spike Curtis <spike@coder.com> --------- Signed-off-by: Spike Curtis <spike@coder.com>
80 lines
1.3 KiB
SQL
80 lines
1.3 KiB
SQL
-- name: UpsertTailnetClient :one
|
|
INSERT INTO
|
|
tailnet_clients (
|
|
id,
|
|
coordinator_id,
|
|
agent_id,
|
|
node,
|
|
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,
|
|
agent_id = $3,
|
|
node = $4,
|
|
updated_at = now() at time zone 'utc'
|
|
RETURNING *;
|
|
|
|
-- name: UpsertTailnetAgent :one
|
|
INSERT INTO
|
|
tailnet_agents (
|
|
id,
|
|
coordinator_id,
|
|
node,
|
|
updated_at
|
|
)
|
|
VALUES
|
|
($1, $2, $3, now() at time zone 'utc')
|
|
ON CONFLICT (id, coordinator_id)
|
|
DO UPDATE SET
|
|
id = $1,
|
|
coordinator_id = $2,
|
|
node = $3,
|
|
updated_at = now() at time zone 'utc'
|
|
RETURNING *;
|
|
|
|
|
|
-- name: DeleteTailnetClient :one
|
|
DELETE
|
|
FROM tailnet_clients
|
|
WHERE id = $1 and coordinator_id = $2
|
|
RETURNING id, coordinator_id;
|
|
|
|
-- name: DeleteTailnetAgent :one
|
|
DELETE
|
|
FROM tailnet_agents
|
|
WHERE id = $1 and coordinator_id = $2
|
|
RETURNING id, coordinator_id;
|
|
|
|
-- name: DeleteCoordinator :exec
|
|
DELETE
|
|
FROM tailnet_coordinators
|
|
WHERE id = $1;
|
|
|
|
-- name: GetTailnetAgents :many
|
|
SELECT *
|
|
FROM tailnet_agents
|
|
WHERE id = $1;
|
|
|
|
-- name: GetTailnetClientsForAgent :many
|
|
SELECT *
|
|
FROM tailnet_clients
|
|
WHERE agent_id = $1;
|
|
|
|
-- name: UpsertTailnetCoordinator :one
|
|
INSERT INTO
|
|
tailnet_coordinators (
|
|
id,
|
|
heartbeat_at
|
|
)
|
|
VALUES
|
|
($1, now() at time zone 'utc')
|
|
ON CONFLICT (id)
|
|
DO UPDATE SET
|
|
id = $1,
|
|
heartbeat_at = now() at time zone 'utc'
|
|
RETURNING *;
|