diff --git a/pkg/setup/collection.go b/pkg/setup/collection.go index d61ba14d18f2d8bc93d2a535392b8b608ba6e2d0..170113726de4cd26d73d063592ae60477ad427dd 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 }