Files
coder/coderd/database/queries/templates.sql
Cian Johnston 3e419ddb3d feat: enforce template-level constraints for TTL and autostart (#2018)
This PR adds fields to templates that constrain values for workspaces derived from that template.

- Autostop: Adds a field max_ttl on the template which limits the maximum value of ttl on all workspaces derived from that template. Defaulting to 168 hours, enforced on edits to workspace metadata. New workspaces will default to the templates's `max_ttl` if not specified.
- Autostart: Adds a field min_autostart_duration which limits the minimum duration between successive autostarts of a template, measured from a single reference time. Defaulting to 1 hour, enforced on edits to workspace metadata.
2022-06-07 13:37:45 +01:00

72 lines
951 B
SQL

-- name: GetTemplateByID :one
SELECT
*
FROM
templates
WHERE
id = $1
LIMIT
1;
-- name: GetTemplatesByIDs :many
SELECT
*
FROM
templates
WHERE
id = ANY(@ids :: uuid [ ]);
-- name: GetTemplateByOrganizationAndName :one
SELECT
*
FROM
templates
WHERE
organization_id = @organization_id
AND deleted = @deleted
AND LOWER("name") = LOWER(@name)
LIMIT
1;
-- name: GetTemplatesByOrganization :many
SELECT
*
FROM
templates
WHERE
organization_id = $1
AND deleted = $2;
-- name: InsertTemplate :one
INSERT INTO
templates (
id,
created_at,
updated_at,
organization_id,
"name",
provisioner,
active_version_id,
description,
max_ttl,
min_autostart_interval
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *;
-- name: UpdateTemplateActiveVersionByID :exec
UPDATE
templates
SET
active_version_id = $2
WHERE
id = $1;
-- name: UpdateTemplateDeletedByID :exec
UPDATE
templates
SET
deleted = $2
WHERE
id = $1;