Skip to content

Commit b86bce8

Browse files
authored
feat!: Validate monotonic numbers for rich parameters (#6046)
* Database changes * protobuf * Fix: docs * workspaces_test * Validation in coderd * Fix: resources * omitempty * UI changes * UI tests * fix
1 parent e3ae664 commit b86bce8

32 files changed

+914
-389
lines changed

cli/cliui/parameter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,5 @@ func validateRichPrompt(value string, p codersdk.TemplateVersionParameter) error
114114
return codersdk.ValidateWorkspaceBuildParameter(p, codersdk.WorkspaceBuildParameter{
115115
Name: p.Name,
116116
Value: value,
117-
})
117+
}, nil)
118118
}

coderd/apidoc/docs.go

+86-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+76-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbfake/databasefake.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -2573,18 +2573,19 @@ func (q *fakeQuerier) InsertTemplateVersionParameter(_ context.Context, arg data
25732573

25742574
//nolint:gosimple
25752575
param := database.TemplateVersionParameter{
2576-
TemplateVersionID: arg.TemplateVersionID,
2577-
Name: arg.Name,
2578-
Description: arg.Description,
2579-
Type: arg.Type,
2580-
Mutable: arg.Mutable,
2581-
DefaultValue: arg.DefaultValue,
2582-
Icon: arg.Icon,
2583-
Options: arg.Options,
2584-
ValidationError: arg.ValidationError,
2585-
ValidationRegex: arg.ValidationRegex,
2586-
ValidationMin: arg.ValidationMin,
2587-
ValidationMax: arg.ValidationMax,
2576+
TemplateVersionID: arg.TemplateVersionID,
2577+
Name: arg.Name,
2578+
Description: arg.Description,
2579+
Type: arg.Type,
2580+
Mutable: arg.Mutable,
2581+
DefaultValue: arg.DefaultValue,
2582+
Icon: arg.Icon,
2583+
Options: arg.Options,
2584+
ValidationError: arg.ValidationError,
2585+
ValidationRegex: arg.ValidationRegex,
2586+
ValidationMin: arg.ValidationMin,
2587+
ValidationMax: arg.ValidationMax,
2588+
ValidationMonotonic: arg.ValidationMonotonic,
25882589
}
25892590
q.templateVersionParameters = append(q.templateVersionParameters, param)
25902591
return param, nil

coderd/database/dump.sql

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE template_version_parameters DROP CONSTRAINT validation_monotonic_order;
2+
3+
ALTER TABLE template_version_parameters DROP COLUMN validation_monotonic;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ALTER TABLE template_version_parameters ADD COLUMN validation_monotonic text NOT NULL DEFAULT '';
2+
3+
ALTER TABLE template_version_parameters ADD CONSTRAINT validation_monotonic_order CHECK (validation_monotonic IN ('increasing', 'decreasing', ''));
4+
5+
COMMENT ON COLUMN template_version_parameters.validation_monotonic
6+
IS 'Validation: consecutive values preserve the monotonic order';

coderd/database/models.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+22-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templateversionparameters.sql

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ INSERT INTO
1212
validation_regex,
1313
validation_min,
1414
validation_max,
15-
validation_error
15+
validation_error,
16+
validation_monotonic
1617
)
1718
VALUES
1819
(
@@ -27,7 +28,8 @@ VALUES
2728
$9,
2829
$10,
2930
$11,
30-
$12
31+
$12,
32+
$13
3133
) RETURNING *;
3234

3335
-- name: GetTemplateVersionParameters :many

0 commit comments

Comments
 (0)