fix: UpdateWorkspaceDormantDeletingAt interval out of range (#11000)

This commit is contained in:
Colin Adler
2023-12-02 11:47:08 -06:00
committed by GitHub
parent 49ed66c7ad
commit 6b3c4c00a2
2 changed files with 40 additions and 20 deletions
+20 -10
View File
@@ -476,20 +476,30 @@ WHERE
-- name: UpdateWorkspaceDormantDeletingAt :one
UPDATE
workspaces
workspaces
SET
dormant_at = $2,
-- When a workspace is active we want to update the last_used_at to avoid the workspace going
dormant_at = $2,
-- When a workspace is active we want to update the last_used_at to avoid the workspace going
-- immediately dormant. If we're transition the workspace to dormant then we leave it alone.
last_used_at = CASE WHEN $2::timestamptz IS NULL THEN now() at time zone 'utc' ELSE last_used_at END,
-- If dormant_at is null (meaning active) or the template-defined time_til_dormant_autodelete is 0 we should set
-- deleting_at to NULL else set it to the dormant_at + time_til_dormant_autodelete duration.
deleting_at = CASE WHEN $2::timestamptz IS NULL OR templates.time_til_dormant_autodelete = 0 THEN NULL ELSE $2::timestamptz + INTERVAL '1 milliseconds' * templates.time_til_dormant_autodelete / 1000000 END
last_used_at = CASE WHEN $2::timestamptz IS NULL THEN
now() at time zone 'utc'
ELSE
last_used_at
END,
-- If dormant_at is null (meaning active) or the template-defined time_til_dormant_autodelete is 0 we should set
-- deleting_at to NULL else set it to the dormant_at + time_til_dormant_autodelete duration.
deleting_at = CASE WHEN $2::timestamptz IS NULL OR templates.time_til_dormant_autodelete = 0 THEN
NULL
ELSE
$2::timestamptz + (INTERVAL '1 millisecond' * (templates.time_til_dormant_autodelete / 1000000))
END
FROM
templates
templates
WHERE
workspaces.id = $1
RETURNING workspaces.*;
workspaces.id = $1
AND templates.id = workspaces.template_id
RETURNING
workspaces.*;
-- name: UpdateWorkspacesDormantDeletingAtByTemplateID :exec
UPDATE workspaces