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

правки по ПР

parent 868c35fe
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,7 @@ type Content struct {
}
const (
DBVersion uint32 = 3
DBVersion uint32 = 2
)
func (c *Content) RegisterStart(svc interface{}) {
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment