Skip to content
Snippets Groups Projects
Commit 6d7fc0fd authored by ko_oler's avatar ko_oler
Browse files

добавлена функция UpdateCollectionSchemaMetadata()

parent 0c47980f
No related branches found
No related tags found
No related merge requests found
...@@ -80,6 +80,22 @@ func UpdateExistingCollection() CollectionsOption { ...@@ -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) { func (s *Setup) InstallCollections(ctx context.Context) (err error) {
if len(s.Collections) == 0 { if len(s.Collections) == 0 {
return nil return nil
...@@ -133,13 +149,16 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -133,13 +149,16 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
if exist == nil { if exist == nil {
setSchema = !collection.IsView() setSchema = !collection.IsView()
exist, err = s.content.Collections.Create(ctx, collection) _, err = s.content.Collections.Create(ctx, collection)
if err != nil { if err != nil {
return false, err return false, err
} }
} else { } else {
var upd bool var upd bool
collection, upd, setSchema, err = c.UpdateFn(s, exist, c.collection) collection, upd, setSchema, err = c.UpdateFn(s, exist, c.collection)
if err != nil {
return false, err
}
if upd { if upd {
if err = s.content.Collections.Update(ctx, collection); err != nil { if err = s.content.Collections.Update(ctx, collection); err != nil {
return false, err return false, err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment