|
| 1 | +-- name: ClaimPrebuiltWorkspace :one |
| 2 | +UPDATE workspaces w |
| 3 | +SET owner_id = @new_user_id::uuid, |
| 4 | + name = @new_name::text, |
| 5 | + updated_at = NOW() |
| 6 | +WHERE w.id IN ( |
| 7 | + SELECT p.id |
| 8 | + FROM workspace_prebuilds p |
| 9 | + INNER JOIN workspace_latest_builds b ON b.workspace_id = p.id |
| 10 | + INNER JOIN templates t ON p.template_id = t.id |
| 11 | + WHERE (b.transition = 'start'::workspace_transition |
| 12 | + AND b.job_status IN ('succeeded'::provisioner_job_status)) |
| 13 | + -- The prebuilds system should never try to claim a prebuild for an inactive template version. |
| 14 | + -- Nevertheless, this filter is here as a defensive measure: |
| 15 | + AND b.template_version_id = t.active_version_id |
| 16 | + AND p.current_preset_id = @preset_id::uuid |
| 17 | + AND p.ready |
| 18 | + LIMIT 1 FOR UPDATE OF p SKIP LOCKED -- Ensure that a concurrent request will not select the same prebuild. |
| 19 | +) |
| 20 | +RETURNING w.id, w.name; |
| 21 | + |
1 | 22 | -- name: GetTemplatePresetsWithPrebuilds :many
|
2 | 23 | -- GetTemplatePresetsWithPrebuilds retrieves template versions with configured presets.
|
3 | 24 | -- It also returns the number of desired instances for each preset.
|
@@ -104,27 +125,6 @@ WHERE tsb.rn <= tsb.desired_instances -- Fetch the last N builds, where N is the
|
104 | 125 | AND created_at >= @lookback::timestamptz
|
105 | 126 | GROUP BY tsb.template_version_id, tsb.preset_id, fc.num_failed;
|
106 | 127 |
|
107 |
| --- name: ClaimPrebuiltWorkspace :one |
108 |
| -UPDATE workspaces w |
109 |
| -SET owner_id = @new_user_id::uuid, |
110 |
| - name = @new_name::text, |
111 |
| - updated_at = NOW() |
112 |
| -WHERE w.id IN ( |
113 |
| - SELECT p.id |
114 |
| - FROM workspace_prebuilds p |
115 |
| - INNER JOIN workspace_latest_builds b ON b.workspace_id = p.id |
116 |
| - INNER JOIN templates t ON p.template_id = t.id |
117 |
| - WHERE (b.transition = 'start'::workspace_transition |
118 |
| - AND b.job_status IN ('succeeded'::provisioner_job_status)) |
119 |
| - -- The prebuilds system should never try to claim a prebuild for an inactive template version. |
120 |
| - -- Nevertheless, this filter is here as a defensive measure: |
121 |
| - AND b.template_version_id = t.active_version_id |
122 |
| - AND p.current_preset_id = @preset_id::uuid |
123 |
| - AND p.ready |
124 |
| - LIMIT 1 FOR UPDATE OF p SKIP LOCKED -- Ensure that a concurrent request will not select the same prebuild. |
125 |
| -) |
126 |
| -RETURNING w.id, w.name; |
127 |
| - |
128 | 128 | -- name: GetPrebuildMetrics :many
|
129 | 129 | SELECT
|
130 | 130 | t.name as template_name,
|
|
0 commit comments