1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-11 02:13:41 +09:00

Relations rework and migration p1

- store relations within the workspace as subobjects (like options)
- RelationLink: remove Id, add Format
- do the reinterpretation of old relation changes to add relationLink
- add workspace _anytype_marketplace to the bundled relations/objectTypes
This commit is contained in:
Roman Khafizianov 2022-10-04 23:56:07 +02:00
parent c79fc28166
commit 21f2093e52
No known key found for this signature in database
GPG key ID: F07A7D55A2684852
38 changed files with 5128 additions and 5071 deletions

View file

@ -12,6 +12,7 @@ import (
"github.com/anytypeio/go-anytype-middleware/core/block/simple/link"
"github.com/anytypeio/go-anytype-middleware/core/block/simple/text"
relation2 "github.com/anytypeio/go-anytype-middleware/core/relation"
"github.com/anytypeio/go-anytype-middleware/core/relation/relationutils"
"github.com/gogo/protobuf/types"
"github.com/textileio/go-threads/core/thread"
"io"
@ -159,10 +160,7 @@ func (b *builtinObjects) createObject(ctx context.Context, rd io.ReadCloser) (er
f["analyticsOriginalId"] = pbtypes.String(oldId)
st.Set(simple.New(m))
rels, err := b.relService.MigrateRelations(st.OldExtraRelations())
if err != nil {
return err
}
rels := relationutils.MigrateRelationsModels(st.OldExtraRelations())
st.AddRelationLinks(rels...)
st.RemoveDetail(bundle.RelationKeyCreator.String(), bundle.RelationKeyLastModifiedBy.String())

View file

@ -4,9 +4,9 @@ import "github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
type RelationLinks []*model.RelationLink
func (rl RelationLinks) Has(id string) bool {
func (rl RelationLinks) Has(key string) bool {
for _, l := range rl {
if l.Id == id {
if l.Key == key {
return true
}
}
@ -15,7 +15,7 @@ func (rl RelationLinks) Has(id string) bool {
func (rl RelationLinks) Key(id string) (key string, ok bool) {
for _, l := range rl {
if l.Id == id {
if l.Key == id {
return l.Key, true
}
}
@ -29,7 +29,7 @@ func (rl RelationLinks) Append(l *model.RelationLink) RelationLinks {
func (rl RelationLinks) Remove(id string) RelationLinks {
var n int
for _, x := range rl {
if x.Id != id {
if x.Key != id {
rl[n] = x
n++
}
@ -41,8 +41,8 @@ func (rl RelationLinks) Copy() RelationLinks {
res := make(RelationLinks, 0, len(rl))
for _, l := range rl {
res = append(res, &model.RelationLink{
Id: l.Id,
Key: l.Key,
Format: l.Format,
Key: l.Key,
})
}
return res
@ -51,15 +51,15 @@ func (rl RelationLinks) Copy() RelationLinks {
func (rl RelationLinks) Diff(prev RelationLinks) (added []*model.RelationLink, removed []string) {
var common = make(map[string]struct{})
for _, l := range rl {
if !prev.Has(l.Id) {
if !prev.Has(l.Key) {
added = append(added, l)
} else {
common[l.Id] = struct{}{}
common[l.Key] = struct{}{}
}
}
for _, l := range prev {
if _, ok := common[l.Id]; !ok {
removed = append(removed, l.Id)
if _, ok := common[l.Key]; !ok {
removed = append(removed, l.Key)
}
}
return