Skip to content
Snippets Groups Projects
Commit 2530aea7 authored by ko_oler's avatar ko_oler
Browse files

правки по ПР

parent 868c35fe
Branches
Tags
No related merge requests found
...@@ -39,7 +39,7 @@ type Content struct { ...@@ -39,7 +39,7 @@ type Content struct {
} }
const ( const (
DBVersion uint32 = 3 DBVersion uint32 = 2
) )
func (c *Content) RegisterStart(svc interface{}) { func (c *Content) RegisterStart(svc interface{}) {
......
...@@ -138,22 +138,22 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -138,22 +138,22 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
return false, err return false, err
} }
if c.metadata != nil {
collection.Schema.WithMetadata(c.metadata...)
}
if exist == nil { if exist == nil {
setSchema = !collection.IsView() setSchema = !collection.IsView()
exist, err = s.content.Collections.Create(ctx, collection) _, err = s.content.Collections.Create(ctx, collection)
if err != nil { if err != nil {
return false, err return false, err
} }
} else { } else {
var upd bool if collection.Schema.Metadata != nil && exist.Schema.Metadata["extension"] != collection.Schema.Metadata["extension"] && !s.IsForce() {
if c.metadata != nil { 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")
collection.Schema.WithMetadata(c.metadata...)
err = s.checkSchemaMetadata(collection, exist)
if err != nil {
return false, err
}
} }
var upd bool
collection, upd, setSchema = c.UpdateFn(s, exist, c.collection) collection, upd, setSchema = c.UpdateFn(s, exist, c.collection)
if upd { if upd {
if err = s.content.Collections.Update(ctx, collection); err != nil { if err = s.content.Collections.Update(ctx, collection); err != nil {
...@@ -172,16 +172,6 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -172,16 +172,6 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
return setSchema, nil 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 { func (s *Setup) CheckCollections(ctx context.Context) error {
if len(s.Collections) == 0 { if len(s.Collections) == 0 {
return nil return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment