Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Add commits lost during github outage #303

Merged
merged 2 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions client/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ type RelationType uint8

// Note: These values are serialized and persisted in the database, avoid modifying existing values
const (
Meta_Relation_ONE RelationType = 1 // 0b0000 0001
Meta_Relation_MANY RelationType = 2 // 0b0000 0010
Meta_Relation_ONEONE RelationType = 4 // 0b0000 0100
Meta_Relation_ONEMANY RelationType = 8 // 0b0000 1000
Meta_Relation_MANYMANY RelationType = 16 // 0b0001 0000
Relation_Type_ONE RelationType = 1 // 0b0000 0001
Relation_Type_MANY RelationType = 2 // 0b0000 0010
Relation_Type_ONEONE RelationType = 4 // 0b0000 0100
Relation_Type_ONEMANY RelationType = 8 // 0b0000 1000
Relation_Type_MANYMANY RelationType = 16 // 0b0001 0000
_ RelationType = 32 // 0b0010 0000
Meta_Relation_INTERNAL_ID RelationType = 64 // 0b0100 0000
Meta_Relation_Primary RelationType = 128 // 0b1000 0000 Primary reference entity on relation
Relation_Type_INTERNAL_ID RelationType = 64 // 0b0100 0000
Relation_Type_Primary RelationType = 128 // 0b1000 0000 Primary reference entity on relation
)

