mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
Migrations
Exclude system users from users.sql queries Signed-off-by: Danny Kopping <danny@coder.com>
This commit is contained in:
28
coderd/database/queries/prebuilds.sql
Normal file
28
coderd/database/queries/prebuilds.sql
Normal file
@ -0,0 +1,28 @@
|
||||
-- name: GetTemplatePrebuildState :many
|
||||
WITH latest_workspace_builds AS (SELECT wb.id,
|
||||
wb.workspace_id,
|
||||
wbmax.template_id,
|
||||
wb.template_version_id
|
||||
FROM (SELECT tv.template_id,
|
||||
wbmax.workspace_id,
|
||||
MAX(wbmax.build_number) as max_build_number
|
||||
FROM workspace_builds wbmax
|
||||
JOIN template_versions tv ON (tv.id = wbmax.template_version_id)
|
||||
GROUP BY tv.template_id, wbmax.workspace_id) wbmax
|
||||
JOIN workspace_builds wb ON (
|
||||
wb.workspace_id = wbmax.workspace_id
|
||||
AND wb.build_number = wbmax.max_build_number
|
||||
))
|
||||
-- TODO: need to store the desired instances & autoscaling schedules in db; use desired value here
|
||||
SELECT CAST(1 AS integer) AS desired,
|
||||
CAST(COUNT(wp.*) AS integer) AS actual,
|
||||
CAST(0 AS integer) AS extraneous, -- TODO: calculate this by subtracting actual from count not matching template version
|
||||
t.deleted,
|
||||
t.deprecated,
|
||||
tv.id AS template_version_id
|
||||
FROM latest_workspace_builds lwb
|
||||
JOIN template_versions tv ON lwb.template_version_id = tv.id
|
||||
JOIN templates t ON t.id = lwb.template_id
|
||||
LEFT JOIN workspace_prebuilds wp ON wp.id = lwb.workspace_id
|
||||
WHERE t.id = @template_id::uuid
|
||||
GROUP BY t.id, t.deleted, t.deprecated, tv.id;
|
@ -46,7 +46,8 @@ SELECT
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
deleted = false;
|
||||
deleted = false
|
||||
AND is_system = false;
|
||||
|
||||
-- name: GetActiveUserCount :one
|
||||
SELECT
|
||||
@ -54,7 +55,8 @@ SELECT
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
status = 'active'::user_status AND deleted = false;
|
||||
status = 'active'::user_status AND deleted = false
|
||||
AND is_system = false;
|
||||
|
||||
-- name: InsertUser :one
|
||||
INSERT INTO
|
||||
@ -144,6 +146,7 @@ FROM
|
||||
users
|
||||
WHERE
|
||||
users.deleted = false
|
||||
AND is_system = false
|
||||
AND CASE
|
||||
-- This allows using the last element on a page as effectively a cursor.
|
||||
-- This is an important option for scripts that need to paginate without
|
||||
@ -302,11 +305,13 @@ SET
|
||||
WHERE
|
||||
last_seen_at < @last_seen_after :: timestamp
|
||||
AND status = 'active'::user_status
|
||||
AND is_system = false
|
||||
RETURNING id, email, username, last_seen_at;
|
||||
|
||||
-- AllUserIDs returns all UserIDs regardless of user status or deletion.
|
||||
-- name: AllUserIDs :many
|
||||
SELECT DISTINCT id FROM USERS;
|
||||
SELECT DISTINCT id FROM USERS
|
||||
WHERE is_system = false;
|
||||
|
||||
-- name: UpdateUserHashedOneTimePasscode :exec
|
||||
UPDATE
|
||||
|
Reference in New Issue
Block a user