Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb539ddc

Browse files
committed
chore: adding clarity around soft-deletion constraints
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
1 parent9e8bf7e commitb539ddc

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

‎coderd/database/queries.sql.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/prebuilds.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ FROM templates t
4141
INNER JOIN template_version_presets tvpONtvp.template_version_id=tv.id
4242
INNER JOIN organizations oONo.id=t.organization_id
4343
WHEREtvp.desired_instancesIS NOT NULL-- Consider only presets that have a prebuild configuration.
44+
-- AND NOT t.deleted -- We don't exclude deleted templates because there's no constraint in the DB preventing a soft deletion on a template while workspaces are running.
4445
AND (t.id=sqlc.narg('template_id')::uuidORsqlc.narg('template_id') ISNULL);
4546

4647
-- name: GetRunningPrebuiltWorkspaces :many
@@ -71,6 +72,7 @@ FROM workspace_latest_builds wlb
7172
-- prebuilds that are still building.
7273
INNER JOIN templates tONt.active_version_id=wlb.template_version_id
7374
WHEREwlb.job_statusIN ('pending'::provisioner_job_status,'running'::provisioner_job_status)
75+
-- AND NOT t.deleted -- We don't exclude deleted templates because there's no constraint in the DB preventing a soft deletion on a template while workspaces are running.
7476
GROUP BYt.id,wpb.template_version_id,wpb.transition,wlb.template_version_preset_id;
7577

7678
-- GetPresetsBackoff groups workspace builds by preset ID.

‎enterprise/coderd/prebuilds/reconcile_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,15 @@ func TestPrebuildReconciliation(t *testing.T) {
294294
templateDeleted: []bool{false},
295295
},
296296
{
297-
name:"delete prebuilds for deleted templates",
297+
// Templates can be soft-deleted (`deleted=true`) or hard-deleted (row is removed).
298+
// On the former there is *no* DB constraint to prevent soft deletion, so we have to ensure that if somehow
299+
// the template was soft-deleted any running prebuilds will be removed.
300+
// On the latter there is a DB constraint to prevent row deletion if any workspaces reference the deleting template.
301+
name:"soft-deleted templates MAY have prebuilds",
298302
prebuildLatestTransitions: []database.WorkspaceTransition{database.WorkspaceTransitionStart},
299303
prebuildJobStatuses: []database.ProvisionerJobStatus{database.ProvisionerJobStatusSucceeded},
300304
templateVersionActive: []bool{true,false},
305+
shouldCreateNewPrebuild:ptr.To(false),
301306
shouldDeleteOldPrebuild:ptr.To(true),
302307
templateDeleted: []bool{true},
303308
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp