Skip to content

Commit 6b3c4c0

Browse files
authored
fix: UpdateWorkspaceDormantDeletingAt interval out of range (#11000)
1 parent 49ed66c commit 6b3c4c0

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

coderd/database/queries.sql.go

Lines changed: 20 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,20 +476,30 @@ WHERE
476476

477477
-- name: UpdateWorkspaceDormantDeletingAt :one
478478
UPDATE
479-
workspaces
479+
workspaces
480480
SET
481-
dormant_at = $2,
482-
-- When a workspace is active we want to update the last_used_at to avoid the workspace going
481+
dormant_at = $2,
482+
-- When a workspace is active we want to update the last_used_at to avoid the workspace going
483483
-- immediately dormant. If we're transition the workspace to dormant then we leave it alone.
484-
last_used_at = CASE WHEN $2::timestamptz IS NULL THEN now() at time zone 'utc' ELSE last_used_at END,
485-
-- If dormant_at is null (meaning active) or the template-defined time_til_dormant_autodelete is 0 we should set
486-
-- deleting_at to NULL else set it to the dormant_at + time_til_dormant_autodelete duration.
487-
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
484+
last_used_at = CASE WHEN $2::timestamptz IS NULL THEN
485+
now() at time zone 'utc'
486+
ELSE
487+
last_used_at
488+
END,
489+
-- If dormant_at is null (meaning active) or the template-defined time_til_dormant_autodelete is 0 we should set
490+
-- deleting_at to NULL else set it to the dormant_at + time_til_dormant_autodelete duration.
491+
deleting_at = CASE WHEN $2::timestamptz IS NULL OR templates.time_til_dormant_autodelete = 0 THEN
492+
NULL
493+
ELSE
494+
$2::timestamptz + (INTERVAL '1 millisecond' * (templates.time_til_dormant_autodelete / 1000000))
495+
END
488496
FROM
489-
templates
497+
templates
490498
WHERE
491-
workspaces.id = $1
492-
RETURNING workspaces.*;
499+
workspaces.id = $1
500+
AND templates.id = workspaces.template_id
501+
RETURNING
502+
workspaces.*;
493503

494504
-- name: UpdateWorkspacesDormantDeletingAtByTemplateID :exec
495505
UPDATE workspaces

0 commit comments

Comments
 (0)