diff --git a/pkg/setup/collection.go b/pkg/setup/collection.go index 170113726de4cd26d73d063592ae60477ad427dd..4dca0192d86957c976e5a2d9201234a79673aa40 100644 --- a/pkg/setup/collection.go +++ b/pkg/setup/collection.go @@ -80,6 +80,22 @@ func UpdateExistingCollection() CollectionsOption { } } +func UpdateCollectionSchemaMetadata() CollectionsOption { + return func(c *CollectionConfig) { + c.UpdateFn = func(s *Setup, exist, new *collections.Collection) (coll *collections.Collection, upd bool, setSchema bool, err error) { + if !new.IsView() && !exist.IsView() { + if new.Schema.Metadata != nil && exist.Schema.Metadata == nil && !s.IsForce() { + return nil, false, false, collections.ErrAlreadyExists + } + if new.Schema.Metadata != nil && exist.Schema.Metadata != nil { + return new, true, true, nil + } + } + return new, true, true, nil + } + } +} + func (s *Setup) InstallCollections(ctx context.Context) (err error) { if len(s.Collections) == 0 { return nil @@ -133,13 +149,16 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS if exist == nil { setSchema = !collection.IsView() - exist, err = s.content.Collections.Create(ctx, collection) + _, err = s.content.Collections.Create(ctx, collection) if err != nil { return false, err } } else { var upd bool collection, upd, setSchema, err = c.UpdateFn(s, exist, c.collection) + if err != nil { + return false, err + } if upd { if err = s.content.Collections.Update(ctx, collection); err != nil { return false, err