mirror of
https://github.com/coder/coder.git
synced 2026-06-03 04:58:23 +00:00
fix: UpdateWorkspaceDormantDeletingAt interval out of range (#11000)
This commit is contained in:
@@ -11300,20 +11300,30 @@ func (q *sqlQuerier) UpdateWorkspaceDeletedByID(ctx context.Context, arg UpdateW
|
||||
|
||||
const updateWorkspaceDormantDeletingAt = `-- 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.id, workspaces.created_at, workspaces.updated_at, workspaces.owner_id, workspaces.organization_id, workspaces.template_id, workspaces.deleted, workspaces.name, workspaces.autostart_schedule, workspaces.ttl, workspaces.last_used_at, workspaces.dormant_at, workspaces.deleting_at, workspaces.automatic_updates
|
||||
workspaces.id = $1
|
||||
AND templates.id = workspaces.template_id
|
||||
RETURNING
|
||||
workspaces.id, workspaces.created_at, workspaces.updated_at, workspaces.owner_id, workspaces.organization_id, workspaces.template_id, workspaces.deleted, workspaces.name, workspaces.autostart_schedule, workspaces.ttl, workspaces.last_used_at, workspaces.dormant_at, workspaces.deleting_at, workspaces.automatic_updates
|
||||
`
|
||||
|
||||
type UpdateWorkspaceDormantDeletingAtParams struct {
|
||||
|
||||
Reference in New Issue
Block a user