From 2530aea7fcebd3084293e8cddd22a9580cdee8a0 Mon Sep 17 00:00:00 2001 From: ko_oler <kooler89@gmail.com> Date: Wed, 5 Jul 2023 14:07:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=9F=D0=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/content/content.go | 2 +- pkg/setup/collection.go | 26 ++++++++------------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/pkg/content/content.go b/pkg/content/content.go index 29abfb45..1d351e93 100644 --- a/pkg/content/content.go +++ b/pkg/content/content.go @@ -39,7 +39,7 @@ type Content struct { } const ( - DBVersion uint32 = 3 + DBVersion uint32 = 2 ) func (c *Content) RegisterStart(svc interface{}) { diff --git a/pkg/setup/collection.go b/pkg/setup/collection.go index bd8bea92..a2922a0d 100644 --- a/pkg/setup/collection.go +++ b/pkg/setup/collection.go @@ -138,22 +138,22 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS return false, err } + if c.metadata != nil { + collection.Schema.WithMetadata(c.metadata...) + } + 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 - if c.metadata != nil { - collection.Schema.WithMetadata(c.metadata...) - err = s.checkSchemaMetadata(collection, exist) - if err != nil { - return false, err - } + if collection.Schema.Metadata != nil && exist.Schema.Metadata["extension"] != collection.Schema.Metadata["extension"] && !s.IsForce() { + return false, errors.Wrap(errors.Errorf("collection %s has the same id(%s) as extension's collection %s", exist.Name, exist.ID, collection.Name), "fail to update collection") } + var upd bool collection, upd, setSchema = c.UpdateFn(s, exist, c.collection) if upd { if err = s.content.Collections.Update(ctx, collection); err != nil { @@ -172,16 +172,6 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS return setSchema, nil } -// checkSchemaMetadata проверяет изменилось ли значение Metadata в схеме коллекции -func (s *Setup) checkSchemaMetadata(collection *collections.Collection, exist *collections.Collection) error { - if collection.Schema.Metadata != nil { - if exist.Schema.Metadata["extension"] != collection.Schema.Metadata["extension"] && !s.IsForce() { - return errors.WithHint(errors.New("fail to update collection"), "collection has the same id as extension's collection, change yours collection id") - } - } - return nil -} - func (s *Setup) CheckCollections(ctx context.Context) error { if len(s.Collections) == 0 { return nil -- GitLab