2022-04-06 12:42:40 -05:00
|
|
|
-- name: GetTemplateByID :one
|
2022-04-01 15:45:23 -05:00
|
|
|
SELECT
|
|
|
|
|
*
|
|
|
|
|
FROM
|
2022-04-06 12:42:40 -05:00
|
|
|
templates
|
2022-04-01 15:45:23 -05:00
|
|
|
WHERE
|
|
|
|
|
id = $1
|
|
|
|
|
LIMIT
|
|
|
|
|
1;
|
|
|
|
|
|
2022-06-14 08:46:33 -05:00
|
|
|
-- name: GetTemplatesWithFilter :many
|
2022-04-01 15:45:23 -05:00
|
|
|
SELECT
|
|
|
|
|
*
|
|
|
|
|
FROM
|
2022-04-06 12:42:40 -05:00
|
|
|
templates
|
2022-04-01 15:45:23 -05:00
|
|
|
WHERE
|
2022-06-14 08:46:33 -05:00
|
|
|
-- Optionally include deleted templates
|
|
|
|
|
templates.deleted = @deleted
|
|
|
|
|
-- Filter by organization_id
|
|
|
|
|
AND CASE
|
|
|
|
|
WHEN @organization_id :: uuid != '00000000-00000000-00000000-00000000' THEN
|
|
|
|
|
organization_id = @organization_id
|
|
|
|
|
ELSE true
|
|
|
|
|
END
|
|
|
|
|
-- Filter by exact name
|
|
|
|
|
AND CASE
|
|
|
|
|
WHEN @exact_name :: text != '' THEN
|
|
|
|
|
LOWER("name") = LOWER(@exact_name)
|
|
|
|
|
ELSE true
|
|
|
|
|
END
|
|
|
|
|
-- Filter by ids
|
|
|
|
|
AND CASE
|
|
|
|
|
WHEN array_length(@ids :: uuid[], 1) > 0 THEN
|
|
|
|
|
id = ANY(@ids)
|
|
|
|
|
ELSE true
|
|
|
|
|
END
|
2022-08-05 13:03:22 -05:00
|
|
|
ORDER BY (name, id) ASC
|
2022-06-14 08:46:33 -05:00
|
|
|
;
|
2022-04-01 15:45:23 -05:00
|
|
|
|
2022-04-06 12:42:40 -05:00
|
|
|
-- name: GetTemplateByOrganizationAndName :one
|
2022-04-01 15:45:23 -05:00
|
|
|
SELECT
|
|
|
|
|
*
|
|
|
|
|
FROM
|
2022-04-06 12:42:40 -05:00
|
|
|
templates
|
2022-04-01 15:45:23 -05:00
|
|
|
WHERE
|
|
|
|
|
organization_id = @organization_id
|
|
|
|
|
AND deleted = @deleted
|
|
|
|
|
AND LOWER("name") = LOWER(@name)
|
|
|
|
|
LIMIT
|
|
|
|
|
1;
|
|
|
|
|
|
2022-06-17 00:26:40 -05:00
|
|
|
-- name: GetTemplates :many
|
2022-07-27 18:04:29 +03:00
|
|
|
SELECT * FROM templates
|
2022-08-05 13:03:22 -05:00
|
|
|
ORDER BY (name, id) ASC
|
2022-07-27 18:04:29 +03:00
|
|
|
;
|
2022-06-17 00:26:40 -05:00
|
|
|
|
2022-04-06 12:42:40 -05:00
|
|
|
-- name: InsertTemplate :one
|
2022-04-01 15:45:23 -05:00
|
|
|
INSERT INTO
|
2022-04-06 12:42:40 -05:00
|
|
|
templates (
|
2022-04-01 15:45:23 -05:00
|
|
|
id,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at,
|
|
|
|
|
organization_id,
|
|
|
|
|
"name",
|
|
|
|
|
provisioner,
|
2022-05-16 15:56:11 -05:00
|
|
|
active_version_id,
|
2022-06-07 13:37:45 +01:00
|
|
|
description,
|
|
|
|
|
max_ttl,
|
2022-06-10 15:24:21 -04:00
|
|
|
min_autostart_interval,
|
2022-08-19 10:17:35 -03:00
|
|
|
created_by,
|
|
|
|
|
icon
|
2022-04-01 15:45:23 -05:00
|
|
|
)
|
|
|
|
|
VALUES
|
2022-08-19 10:17:35 -03:00
|
|
|
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *;
|
2022-04-01 15:45:23 -05:00
|
|
|
|
2022-04-06 12:42:40 -05:00
|
|
|
-- name: UpdateTemplateActiveVersionByID :exec
|
2022-04-01 15:45:23 -05:00
|
|
|
UPDATE
|
2022-04-06 12:42:40 -05:00
|
|
|
templates
|
2022-04-01 15:45:23 -05:00
|
|
|
SET
|
2022-06-30 08:14:51 -04:00
|
|
|
active_version_id = $2,
|
|
|
|
|
updated_at = $3
|
2022-04-01 15:45:23 -05:00
|
|
|
WHERE
|
|
|
|
|
id = $1;
|
|
|
|
|
|
2022-04-06 12:42:40 -05:00
|
|
|
-- name: UpdateTemplateDeletedByID :exec
|
2022-04-01 15:45:23 -05:00
|
|
|
UPDATE
|
2022-04-06 12:42:40 -05:00
|
|
|
templates
|
2022-04-01 15:45:23 -05:00
|
|
|
SET
|
2022-06-30 08:14:51 -04:00
|
|
|
deleted = $2,
|
|
|
|
|
updated_at = $3
|
2022-04-01 15:45:23 -05:00
|
|
|
WHERE
|
|
|
|
|
id = $1;
|
2022-06-08 15:14:57 +01:00
|
|
|
|
2022-09-09 11:34:23 -05:00
|
|
|
-- name: UpdateTemplateMetaByID :one
|
2022-06-08 15:14:57 +01:00
|
|
|
UPDATE
|
|
|
|
|
templates
|
|
|
|
|
SET
|
|
|
|
|
updated_at = $2,
|
|
|
|
|
description = $3,
|
|
|
|
|
max_ttl = $4,
|
2022-08-17 16:04:00 -03:00
|
|
|
min_autostart_interval = $5,
|
2022-08-19 10:17:35 -03:00
|
|
|
name = $6,
|
|
|
|
|
icon = $7
|
2022-06-08 15:14:57 +01:00
|
|
|
WHERE
|
|
|
|
|
id = $1
|
|
|
|
|
RETURNING
|
|
|
|
|
*;
|