type FieldID uint32
Expand All @@ -158,7 +158,7 @@ type FieldDescription struct {
Schema string // If the field is an OBJECT type, then it has a target schema
RelationName string // The name of the relation index if the field is of type FOREIGN_OBJECT
Typ CType
Meta RelationType
RelationType RelationType
// @todo: Add relation name for specifying target relation index
// @body: If a type has two User sub objects, you need to specify the relation
// name used. By default the relation name is "rootType_subType". However,
Expand Down
8 changes: 4 additions & 4 deletions db/fetcher/versioned_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
"verified": true
}`),
// cid: "Qmcv2iU3myUBwuFCHe3w97sBMMER2FTY2rpbNBP6cqWb4S",
cid: "bafybeig4fwvzsiwb3jk3okr4goibmgjt2m2to3duyfy5ejldpxtgq5hdo4",
cid: "bafybeiatx2n4cswlg35oju2i7ghft2yew4b3q2bm2lingouosoxvh4hej4",
},
{
payload: []byte(`{
Expand All @@ -56,7 +56,7 @@ var (
"points": 99.9,
},
// cid: "QmPgnQvhPuLGwVU4ZEcbRy7RNCxSkeS72eKwXusUrAEEXR",
cid: "bafybeienkr6hj73uwd5vhxehavbu26mkk4tv4yd4xefjsa2xy5wlafpls4",
cid: "bafybeibdmpnxzau7rqpvgoim7saesuvwlqyyjwl2us2zftybsz5u5vd2t4",
},
{
payload: []byte(`{
Expand All @@ -70,7 +70,7 @@ var (
"age": 22,
},
// cid: "QmRpMfTzExGrXat5W9uCAEtnSpRTvWBcd1hBYNWVPdN9Xh",
cid: "bafybeif24w2yjzkb45kywubghcj2pacrfwjjolqq3k3qyiciclvoxcycxe",
cid: "bafybeiccqlxez5pn62nnoqccl62p2a4lpafzlqgp4mwmg24iroppo5d6mq",
},
{
payload: []byte(`{
Expand All @@ -83,7 +83,7 @@ var (
"points": 129.99,
},
// cid: "QmRWYwKadjWqHLrzPKd7MdS4EoQuT2RzWVTaBxxVkeSjFH",
cid: "bafybeiasb5jvqygubz54bp2c7wryj643osthoqgzismc6p53wriq3bpubq",
cid: "bafybeieiucuh63h4445ydiz4ugos7x5ri6f25hrflrnrs5uyq3ncme3frm",
},
}
)
Expand Down
6 changes: 3 additions & 3 deletions db/tests/query/all_commits/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestQueryAllCommitsSingleDAG(t *testing.T) {
},
Results: []map[string]interface{}{
{
"cid": "bafybeiatyttzyajjsw5lshkz6unhei6k4mr3rcmapmooeamkeamx72cuny",
"cid": "bafybeiezoa54vxdfjwjedj6rerglndsnvmbxvs3kcxosvfqaybe5ro3jfi",
"links": []map[string]interface{}{
{
"cid": "bafybeiftyjqxyzqtfpi65kde4hla4xm3v4dvtr7fr2p2p5ng5lfg7rrcve",
Expand Down Expand Up @@ -79,11 +79,11 @@ func TestQueryAllCommitsMultipleDAG(t *testing.T) {
},
Results: []map[string]interface{}{
{
"cid": "bafybeic5hchq265qztlr3n6265v22aj5jvdsxcm2w4f2yk3tnv5gktyhza",
"cid": "bafybeicvntqdbovqdkcrutdrtfcajtpkvsgqslym243p62lconez2bf3ai",
"height": int64(2),
},
{
"cid": "bafybeiatyttzyajjsw5lshkz6unhei6k4mr3rcmapmooeamkeamx72cuny",
"cid": "bafybeiezoa54vxdfjwjedj6rerglndsnvmbxvs3kcxosvfqaybe5ro3jfi",
"height": int64(1),
},
},
Expand Down
2 changes: 1 addition & 1 deletion db/tests/query/all_commits/with_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestQueryAllCommitsSingleDAGWithLinkCount(t *testing.T) {
},
Results: []map[string]interface{}{
{
"cid": "bafybeiatyttzyajjsw5lshkz6unhei6k4mr3rcmapmooeamkeamx72cuny",
"cid": "bafybeiezoa54vxdfjwjedj6rerglndsnvmbxvs3kcxosvfqaybe5ro3jfi",
"_count": 2,
},
},
Expand Down
4 changes: 2 additions & 2 deletions db/tests/query/commit/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestQueryOneCommit(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "query for a single block by CID",
Query: `query {
commit(cid: "bafkreiatyttzyajjsw5lshkz6unhei6k4mr3rcmapmooeamkeamx72cuny") {
commit(cid: "bafybeiezoa54vxdfjwjedj6rerglndsnvmbxvs3kcxosvfqaybe5ro3jfi") {
cid
height
delta
Expand All @@ -35,7 +35,7 @@ func TestQueryOneCommit(t *testing.T) {
},
Results: []map[string]interface{}{
{
"cid": "bafkreiatyttzyajjsw5lshkz6unhei6k4mr3rcmapmooeamkeamx72cuny",
"cid": "bafybeiezoa54vxdfjwjedj6rerglndsnvmbxvs3kcxosvfqaybe5ro3jfi",
"height": int64(1),
// cbor encoded delta
"delta": []uint8{0xa2, 0x63, 0x41, 0x67, 0x65, 0x15, 0x64, 0x4e, 0x61, 0x6d, 0x65, 0x64, 0x4a, 0x6f, 0x68, 0x6e},
Expand Down
2 changes: 1 addition & 1 deletion db/tests/query/latest_commits/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestQueryLatestCommits(t *testing.T) {
},
Results: []map[string]interface{}{
{
"cid": "bafybeiatyttzyajjsw5lshkz6unhei6k4mr3rcmapmooeamkeamx72cuny",
"cid": "bafybeiezoa54vxdfjwjedj6rerglndsnvmbxvs3kcxosvfqaybe5ro3jfi",
"links": []map[string]interface{}{
{
"cid": "bafybeiftyjqxyzqtfpi65kde4hla4xm3v4dvtr7fr2p2p5ng5lfg7rrcve",
Expand Down
2 changes: 1 addition & 1 deletion db/tests/query/simple/with_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestQuerySimpleWithEmbeddedLatestCommit(t *testing.T) {
"Age": uint64(21),
"_version": []map[string]interface{}{
{
"cid": "bafybeibbpmufrnx2zyl66xcxcas25ztyihtkguhtaevyqt72syvplooube",
"cid": "bafybeiewn6dvdwu436khe7okcsihjcxuijvskae7zh52cyyrytuhwr34oq",
"links": []map[string]interface{}{
{
"cid": "bafybeiftyjqxyzqtfpi65kde4hla4xm3v4dvtr7fr2p2p5ng5lfg7rrcve",
Expand Down
3 changes: 3 additions & 0 deletions docs/data_format_changes/i200-mv-descriptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Public interface cleanup

FieldDescription.Meta was renamed to FieldDescription.RelationType, FieldDescription is serialized and thus the renaming alters the Cids outputted.
4 changes: 2 additions & 2 deletions query/graphql/planner/type_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (p *Planner) makeTypeIndexJoin(parent *selectNode, source planNode, subType
return nil, fmt.Errorf("Unknown field %s on sub selection", subType.Name)
}

meta := typeFieldDesc.Meta
meta := typeFieldDesc.RelationType
if schema.IsOne(meta) { // One-to-One, or One side of One-to-Many
joinPlan, err = p.makeTypeJoinOne(parent, source, subType)
} else if schema.IsOneToMany(meta) { // Many side of One-to-Many
Expand Down Expand Up @@ -357,7 +357,7 @@ func (p *Planner) makeTypeJoinOne(parent *selectNode, source planNode, subType *

// determine relation direction (primary or secondary?)
// check if the field we're querying is the primary side of the relation
if subTypeFieldDesc.Meta&client.Meta_Relation_Primary > 0 {
if subTypeFieldDesc.RelationType&client.Relation_Type_Primary > 0 {
typeJoin.primary = true
} else {
typeJoin.primary = false
Expand Down
12 changes: 6 additions & 6 deletions query/graphql/schema/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (g *Generator) CreateDescriptions(types []*gql.Object) ([]client.Collection
return nil, errors.New("Relation is missing field")
}

fd.Meta = rel.Kind() | fieldRelationType
fd.RelationType = rel.Kind() | fieldRelationType

// handle object id field, defined as {{object_name}}_id
// with type gql.ID
Expand All @@ -190,9 +190,9 @@ func (g *Generator) CreateDescriptions(types []*gql.Object) ([]client.Collection

// create field
fdRelated := client.FieldDescription{
Name: fmt.Sprintf("%s_id", fname),
Kind: gqlTypeToFieldKind(gql.ID),
Meta: client.Meta_Relation_INTERNAL_ID,
Name: fmt.Sprintf("%s_id", fname),
Kind: gqlTypeToFieldKind(gql.ID),
RelationType: client.Relation_Type_INTERNAL_ID,
}
fdRelated.Typ = defaultCRDTForFieldKind[fdRelated.Kind]
desc.Schema.Fields = append(desc.Schema.Fields, fdRelated)
Expand Down Expand Up @@ -272,7 +272,7 @@ return client.CollectionDescription{
Kind: base.FieldKind_FOREIGN_OBJECT,
Schema: "author",
Typ: client.NONE_CRDT,
Meta: base.Meta_Relation_ONE | base.Meta_Relation_Primary,
Meta: base.Relation_Type_ONE | base.Relation_Type_Primary,
},
client.FieldDescription{
Name: "author_id",
Expand Down Expand Up @@ -329,7 +329,7 @@ return client.CollectionDescription{
Kind: base.FieldKind_FOREIGN_OBJECT_ARRAY,
Schema: "book",
Typ: client.NONE_CRDT,
Meta: base.Meta_Relation_ONEMANY,
Meta: base.Relation_Type_ONEMANY,
},
},
},
Expand Down
32 changes: 16 additions & 16 deletions query/graphql/schema/descriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ func TestSingleSimpleType(t *testing.T) {
Kind: client.FieldKind_FOREIGN_OBJECT,
Typ: client.NONE_CRDT,
Schema: "author",
Meta: client.Meta_Relation_ONE | client.Meta_Relation_ONEONE,
RelationType: client.Relation_Type_ONE | client.Relation_Type_ONEONE,
},
{
Name: "author_id",
Kind: client.FieldKind_DocKey,
Typ: client.LWW_REGISTER,
Meta: client.Meta_Relation_INTERNAL_ID,
Name: "author_id",
Kind: client.FieldKind_DocKey,
Typ: client.LWW_REGISTER,
RelationType: client.Relation_Type_INTERNAL_ID,
},
{
Name: "name",
Expand Down Expand Up @@ -227,13 +227,13 @@ func TestSingleSimpleType(t *testing.T) {
Kind: client.FieldKind_FOREIGN_OBJECT,
Typ: client.NONE_CRDT,
Schema: "book",
Meta: client.Meta_Relation_ONE | client.Meta_Relation_ONEONE | client.Meta_Relation_Primary,
RelationType: client.Relation_Type_ONE | client.Relation_Type_ONEONE | client.Relation_Type_Primary,
},
{
Name: "published_id",
Kind: client.FieldKind_DocKey,
Typ: client.LWW_REGISTER,
Meta: client.Meta_Relation_INTERNAL_ID,
Name: "published_id",
Kind: client.FieldKind_DocKey,
Typ: client.LWW_REGISTER,
RelationType: client.Relation_Type_INTERNAL_ID,
},
},
},
Expand Down Expand Up @@ -273,13 +273,13 @@ func TestSingleSimpleType(t *testing.T) {
Kind: client.FieldKind_FOREIGN_OBJECT,
Typ: client.NONE_CRDT,
Schema: "author",
Meta: client.Meta_Relation_ONE | client.Meta_Relation_ONEMANY | client.Meta_Relation_Primary,
RelationType: client.Relation_Type_ONE | client.Relation_Type_ONEMANY | client.Relation_Type_Primary,
},
{
Name: "author_id",
Kind: client.FieldKind_DocKey,
Typ: client.LWW_REGISTER,
Meta: client.Meta_Relation_INTERNAL_ID,
Name: "author_id",
Kind: client.FieldKind_DocKey,
Typ: client.LWW_REGISTER,
RelationType: client.Relation_Type_INTERNAL_ID,
},
{
Name: "name",
Expand Down Expand Up @@ -321,7 +321,7 @@ func TestSingleSimpleType(t *testing.T) {
Kind: client.FieldKind_FOREIGN_OBJECT_ARRAY,
Typ: client.NONE_CRDT,
Schema: "book",
Meta: client.Meta_Relation_MANY | client.Meta_Relation_ONEMANY,
RelationType: client.Relation_Type_MANY | client.Relation_Type_ONEMANY,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions query/graphql/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (g *Generator) buildTypesFromAST(ctx context.Context, document *ast.Documen
return nil, err
}

_, err = g.manager.Relations.RegisterSingle(relName, ttype.Name(), fType.Name, client.Meta_Relation_ONE)
_, err = g.manager.Relations.RegisterSingle(relName, ttype.Name(), fType.Name, client.Relation_Type_ONE)
if err != nil {
log.ErrorE(ctx, "Error while registering single relation", err)
}
Expand All @@ -372,7 +372,7 @@ func (g *Generator) buildTypesFromAST(ctx context.Context, document *ast.Documen
return nil, err
}

_, err = g.manager.Relations.RegisterSingle(relName, ltype.Name(), fType.Name, client.Meta_Relation_MANY)
_, err = g.manager.Relations.RegisterSingle(relName, ltype.Name(), fType.Name, client.Relation_Type_MANY)
if err != nil {
log.ErrorE(ctx, "Error while registering single relation", err)
}
Expand Down
Loading