From 79c844e3ceeb04d4d711e8f0232f2be5970928c0 Mon Sep 17 00:00:00 2001 From: ko_oler <kooler89@gmail.com> Date: Mon, 10 Jul 2023 21:46:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81=20fu?= =?UTF-8?q?nc=20UpdateCollectionSchemaMetadata()=20=D0=B2=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BA=D0=B5=D1=82=20extension?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/extension/extension.go | 18 ++++++++++++++++++ pkg/setup/collection.go | 16 ---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pkg/extension/extension.go b/pkg/extension/extension.go index fb8044c7..5e31c700 100644 --- a/pkg/extension/extension.go +++ b/pkg/extension/extension.go @@ -4,9 +4,11 @@ import ( "context" "fmt" + "git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/content" "git.perx.ru/perxis/perxis-go/pkg/errors" "git.perx.ru/perxis/perxis-go/pkg/items" + "git.perx.ru/perxis/perxis-go/pkg/setup" pb "git.perx.ru/perxis/perxis-go/proto/extensions" ) @@ -105,3 +107,19 @@ func ExtensionFromError(err error) string { ext, _ := v.(string) return ext } + +func UpdateCollectionSchemaMetadata() setup.CollectionsOption { + return func(c *setup.CollectionConfig) { + c.UpdateFn = func(s *setup.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 + } + } +} diff --git a/pkg/setup/collection.go b/pkg/setup/collection.go index 4dca0192..f80e0827 100644 --- a/pkg/setup/collection.go +++ b/pkg/setup/collection.go @@ -80,22 +80,6 @@ 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) { if len(s.Collections) == 0 { return nil -- GitLab