mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
Implement Quotas v3 (#5012)
* provisioner/terraform: add cost to resource_metadata * provisionerd/runner: use Options struct * Complete provisionerd implementation * Add quota_allowance to groups * Combine Quota and RBAC licenses * Add Opts to InTx
This commit is contained in:
@ -75,10 +75,11 @@ INSERT INTO groups (
|
||||
id,
|
||||
name,
|
||||
organization_id,
|
||||
avatar_url
|
||||
avatar_url,
|
||||
quota_allowance
|
||||
)
|
||||
VALUES
|
||||
( $1, $2, $3, $4) RETURNING *;
|
||||
( $1, $2, $3, $4, $5) RETURNING *;
|
||||
|
||||
-- We use the organization_id as the id
|
||||
-- for simplicity since all users is
|
||||
@ -97,9 +98,10 @@ UPDATE
|
||||
groups
|
||||
SET
|
||||
name = $1,
|
||||
avatar_url = $2
|
||||
avatar_url = $2,
|
||||
quota_allowance = $3
|
||||
WHERE
|
||||
id = $3
|
||||
id = $4
|
||||
RETURNING *;
|
||||
|
||||
-- name: InsertGroupMember :exec
|
||||
|
30
coderd/database/queries/quotas.sql
Normal file
30
coderd/database/queries/quotas.sql
Normal file
@ -0,0 +1,30 @@
|
||||
-- name: GetQuotaAllowanceForUser :one
|
||||
SELECT
|
||||
coalesce(SUM(quota_allowance), 0)::BIGINT
|
||||
FROM
|
||||
group_members gm
|
||||
JOIN groups g ON
|
||||
g.id = gm.group_id
|
||||
WHERE
|
||||
user_id = $1;
|
||||
|
||||
-- name: GetQuotaConsumedForUser :one
|
||||
WITH latest_builds AS (
|
||||
SELECT
|
||||
DISTINCT ON
|
||||
(workspace_id) id,
|
||||
workspace_id,
|
||||
daily_cost
|
||||
FROM
|
||||
workspace_builds wb
|
||||
ORDER BY
|
||||
workspace_id,
|
||||
created_at DESC
|
||||
)
|
||||
SELECT
|
||||
coalesce(SUM(daily_cost), 0)::BIGINT
|
||||
FROM
|
||||
workspaces
|
||||
JOIN latest_builds ON
|
||||
latest_builds.workspace_id = workspaces.id
|
||||
WHERE NOT deleted AND workspaces.owner_id = $1;
|
@ -133,3 +133,12 @@ SET
|
||||
deadline = $4
|
||||
WHERE
|
||||
id = $1 RETURNING *;
|
||||
|
||||
-- name: UpdateWorkspaceBuildCostByID :one
|
||||
UPDATE
|
||||
workspace_builds
|
||||
SET
|
||||
daily_cost = $2
|
||||
WHERE
|
||||
id = $1 RETURNING *;
|
||||
|
||||
|
@ -27,9 +27,9 @@ SELECT * FROM workspace_resources WHERE created_at > $1;
|
||||
|
||||
-- name: InsertWorkspaceResource :one
|
||||
INSERT INTO
|
||||
workspace_resources (id, created_at, job_id, transition, type, name, hide, icon, instance_type)
|
||||
workspace_resources (id, created_at, job_id, transition, type, name, hide, icon, instance_type, daily_cost)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *;
|
||||
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *;
|
||||
|
||||
-- name: GetWorkspaceResourceMetadataByResourceID :many
|
||||
SELECT
|
||||
|
Reference in New Issue
Block a user