From 0c47980fe5db9a5d6a47d0f442ef89378645f50a Mon Sep 17 00:00:00 2001 From: ko_oler <kooler89@gmail.com> Date: Mon, 10 Jul 2023 18:58:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=82=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=B2=20UpdateCollectionFn=20?= =?UTF-8?q?=D0=B8=20DeleteCollectionFn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/setup/collection.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/setup/collection.go b/pkg/setup/collection.go index d61ba14d..17011372 100644 --- a/pkg/setup/collection.go +++ b/pkg/setup/collection.go @@ -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 } -- GitLab