Files
coder/coderd/database/queries/presets.sql
T
Susana Ferreira 0672bf5084 feat: support icon and description in preset (#18977)
## Description 

This PR adds support for `description` and `icon` fields to
`template_version_presets`. These fields will allow displaying richer
information for presets in the UI, improving the user experience when
creating a workspace.
Both fields are optional, non-nullable, and default to empty strings.

## Changes

* Database migration with the addition of `description VARCHAR(128)` and
`icon VARCHAR(256)` columns to the `template_version_presets` table.
* Updated the `CreateWorkspacePageView` in the UI

Note: UI changes will be addressed in a separate PR
2025-07-28 15:02:26 +01:00

106 lines
2.5 KiB
SQL

-- name: InsertPreset :one
INSERT INTO template_version_presets (
id,
template_version_id,
name,
created_at,
desired_instances,
invalidate_after_secs,
scheduling_timezone,
is_default,
description,
icon
)
VALUES (
@id,
@template_version_id,
@name,
@created_at,
@desired_instances,
@invalidate_after_secs,
@scheduling_timezone,
@is_default,
@description,
@icon
) RETURNING *;
-- name: InsertPresetParameters :many
INSERT INTO
template_version_preset_parameters (template_version_preset_id, name, value)
SELECT
@template_version_preset_id,
unnest(@names :: TEXT[]),
unnest(@values :: TEXT[])
RETURNING *;
-- name: InsertPresetPrebuildSchedule :one
INSERT INTO template_version_preset_prebuild_schedules (
preset_id,
cron_expression,
desired_instances
)
VALUES (
@preset_id,
@cron_expression,
@desired_instances
) RETURNING *;
-- name: UpdatePresetPrebuildStatus :exec
UPDATE template_version_presets
SET prebuild_status = @status
WHERE id = @preset_id;
-- name: GetPresetsByTemplateVersionID :many
SELECT
*
FROM
template_version_presets
WHERE
template_version_id = @template_version_id;
-- name: GetPresetByWorkspaceBuildID :one
SELECT
template_version_presets.*
FROM
template_version_presets
INNER JOIN workspace_builds ON workspace_builds.template_version_preset_id = template_version_presets.id
WHERE
workspace_builds.id = @workspace_build_id;
-- name: GetPresetParametersByTemplateVersionID :many
SELECT
template_version_preset_parameters.*
FROM
template_version_preset_parameters
INNER JOIN template_version_presets ON template_version_preset_parameters.template_version_preset_id = template_version_presets.id
WHERE
template_version_presets.template_version_id = @template_version_id;
-- name: GetPresetParametersByPresetID :many
SELECT
tvpp.*
FROM
template_version_preset_parameters tvpp
WHERE
tvpp.template_version_preset_id = @preset_id;
-- name: GetPresetByID :one
SELECT tvp.*, tv.template_id, tv.organization_id FROM
template_version_presets tvp
INNER JOIN template_versions tv ON tvp.template_version_id = tv.id
WHERE tvp.id = @preset_id;
-- name: GetActivePresetPrebuildSchedules :many
SELECT
tvpps.*
FROM
template_version_preset_prebuild_schedules tvpps
INNER JOIN template_version_presets tvp ON tvp.id = tvpps.preset_id
INNER JOIN template_versions tv ON tv.id = tvp.template_version_id
INNER JOIN templates t ON t.id = tv.template_id
WHERE
-- Template version is active, and template is not deleted or deprecated
tv.id = t.active_version_id
AND NOT t.deleted
AND t.deprecated = '';