Skip to content
Snippets Groups Projects
Commit 0c47980f authored by ko_oler's avatar ko_oler
Browse files

добавлен возврат ошибки в UpdateCollectionFn и DeleteCollectionFn

parent 1348750e
No related branches found
No related tags found
No related merge requests found
......@@ -18,8 +18,8 @@ var (
)
type CollectionsOption func(c *CollectionConfig)
type UpdateCollectionFn func(s *Setup, exist, new *collections.Collection) (coll *collections.Collection, upd bool, setSchema bool)
type DeleteCollectionFn func(s *Setup, col *collections.Collection) bool
type UpdateCollectionFn func(s *Setup, exist, new *collections.Collection) (coll *collections.Collection, upd bool, setSchema bool, err error)
type DeleteCollectionFn func(s *Setup, col *collections.Collection) (bool, error)
type CollectionConfig struct {
collection *collections.Collection
......@@ -42,40 +42,40 @@ func NewCollectionConfig(collection *collections.Collection, opt ...CollectionsO
func OverwriteCollection() CollectionsOption {
return func(c *CollectionConfig) {
c.UpdateFn = func(s *Setup, old, new *collections.Collection) (*collections.Collection, bool, bool) {
return new, true, true
c.UpdateFn = func(s *Setup, old, new *collections.Collection) (*collections.Collection, bool, bool, error) {
return new, true, true, nil
}
}
}
func KeepExistingCollection() CollectionsOption {
return func(c *CollectionConfig) {
c.UpdateFn = func(s *Setup, old, new *collections.Collection) (*collections.Collection, bool, bool) {
return old, false, false
c.UpdateFn = func(s *Setup, old, new *collections.Collection) (*collections.Collection, bool, bool, error) {
return old, false, false, nil
}
}
}
func DeleteCollection() CollectionsOption {
return func(c *CollectionConfig) {
c.DeleteFn = func(s *Setup, collection *collections.Collection) bool { return true }
c.DeleteFn = func(s *Setup, collection *collections.Collection) (bool, error) { return true, nil }
}
}
func DeleteCollectionIfRemove() CollectionsOption {
return func(c *CollectionConfig) {
c.DeleteFn = func(s *Setup, collection *collections.Collection) bool { return s.IsRemove() }
c.DeleteFn = func(s *Setup, collection *collections.Collection) (bool, error) { return s.IsRemove(), nil }
}
}
func UpdateExistingCollection() CollectionsOption {
return func(c *CollectionConfig) {
c.UpdateFn = func(s *Setup, exist, collection *collections.Collection) (*collections.Collection, bool, bool) {
c.UpdateFn = func(s *Setup, exist, collection *collections.Collection) (*collections.Collection, bool, bool, error) {
if len(exist.Tags) > 0 {
collection.Tags = append(exist.Tags, collection.Tags...)
}
return collection, true, !collection.IsView() && !reflect.DeepEqual(exist.Schema, collection.Schema)
return collection, true, !collection.IsView() && !reflect.DeepEqual(exist.Schema, collection.Schema), nil
}
}
}
......@@ -139,7 +139,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
}
} else {
var upd bool
collection, upd, setSchema = c.UpdateFn(s, exist, c.collection)
collection, upd, setSchema, err = c.UpdateFn(s, exist, c.collection)
if upd {
if err = s.content.Collections.Update(ctx, collection); err != nil {
return false, err
......@@ -205,7 +205,7 @@ func (s *Setup) UninstallCollections(ctx context.Context) error {
}
func (s *Setup) UninstallCollection(ctx context.Context, c CollectionConfig) error {
if c.DeleteFn(s, c.collection) {
if ok, _ := c.DeleteFn(s, c.collection); ok {
if err := s.content.Collections.Delete(ctx, s.SpaceID, s.EnvironmentID, c.collection.ID); err != nil && !strings.Contains(err.Error(), collections.ErrNotFound.Error()) {
return err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment