chore: rename locked to dormant (#9290)

* chore: rename locked to dormant

- The following columns have been updated:
  - workspace.locked_at -> dormant_at
  - template.inactivity_ttl -> time_til_dormant
  - template.locked_ttl -> time_til_dormant_autodelete

This change has also been reflected in the SDK.

A route has also been updated from /workspaces/<id>/lock to /workspaces/<id>/dormant
This commit is contained in:
Jon Ayers
2023-08-24 13:25:54 -05:00
committed by GitHub
parent ebd878b6b5
commit 7f14b50dbe
67 changed files with 1174 additions and 1206 deletions
+24 -24
View File
@@ -259,13 +259,13 @@ WHERE
) > 0
ELSE true
END
-- Filter by locked workspaces. By default we do not return locked
-- Filter by dormant workspaces. By default we do not return dormant
-- workspaces since they are considered soft-deleted.
AND CASE
WHEN @locked_at :: timestamptz > '0001-01-01 00:00:00+00'::timestamptz THEN
locked_at IS NOT NULL AND locked_at >= @locked_at
WHEN @dormant_at :: timestamptz > '0001-01-01 00:00:00+00'::timestamptz THEN
dormant_at IS NOT NULL AND dormant_at >= @dormant_at
ELSE
locked_at IS NULL
dormant_at IS NULL
END
-- Filter by last_used
AND CASE
@@ -479,31 +479,31 @@ WHERE
) OR
-- If the workspace's template has an inactivity_ttl set
-- it may be eligible for locking.
-- it may be eligible for dormancy.
(
templates.inactivity_ttl > 0 AND
workspaces.locked_at IS NULL
templates.time_til_dormant > 0 AND
workspaces.dormant_at IS NULL
) OR
-- If the workspace's template has a locked_ttl set
-- and the workspace is already locked
-- If the workspace's template has a time_til_dormant_autodelete set
-- and the workspace is already dormant.
(
templates.locked_ttl > 0 AND
workspaces.locked_at IS NOT NULL
templates.time_til_dormant_autodelete > 0 AND
workspaces.dormant_at IS NOT NULL
)
) AND workspaces.deleted = 'false';
-- name: UpdateWorkspaceLockedDeletingAt :one
-- name: UpdateWorkspaceDormantDeletingAt :one
UPDATE
workspaces
SET
locked_at = $2,
-- When a workspace is unlocked we want to update the last_used_at to avoid the workspace getting re-locked.
-- if we're locking the workspace then we leave it alone.
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 locked_at is null (meaning unlocked) or the template-defined locked_ttl is 0 we should set
-- deleting_at to NULL else set it to the locked_at + locked_ttl duration.
deleting_at = CASE WHEN $2::timestamptz IS NULL OR templates.locked_ttl = 0 THEN NULL ELSE $2::timestamptz + INTERVAL '1 milliseconds' * templates.locked_ttl / 1000000 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
FROM
templates
WHERE
@@ -512,19 +512,19 @@ AND
workspaces.id = $1
RETURNING workspaces.*;
-- name: UpdateWorkspacesLockedDeletingAtByTemplateID :exec
-- name: UpdateWorkspacesDormantDeletingAtByTemplateID :exec
UPDATE workspaces
SET
deleting_at = CASE
WHEN @locked_ttl_ms::bigint = 0 THEN NULL
WHEN @locked_at::timestamptz > '0001-01-01 00:00:00+00'::timestamptz THEN (@locked_at::timestamptz) + interval '1 milliseconds' * @locked_ttl_ms::bigint
ELSE locked_at + interval '1 milliseconds' * @locked_ttl_ms::bigint
WHEN @time_til_dormant_autodelete_ms::bigint = 0 THEN NULL
WHEN @dormant_at::timestamptz > '0001-01-01 00:00:00+00'::timestamptz THEN (@dormant_at::timestamptz) + interval '1 milliseconds' * @time_til_dormant_autodelete_ms::bigint
ELSE dormant_at + interval '1 milliseconds' * @time_til_dormant_autodelete_ms::bigint
END,
locked_at = CASE WHEN @locked_at::timestamptz > '0001-01-01 00:00:00+00'::timestamptz THEN @locked_at::timestamptz ELSE locked_at END
dormant_at = CASE WHEN @dormant_at::timestamptz > '0001-01-01 00:00:00+00'::timestamptz THEN @dormant_at::timestamptz ELSE dormant_at END
WHERE
template_id = @template_id
AND
locked_at IS NOT NULL;
dormant_at IS NOT NULL;
-- name: UpdateTemplateWorkspacesLastUsedAt :exec
UPDATE workspaces