8000 feat(coderd/database): add support for presets by SasSwart · Pull Request #16509 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat(coderd/database): add support for presets #16509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
stop using gen_random_uuid
  • Loading branch information
SasSwart committed Feb 11, 2025
commit bc7e7d2dce7e48ac448859c1c53d62c94566ff92
4 changes: 2 additions & 2 deletions coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
-- TODO (sasswart): add IF NOT EXISTS and other clauses to make the migration more robust
CREATE TABLE template_version_presets
(
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
id UUID PRIMARY KEY NOT NULL,
template_version_id UUID NOT NULL,
name TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- TODO (sasswart): Will auditing have any relevance to presets?
FOREIGN KEY (template_version_id) REFERENCES template_versions (id) ON DELETE CASCADE
);

CREATE TABLE template_version_preset_parameters
(
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
id UUID PRIMARY KEY NOT NULL,
template_version_preset_id UUID NOT NULL,
name TEXT NOT NULL,
-- TODO (sasswart): would it be beneficial to allow presets to still offer a choice for values?
-- This would allow an operator to avoid having to create many similar templates where only one or
-- a few values are different.
value TEXT NOT NULL,
FOREIGN KEY (template_version_preset_id) REFERENCES template_version_presets (id) ON DELETE CASCADE
);
Expand All @@ -28,9 +23,6 @@ ALTER TABLE workspace_builds
ADD CONSTRAINT workspace_builds_template_version_preset_id_fkey
FOREIGN KEY (template_version_preset_id)
REFERENCES template_version_presets (id)
-- TODO (sasswart): SET NULL might not be the best choice here. The rest of the hierarchy has ON DELETE CASCADE.
-- We don't want CASCADE here, because we don't want to delete the workspace build if the preset is deleted.
-- However, do we want to lose record of the preset id for a workspace build?
ON DELETE SET NULL;

-- Recreate the view to include the new column.
Expand Down
27 changes: 20 additions & 7 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions coderd/database/queries/presets.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
-- name: InsertPreset :one
INSERT INTO
template_version_presets (template_version_id, name, created_at)
template_version_presets (id, template_version_id, name, created_at)
VALUES
(@template_version_id, @name, @created_at) RETURNING *;
(@id, @template_version_id, @name, @created_at) RETURNING *;

-- name: InsertPresetParameters :many
INSERT INTO
template_version_preset_parameters (template_version_preset_id, name, value)
template_version_preset_parameters (id, template_version_preset_id, name, value)
SELECT
@id,
@template_version_preset_id,
unnest(@names :: TEXT[]),
unnest(@values :: TEXT[])
Expand Down
Loading
0