Skip to content

Commit 804f4a1

Browse files
committed
add pinned status to GetWorkspaces/GetAuthorizedWorkspaces queries
1 parent faeab68 commit 804f4a1

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

coderd/database/modelqueries.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
213213
// The name comment is for metric tracking
214214
query := fmt.Sprintf("-- name: GetAuthorizedWorkspaces :many\n%s", filtered)
215215
rows, err := q.db.QueryContext(ctx, query,
216+
arg.OwnerID,
216217
arg.Deleted,
217218
arg.Status,
218-
arg.OwnerID,
219219
arg.OwnerUsername,
220220
arg.TemplateName,
221221
pq.Array(arg.TemplateIDs),
@@ -253,6 +253,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
253253
&i.TemplateName,
254254
&i.TemplateVersionID,
255255
&i.TemplateVersionName,
256+
&i.Pinned,
256257
&i.Count,
257258
); err != nil {
258259
return nil, err

coderd/database/queries.sql.go

+32-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

+15
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ SELECT
8282
COALESCE(template_name.template_name, 'unknown') as template_name,
8383
latest_build.template_version_id,
8484
latest_build.template_version_name,
85+
(upw.user_id IS NOT NULL)::boolean AS pinned,
8586
COUNT(*) OVER () as count
8687
FROM
8788
workspaces
@@ -126,6 +127,19 @@ LEFT JOIN LATERAL (
126127
WHERE
127128
templates.id = workspaces.template_id
128129
) template_name ON true
130+
LEFT JOIN LATERAL (
131+
SELECT
132+
user_id
133+
FROM
134+
user_pinned_workspaces
135+
WHERE
136+
workspaces.id = user_pinned_workspaces.workspace_id
137+
AND
138+
-- Omitting the owner_id parameter will result in
139+
-- 00000000-0000-0000-0000-000000000000 which will not match
140+
-- any rows in user_pinned_workspaces.
141+
user_pinned_workspaces.user_id = @owner_id
142+
) upw ON TRUE
129143
WHERE
130144
-- Optionally include deleted workspaces
131145
workspaces.deleted = @deleted
@@ -262,6 +276,7 @@ WHERE
262276
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
263277
-- @authorize_filter
264278
ORDER BY
279+
pinned DESC,
265280
(latest_build.completed_at IS NOT NULL AND
266281
latest_build.canceled_at IS NULL AND
267282
latest_build.error IS NULL AND

0 commit comments

Comments
 (0)