10000 feat: Allow inheriting parameters from previous template_versions when updating a template by Emyrk · Pull Request #2397 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: Allow inheriting parameters from previous template_versions when updating a template #2397

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 18 commits into from
Jun 17, 2022
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
8000
Prev Previous commit
Next Next commit
Fix db query for scope enum
  • Loading branch information
Emyrk committed Jun 16, 2022
commit 9d17dac16840a773ca56d65877236711cc4a52c5
7 changes: 4 additions & 3 deletions coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,11 @@ func (q *fakeQuerier) ParameterValues(_ context.Context, arg database.ParameterV

parameterValues := make([]database.ParameterValue, 0)
for _, parameterValue := range q.parameterValues {
if arg.Scope != "" && parameterValue.Scope != arg.Scope {
continue
if len(arg.Scopes) > 0 {
if !contains(arg.Scopes, parameterValue.Scope) {
continue
}
}

if len(arg.ScopeIds) > 0 {
if !contains(arg.ScopeIds, parameterValue.ScopeID) {
continue
Expand Down
21 changes: 9 additions & 12 deletions coderd/database/queries.sql.go

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

11 changes: 4 additions & 7 deletions coderd/database/queries/parametervalues.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ SELECT
FROM
parameter_values
WHERE
CASE
-- We need to double cast this. First cast is for the sqlc type,
-- the second case is to convert it to text as the empty string
-- is not a valid parameter_scope enum.
WHEN (@scope :: parameter_scope) :: text != '' THEN
scope = @scope :: parameter_scope
ELSE true
CASE
WHEN cardinality(@scopes :: parameter_scope[]) > 0 THEN
scope = ANY(@scopes :: parameter_scope[])
ELSE true
END
AND CASE
WHEN cardinality(@scope_ids :: uuid[]) > 0 THEN
Expand Down
8 changes: 4 additions & 4 deletions coderd/parameter/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func Compute(ctx context.Context, db database.Store, scope ComputeScope, options

// Job parameters come second!
err = compute.injectScope(ctx, database.ParameterValuesParams{
Scope: database.ParameterScopeImportJob,
Scopes: []database.ParameterScope{database.ParameterScopeImportJob},
ScopeIds: []uuid.UUID{scope.TemplateImportJobID},
})
if err != nil {
Expand Down Expand Up @@ -106,7 +106,7 @@ func Compute(ctx context.Context, db database.Store, scope ComputeScope, options
if scope.TemplateID.Valid {
// Template parameters come third!
err = compute.injectScope(ctx, database.ParameterValuesParams{
Scope: database.ParameterScopeTemplate,
Scopes: []database.ParameterScope{database.ParameterScopeTemplate},
ScopeIds: []uuid.UUID{scope.TemplateID.UUID},
})
if err != nil {
Expand All @@ -117,7 +117,7 @@ func Compute(ctx context.Context, db database.Store, scope ComputeScope, options
if scope.WorkspaceID.Valid {
// Workspace parameters come last!
err = compute.injectScope(ctx, C773 database.ParameterValuesParams{
Scope: database.ParameterScopeWorkspace,
Scopes: []database.ParameterScope{database.ParameterScopeWorkspace},
ScopeIds: []uuid.UUID{scope.WorkspaceID.UUID},
})
if err != nil {
Expand Down Expand Up @@ -154,7 +154,7 @@ func (c *compute) injectScope(ctx context.Context, scopeParams database.Paramete
err = nil
}
if err != nil {
return xerrors.Errorf("get %s parameters: %w", scopeParams.Scope, err)
return xerrors.Errorf("get %s parameters: %w", scopeParams.Scopes, err)
}

for _, scopedParameter := range scopedParameters {
Expand Down
2 changes: 1 addition & 1 deletion coderd/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (api *API) parameters(rw http.ResponseWriter, r *http.Request) {
}

parameterValues, err := api.Database.ParameterValues(r.Context(), database.ParameterValuesParams{
Scope: scope,
Scopes: []database.ParameterScope{scope},
ScopeIds: []uuid.UUID{scopeID},
})
if errors.Is(err, sql.ErrNoRows) {
Expand Down
0