Skip to content

Commit 2e2c092

Browse files
committed
Spaces to tabs
1 parent 6e6fbc3 commit 2e2c092

File tree

3 files changed

+76
-57
lines changed

3 files changed

+76
-57
lines changed

coderd/database/dbfake/dbfake.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5196,7 +5196,7 @@ func (q *FakeQuerier) InsertWorkspaceResourceMetadata(_ context.Context, arg dat
51965196
return metadata, nil
51975197
}
51985198

5199-
func (q *FakeQuerier) PruneUnusedTemplateVersions(ctx context.Context, arg database.PruneUnusedTemplateVersionsParams) ([]uuid.UUID, error) {
5199+
func (q *FakeQuerier) PruneUnusedTemplateVersions(_ context.Context, arg database.PruneUnusedTemplateVersionsParams) ([]uuid.UUID, error) {
52005200
err := validateDatabaseType(arg)
52015201
if err != nil {
52025202
return nil, err

coderd/database/queries.sql.go

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

coderd/database/queries/templateversions.sql

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ FROM
77
WHERE
88
template_id = @template_id :: uuid
99
AND CASE
10-
-- If no filter is provided, default to returning ALL template versions.
11-
-- The called should always provide a filter if they want to omit
12-
-- deleted versions.
10+
-- If no filter is provided, default to returning ALL template versions.
11+
-- The called should always provide a filter if they want to omit
12+
-- deleted versions.
1313
WHEN @deleted :: boolean IS NULL THEN true
1414
ELSE template_versions.deleted = @deleted :: boolean
1515
END
@@ -33,8 +33,8 @@ WHERE
3333
ELSE true
3434
END
3535
ORDER BY
36-
-- Deterministic and consistent ordering of all rows, even if they share
37-
-- a timestamp. This is to ensure consistent pagination.
36+
-- Deterministic and consistent ordering of all rows, even if they share
37+
-- a timestamp. This is to ensure consistent pagination.
3838
(created_at, id) ASC OFFSET @offset_opt
3939
LIMIT
4040
-- A null limit means "no limit", so 0 means return all
@@ -149,45 +149,45 @@ UPDATE
149149
template_versions
150150
SET
151151
deleted = true,
152-
updated_at = @updated_at
152+
updated_at = sqlc.arg('updated_at')
153153
FROM
154-
-- Delete all versions that are returned from this query.
155-
(
156-
SELECT
157-
id
158-
FROM
154+
-- Delete all versions that are returned from this query.
155+
(
156+
SELECT
157+
scoped_template_versions.id
158+
FROM
159159
-- Scope a prune to a single template and ignore already deleted template versions
160-
(SELECT * FROM template_versions WHERE template_id = @template_id AND deleted = false) AS template_versions
161-
LEFT JOIN
162-
provisioner_jobs ON template_versions.job_id = provisioner_jobs.id
163-
LEFT JOIN
164-
templates ON template_versions.template_id = templates.id
165-
WHERE
160+
(SELECT * FROM template_versions WHERE template_versions.template_id = sqlc.arg('template_id') :: uuid AND deleted = false) AS scoped_template_versions
161+
LEFT JOIN
162+
provisioner_jobs ON scoped_template_versions.job_id = provisioner_jobs.id
163+
LEFT JOIN
164+
templates ON scoped_template_versions.template_id = templates.id
165+
WHERE
166166
-- Actively used template versions (meaning the latest build is using
167167
-- the version) are never pruned. A "restart" command on the workspace,
168168
-- even if failed, would use the version. So it cannot be pruned until
169169
-- the build is outdated.
170170
-- TODO: This is an issue for "deleted workspaces", since a deleted workspace
171171
-- has a build with the transition "delete". This will prevent that template
172172
-- version from ever being pruned. We need a method to prune deleted workspaces.
173-
template_versions.id != ANY(
173+
scoped_template_versions.id != ANY(
174174
SELECT DISTINCT ON(workspace_id)
175-
template_version_id
175+
scoped_template_versions
176176
FROM
177177
workspace_builds
178178
ORDER BY build_number DESC
179179
)
180180
-- Also never delete the active template version
181-
AND active_version_id != template_versions.id
182-
AND CASE
183-
-- Optionally, only prune versions that match a given
184-
-- job status like 'failed'.
185-
WHEN @job_status != '' THEN
186-
provisioner_jobs.job_status = @job_status
187-
ELSE
188-
true
189-
END
190-
181+
AND active_version_id != scoped_template_versions.id
182+
AND CASE
183+
-- Optionally, only prune versions that match a given
184+
-- job status like 'failed'.
185+
WHEN sqlc.narg('job_status') :: provisioner_job_status IS NOT NULL THEN
186+
provisioner_jobs.job_status = sqlc.narg('job_status') :: provisioner_job_status
187+
ELSE
188+
true
189+
END
191190
) AS deleted_versions
192191
WHERE
193-
id = ANY(deleted_versions);
192+
template_versions.id = ANY(deleted_versions)
193+
RETURNING template_versions.id;

0 commit comments

Comments
 (0)