Skip to content

Commit

Permalink
Create schema on update if it does not exist
Browse files Browse the repository at this point in the history
Makes the `cmgr update-schema` subcommand and cmgrd
`POST /schemas/{schema_name}` function like upserts
rather than updates. If the named schema does not
exist, a warning will be logged and the schema will
be created, rather than returning an error.

This allows clients to call `update-schema` without the
need to know whether a given schema has already been
created or not, without needing to handle nonexistent
schema errors and falling back to `add-schema`.
  • Loading branch information
dmartin committed Jan 30, 2024
1 parent 50de11d commit ca62a57
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmgr/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ func (m *Manager) UpdateSchema(schema *Schema) []error {
if err != nil {
return []error{err}
} else if !exists {
return []error{fmt.Errorf("schema '%s' does not exist", schema.Name)}
m.log.warnf("schema '%s' does not exist, creating...", schema.Name)
return m.CreateSchema(schema)
}

return m.convergeSchema(schema)
Expand Down

0 comments on commit ca62a57

Please sign in to comment.