mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: mark coder_parameter as "required" (#6433)
* Add required column * Pass through providerd * Pass the required property down * Optional * Fix * Fix * Fix * fix * CLI create: support for optional fields * Use HTML API to mark fields required * Fix * Improve validation * more fixes * make fmt * Fix * WIP * Fix: test * CLI update tets * OptionalParameterAdded * Fix: migration
This commit is contained in:
@ -2722,6 +2722,7 @@ func (q *fakeQuerier) InsertTemplateVersionParameter(_ context.Context, arg data
|
||||
ValidationMin: arg.ValidationMin,
|
||||
ValidationMax: arg.ValidationMax,
|
||||
ValidationMonotonic: arg.ValidationMonotonic,
|
||||
Required: arg.Required,
|
||||
}
|
||||
q.templateVersionParameters = append(q.templateVersionParameters, param)
|
||||
return param, nil
|
||||
|
3
coderd/database/dump.sql
generated
3
coderd/database/dump.sql
generated
@ -351,6 +351,7 @@ CREATE TABLE template_version_parameters (
|
||||
validation_max integer NOT NULL,
|
||||
validation_error text DEFAULT ''::text NOT NULL,
|
||||
validation_monotonic text DEFAULT ''::text NOT NULL,
|
||||
required boolean DEFAULT true NOT NULL,
|
||||
CONSTRAINT validation_monotonic_order CHECK ((validation_monotonic = ANY (ARRAY['increasing'::text, 'decreasing'::text, ''::text])))
|
||||
);
|
||||
|
||||
@ -378,6 +379,8 @@ COMMENT ON COLUMN template_version_parameters.validation_error IS 'Validation: e
|
||||
|
||||
COMMENT ON COLUMN template_version_parameters.validation_monotonic IS 'Validation: consecutive values preserve the monotonic order';
|
||||
|
||||
COMMENT ON COLUMN template_version_parameters.required IS 'Is parameter required?';
|
||||
|
||||
CREATE TABLE template_version_variables (
|
||||
template_version_id uuid NOT NULL,
|
||||
name text NOT NULL,
|
||||
|
@ -0,0 +1 @@
|
||||
ALTER TABLE template_version_parameters DROP COLUMN required;
|
@ -0,0 +1,3 @@
|
||||
ALTER TABLE template_version_parameters ADD COLUMN required boolean NOT NULL DEFAULT true; -- default: true, as so far every parameter should be marked as required
|
||||
|
||||
COMMENT ON COLUMN template_version_parameters.required IS 'Is parameter required?';
|
@ -1467,6 +1467,8 @@ type TemplateVersionParameter struct {
|
||||
ValidationError string `db:"validation_error" json:"validation_error"`
|
||||
// Validation: consecutive values preserve the monotonic order
|
||||
ValidationMonotonic string `db:"validation_monotonic" json:"validation_monotonic"`
|
||||
// Is parameter required?
|
||||
Required bool `db:"required" json:"required"`
|
||||
}
|
||||
|
||||
type TemplateVersionVariable struct {
|
||||
|
@ -3556,7 +3556,7 @@ func (q *sqlQuerier) UpdateTemplateScheduleByID(ctx context.Context, arg UpdateT
|
||||
}
|
||||
|
||||
const getTemplateVersionParameters = `-- name: GetTemplateVersionParameters :many
|
||||
SELECT template_version_id, name, description, type, mutable, default_value, icon, options, validation_regex, validation_min, validation_max, validation_error, validation_monotonic FROM template_version_parameters WHERE template_version_id = $1
|
||||
SELECT template_version_id, name, description, type, mutable, default_value, icon, options, validation_regex, validation_min, validation_max, validation_error, validation_monotonic, required FROM template_version_parameters WHERE template_version_id = $1
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetTemplateVersionParameters(ctx context.Context, templateVersionID uuid.UUID) ([]TemplateVersionParameter, error) {
|
||||
@ -3582,6 +3582,7 @@ func (q *sqlQuerier) GetTemplateVersionParameters(ctx context.Context, templateV
|
||||
&i.ValidationMax,
|
||||
&i.ValidationError,
|
||||
&i.ValidationMonotonic,
|
||||
&i.Required,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -3611,7 +3612,8 @@ INSERT INTO
|
||||
validation_min,
|
||||
validation_max,
|
||||
validation_error,
|
||||
validation_monotonic
|
||||
validation_monotonic,
|
||||
required
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@ -3627,8 +3629,9 @@ VALUES
|
||||
$10,
|
||||
$11,
|
||||
$12,
|
||||
$13
|
||||
) RETURNING template_version_id, name, description, type, mutable, default_value, icon, options, validation_regex, validation_min, validation_max, validation_error, validation_monotonic
|
||||
$13,
|
||||
$14
|
||||
) RETURNING template_version_id, name, description, type, mutable, default_value, icon, options, validation_regex, validation_min, validation_max, validation_error, validation_monotonic, required
|
||||
`
|
||||
|
||||
type InsertTemplateVersionParameterParams struct {
|
||||
@ -3645,6 +3648,7 @@ type InsertTemplateVersionParameterParams struct {
|
||||
ValidationMax int32 `db:"validation_max" json:"validation_max"`
|
||||
ValidationError string `db:"validation_error" json:"validation_error"`
|
||||
ValidationMonotonic string `db:"validation_monotonic" json:"validation_monotonic"`
|
||||
Required bool `db:"required" json:"required"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertTemplateVersionParameter(ctx context.Context, arg InsertTemplateVersionParameterParams) (TemplateVersionParameter, error) {
|
||||
@ -3662,6 +3666,7 @@ func (q *sqlQuerier) InsertTemplateVersionParameter(ctx context.Context, arg Ins
|
||||
arg.ValidationMax,
|
||||
arg.ValidationError,
|
||||
arg.ValidationMonotonic,
|
||||
arg.Required,
|
||||
)
|
||||
var i TemplateVersionParameter
|
||||
err := row.Scan(
|
||||
@ -3678,6 +3683,7 @@ func (q *sqlQuerier) InsertTemplateVersionParameter(ctx context.Context, arg Ins
|
||||
&i.ValidationMax,
|
||||
&i.ValidationError,
|
||||
&i.ValidationMonotonic,
|
||||
&i.Required,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
@ -13,7 +13,8 @@ INSERT INTO
|
||||
validation_min,
|
||||
validation_max,
|
||||
validation_error,
|
||||
validation_monotonic
|
||||
validation_monotonic,
|
||||
required
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@ -29,7 +30,8 @@ VALUES
|
||||
$10,
|
||||
$11,
|
||||
$12,
|
||||
$13
|
||||
$13,
|
||||
$14
|
||||
) RETURNING *;
|
||||
|
||||
-- name: GetTemplateVersionParameters :many
|
||||
|
Reference in New Issue
Block a user