Skip to content

Commit ca62a57

Browse files
committed
Create schema on update if it does not exist
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`.
1 parent 50de11d commit ca62a57

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

cmgr/api.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ func (m *Manager) UpdateSchema(schema *Schema) []error {
350350
if err != nil {
351351
return []error{err}
352352
} else if !exists {
353-
return []error{fmt.Errorf("schema '%s' does not exist", schema.Name)}
353+
m.log.warnf("schema '%s' does not exist, creating...", schema.Name)
354+
return m.CreateSchema(schema)
354355
}
355356

356357
return m.convergeSchema(schema)

0 commit comments

Comments
 (0)