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

Commit51773ec

Browse files
committed
Simplify workspace_latest_build view
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
1 parent412d198 commit51773ec

File tree

3 files changed

+47
-70
lines changed

3 files changed

+47
-70
lines changed

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ var (
362362

363363
subjectPrebuildsOrchestrator= rbac.Subject{
364364
FriendlyName:"Prebuilds Orchestrator",
365-
ID:prebuilds.OwnerID.String(),
365+
ID:prebuilds.SystemUserID.String(),
366366
Roles:rbac.Roles([]rbac.Role{
367367
{
368368
Identifier: rbac.RoleIdentifier{Name:"prebuilds-orchestrator"},

‎coderd/database/dump.sql

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

‎coderd/database/migrations/000302_prebuilds.up.sql

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,38 @@
11
CREATEVIEWworkspace_latest_buildAS
2-
SELECT wb.*
3-
FROM (SELECTtv.template_id,
4-
wbmax.workspace_id,
5-
MAX(wbmax.build_number)as max_build_number
6-
FROM workspace_builds wbmax
7-
JOIN template_versions tvON (tv.id=wbmax.template_version_id)
8-
GROUP BYtv.template_id,wbmax.workspace_id) wbmax
9-
JOIN workspace_builds wbON (
10-
wb.workspace_id=wbmax.workspace_id
11-
ANDwb.build_number=wbmax.max_build_number
12-
);
2+
SELECT DISTINCTON (workspace_id)*
3+
FROM workspace_builds
4+
ORDER BY workspace_id, build_numberDESC;
135

146
CREATEVIEWworkspace_prebuildsAS
157
WITH
16-
-- All workspaces owned by the "prebuilds" user.
17-
all_prebuildsAS (SELECT w.*
18-
FROM workspaces w
19-
WHEREw.owner_id='c42fdf75-3097-471c-8c33-fb52454d81c0'),-- The system user responsible for prebuilds.
20-
-- All workspace agents belonging to the workspaces owned by the "prebuilds" user.
21-
workspace_agentsAS (SELECTw.idAS workspace_id,wa.idAS agent_id,wa.lifecycle_state,wa.ready_at
22-
FROM workspaces w
23-
INNER JOIN workspace_latest_build wlbONwlb.workspace_id=w.id
24-
INNER JOIN workspace_resources wrONwr.job_id=wlb.job_id
25-
INNER JOIN workspace_agents waONwa.resource_id=wr.id
26-
WHEREw.owner_id='c42fdf75-3097-471c-8c33-fb52454d81c0'-- The system user responsible for prebuilds.
27-
GROUP BYw.id,wa.id),
28-
-- We can't rely on the template_version_preset_id in the workspace_builds table because this value is only set on the
29-
-- initial workspace creation. Subsequent stop/start transitions will not have a value for template_version_preset_id,
30-
-- and therefore we can't rely on (say) the latest build's chosen template_version_preset_id.
31-
--
32-
-- See https://github.com/coder/internal/issues/398
33-
current_presetsAS (SELECTw.idAS prebuild_id,lps.template_version_preset_id
34-
FROM workspaces w
35-
INNER JOIN (
36-
-- The latest workspace build which had a preset explicitly selected
37-
SELECT wb.*
38-
FROM (SELECTtv.template_id,
39-
wbmax.workspace_id,
40-
MAX(wbmax.build_number)as max_build_number
41-
FROM workspace_builds wbmax
42-
JOIN template_versions tvON (tv.id=wbmax.template_version_id)
43-
WHEREwbmax.template_version_preset_idIS NOT NULL
44-
GROUP BYtv.template_id,wbmax.workspace_id) wbmax
45-
JOIN workspace_builds wbON (
46-
wb.workspace_id=wbmax.workspace_id
47-
ANDwb.build_number=wbmax.max_build_number
48-
)) lpsONlps.workspace_id=w.id
49-
WHEREw.owner_id='c42fdf75-3097-471c-8c33-fb52454d81c0')-- The system user responsible for prebuilds.
8+
-- All workspaces owned by the "prebuilds" user.
9+
all_prebuildsAS (SELECT w.*
10+
FROM workspaces w
11+
WHEREw.owner_id='c42fdf75-3097-471c-8c33-fb52454d81c0'),-- The system user responsible for prebuilds.
12+
-- We can't rely on the template_version_preset_id in the workspace_builds table because this value is only set on the
13+
-- initial workspace creation. Subsequent stop/start transitions will not have a value for template_version_preset_id,
14+
-- and therefore we can't rely on (say) the latest build's chosen template_version_preset_id.
15+
--
16+
-- See https://github.com/coder/internal/issues/398
17+
latest_prebuild_buildsAS (SELECT*
18+
FROM workspace_latest_build
19+
WHERE template_version_preset_idIS NOT NULL),
20+
-- All workspace agents belonging to the workspaces owned by the "prebuilds" user.
21+
workspace_agentsAS (SELECTw.idAS workspace_id,wa.idAS agent_id,wa.lifecycle_state,wa.ready_at
22+
FROM workspaces w
23+
INNER JOIN workspace_latest_build wlbONwlb.workspace_id=w.id
24+
INNER JOIN workspace_resources wrONwr.job_id=wlb.job_id
25+
INNER JOIN workspace_agents waONwa.resource_id=wr.id
26+
WHEREw.owner_id='c42fdf75-3097-471c-8c33-fb52454d81c0'-- The system user responsible for prebuilds.
27+
GROUP BYw.id,wa.id),
28+
current_presetsAS (SELECTw.idAS prebuild_id,lpb.template_version_preset_id
29+
FROM workspaces w
30+
INNER JOIN latest_prebuild_builds lpbONlpb.workspace_id=w.id
31+
WHEREw.owner_id='c42fdf75-3097-471c-8c33-fb52454d81c0')-- The system user responsible for prebuilds.
5032
SELECT p.*,a.agent_id,a.lifecycle_state,a.ready_at,cp.template_version_preset_idAS current_preset_id
5133
FROM all_prebuilds p
52-
LEFT JOIN workspace_agents aONa.workspace_id=p.id
53-
INNER JOIN current_presets cpONcp.prebuild_id=p.id;
34+
LEFT JOIN workspace_agents aONa.workspace_id=p.id
35+
INNER JOIN current_presets cpONcp.prebuild_id=p.id;
5436

5537
CREATEVIEWworkspace_prebuild_buildsAS
5638
SELECT*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp