Skip to content

Commit a83a281

Browse files
committed
feat: add "updated" search param to workspaces
1 parent 369821e commit a83a281

File tree

5 files changed

+54
-23
lines changed

5 files changed

+54
-23
lines changed

coderd/database/modelqueries.go

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
225225
arg.Dormant,
226226
arg.LastUsedBefore,
227227
arg.LastUsedAfter,
228+
arg.UsingActive,
228229
arg.Offset,
229230
arg.Limit,
230231
)

coderd/database/queries.sql.go

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

coderd/database/queries/workspaces.sql

+8-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ WHERE
7979
-- name: GetWorkspaces :many
8080
SELECT
8181
workspaces.*,
82-
COALESCE(template_name.template_name, 'unknown') as template_name,
82+
COALESCE(template.name, 'unknown') as template_name,
8383
latest_build.template_version_id,
8484
latest_build.template_version_name,
8585
COUNT(*) OVER () as count
@@ -120,12 +120,12 @@ LEFT JOIN LATERAL (
120120
) latest_build ON TRUE
121121
LEFT JOIN LATERAL (
122122
SELECT
123-
templates.name AS template_name
123+
*
124124
FROM
125125
templates
126126
WHERE
127127
templates.id = workspaces.template_id
128-
) template_name ON true
128+
) template ON true
129129
WHERE
130130
-- Optionally include deleted workspaces
131131
workspaces.deleted = @deleted
@@ -259,6 +259,11 @@ WHERE
259259
workspaces.last_used_at >= @last_used_after
260260
ELSE true
261261
END
262+
AND CASE
263+
WHEN sqlc.narg('using_active') :: boolean IS NOT NULL THEN
264+
(latest_build.template_version_id = template.active_version_id) = sqlc.narg('using_active') :: boolean
265+
ELSE true
266+
END
262267
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
263268
-- @authorize_filter
264269
ORDER BY

coderd/searchquery/search.go

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package searchquery
22

33
import (
4+
"database/sql"
45
"fmt"
56
"net/url"
67
"strings"
@@ -110,6 +111,12 @@ func Workspaces(query string, page codersdk.Pagination, agentInactiveDisconnectT
110111
filter.Dormant = parser.Boolean(values, false, "dormant")
111112
filter.LastUsedAfter = parser.Time3339Nano(values, time.Time{}, "last_used_after")
112113
filter.LastUsedBefore = parser.Time3339Nano(values, time.Time{}, "last_used_before")
114+
filter.UsingActive = sql.NullBool{
115+
// UsingActive returns if the workspace is on the latest template active version.
116+
// This means the workspace is "up to date".
117+
Bool: parser.Boolean(values, false, "updated"),
118+
Valid: values.Has("updated"),
119+
}
113120

114121
parser.ErrorExcessParams(values)
115122
return filter, parser.Errors

coderd/searchquery/search_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package searchquery_test
22

33
import (
4+
"database/sql"
45
"fmt"
56
"strings"
67
"testing"
@@ -116,6 +117,16 @@ func TestSearchWorkspace(t *testing.T) {
116117
OwnerUsername: "foo",
117118
},
118119
},
120+
{
121+
Name: "Updated",
122+
Query: `updated:true`,
123+
Expected: database.GetWorkspacesParams{
124+
UsingActive: sql.NullBool{
125+
Bool: true,
126+
Valid: true,
127+
},
128+
},
129+
},
119130

120131
// Failures
121132
{

0 commit comments

Comments
 (0)