mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd/database): add UpsertProvisionerDaemons query (#11178)
Co-authored-by: Marcin Tojek <marcin@coder.com>
This commit is contained in:
co-authored by
Marcin Tojek
parent
ef4d1b68e1
commit
4f7ae6461b
@@ -4,19 +4,6 @@ SELECT
|
||||
FROM
|
||||
provisioner_daemons;
|
||||
|
||||
-- name: InsertProvisionerDaemon :one
|
||||
INSERT INTO
|
||||
provisioner_daemons (
|
||||
id,
|
||||
created_at,
|
||||
"name",
|
||||
provisioners,
|
||||
tags,
|
||||
last_seen_at
|
||||
)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6) RETURNING *;
|
||||
|
||||
-- name: DeleteOldProvisionerDaemons :exec
|
||||
-- Delete provisioner daemons that have been created at least a week ago
|
||||
-- and have not connected to coderd since a week.
|
||||
@@ -26,3 +13,32 @@ DELETE FROM provisioner_daemons WHERE (
|
||||
(created_at < (NOW() - INTERVAL '7 days') AND last_seen_at IS NULL) OR
|
||||
(last_seen_at IS NOT NULL AND last_seen_at < (NOW() - INTERVAL '7 days'))
|
||||
);
|
||||
|
||||
-- name: UpsertProvisionerDaemon :one
|
||||
INSERT INTO
|
||||
provisioner_daemons (
|
||||
id,
|
||||
created_at,
|
||||
"name",
|
||||
provisioners,
|
||||
tags,
|
||||
last_seen_at,
|
||||
"version"
|
||||
)
|
||||
VALUES (
|
||||
gen_random_uuid(),
|
||||
@created_at,
|
||||
@name,
|
||||
@provisioners,
|
||||
@tags,
|
||||
@last_seen_at,
|
||||
@version
|
||||
) ON CONFLICT("name", lower((tags ->> 'owner'::text))) DO UPDATE SET
|
||||
provisioners = @provisioners,
|
||||
tags = @tags,
|
||||
last_seen_at = @last_seen_at,
|
||||
"version" = @version
|
||||
WHERE
|
||||
-- Only ones with the same tags are allowed clobber
|
||||
provisioner_daemons.tags <@ @tags :: jsonb
|
||||
RETURNING *;
|
||||
|
||||
Reference in New Issue
Block a user