From 32d9cecf2ea6f187c8ebf318377fec3460cf2e0e Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Tue, 2 Apr 2024 15:00:43 -0400 Subject: [PATCH 01/11] Extract parsing of FieldKind to private func We'll need to call this somewhere else soon too. --- client/schema_field_description.go | 62 ++++++++++++++++-------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/client/schema_field_description.go b/client/schema_field_description.go index 7f945e3ab8..0e9fabc03b 100644 --- a/client/schema_field_description.go +++ b/client/schema_field_description.go @@ -304,50 +304,54 @@ func (f *SchemaFieldDescription) UnmarshalJSON(bytes []byte) error { f.RelationName = descMap.RelationName f.Typ = descMap.Typ f.IsPrimaryRelation = descMap.IsPrimaryRelation + f.Kind, err = parseFieldKind(descMap.Kind) + if err != nil { + return err + } + + return nil +} - if len(descMap.Kind) == 0 { - f.Kind = FieldKind_None - return nil +func parseFieldKind(bytes json.RawMessage) (FieldKind, error) { + if len(bytes) == 0 { + return FieldKind_None, nil } - if descMap.Kind[0] != '"' { + if bytes[0] != '"' { // If the Kind is not represented by a string, assume try to parse it to an int, as // that is the only other type we support. var intKind uint8 - err := json.Unmarshal(descMap.Kind, &intKind) + err := json.Unmarshal(bytes, &intKind) if err != nil { - return err + return nil, err } switch intKind { case uint8(FieldKind_BOOL_ARRAY), uint8(FieldKind_INT_ARRAY), uint8(FieldKind_FLOAT_ARRAY), uint8(FieldKind_STRING_ARRAY), uint8(FieldKind_NILLABLE_BOOL_ARRAY), uint8(FieldKind_NILLABLE_INT_ARRAY), uint8(FieldKind_NILLABLE_FLOAT_ARRAY), uint8(FieldKind_NILLABLE_STRING_ARRAY): - f.Kind = ScalarArrayKind(intKind) + return ScalarArrayKind(intKind), nil default: - f.Kind = ScalarKind(intKind) - } - } else { - var strKind string - err := json.Unmarshal(descMap.Kind, &strKind) - if err != nil { - return err + return ScalarKind(intKind), nil } + } - kind, ok := FieldKindStringToEnumMapping[strKind] - if ok { - f.Kind = kind - } else { - // If we don't find the string representation of this type in the - // scalar mapping, assume it is an object - if it is not, validation - // will catch this later. If it is unknown we have no way of telling - // as to whether the user thought it was a scalar or an object anyway. - if strKind[0] == '[' { - f.Kind = ObjectArrayKind(strings.Trim(strKind, "[]")) - } else { - f.Kind = ObjectKind(strKind) - } - } + var strKind string + err := json.Unmarshal(bytes, &strKind) + if err != nil { + return nil, err } - return nil + kind, ok := FieldKindStringToEnumMapping[strKind] + if ok { + return kind, nil + } + + // If we don't find the string representation of this type in the + // scalar mapping, assume it is an object - if it is not, validation + // will catch this later. If it is unknown we have no way of telling + // as to whether the user thought it was a scalar or an object anyway. + if strKind[0] == '[' { + return ObjectArrayKind(strings.Trim(strKind, "[]")), nil + } + return ObjectKind(strKind), nil } From 819c1cc21f568fdc70b0277297c51bf795d9dfd3 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Fri, 12 Apr 2024 11:56:38 -0400 Subject: [PATCH 02/11] Remove duplicate error message Is really not worth having two slightly different messages for the same thing --- client/document.go | 2 +- client/errors.go | 6 ------ .../update/field_kinds/one_to_many/with_alias_test.go | 4 ++-- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/client/document.go b/client/document.go index 531ccd42cd..3631bb1906 100644 --- a/client/document.go +++ b/client/document.go @@ -187,7 +187,7 @@ func validateFieldSchema(val any, field SchemaFieldDescription) (NormalValue, er } if field.Kind.IsObjectArray() { - return nil, NewErrFieldOrAliasToFieldNotExist(field.Name) + return nil, NewErrFieldNotExist(field.Name) } if field.Kind.IsObject() { diff --git a/client/errors.go b/client/errors.go index dbc29ed78b..c9f7fa0b39 100644 --- a/client/errors.go +++ b/client/errors.go @@ -24,7 +24,6 @@ const ( errMaxTxnRetries string = "reached maximum transaction reties" errRelationOneSided string = "relation must be defined on both schemas" errCollectionNotFound string = "collection not found" - errFieldOrAliasToFieldNotExist string = "The given field or alias to field does not exist" errUnknownCRDT string = "unknown crdt" errCRDTKindMismatch string = "CRDT type %s can't be assigned to field kind %s" errInvalidCRDTType string = "CRDT type not supported" @@ -161,11 +160,6 @@ func NewErrUnknownCRDT(cType CType) error { ) } -// NewErrFieldOrAliasToFieldNotExist returns an error indicating that the given field or an alias field does not exist. -func NewErrFieldOrAliasToFieldNotExist(name string) error { - return errors.New(errFieldOrAliasToFieldNotExist, errors.NewKV("Name", name)) -} - func NewErrInvalidCRDTType(name, crdtType string) error { return errors.New( errInvalidCRDTType, diff --git a/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go b/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go index 751ca67b78..d3df327de2 100644 --- a/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go +++ b/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go @@ -65,7 +65,7 @@ func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromSingleSide_Collectio }`, bookID, ), - ExpectedError: "The given field or alias to field does not exist. Name: published", + ExpectedError: "The given field does not exist. Name: published", }, }, } @@ -118,7 +118,7 @@ func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromSingleSide_GQL(t *te }`, bookID, ), - ExpectedError: "The given field or alias to field does not exist. Name: published", + ExpectedError: "The given field does not exist. Name: published", }, }, } From f917253121983f70ff6cce35afc5b526ab35431f Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Fri, 12 Apr 2024 16:23:27 -0400 Subject: [PATCH 03/11] Resolve sec. mapping using ColDef Soon, secondary fields will not exist on the schema --- planner/mapper/mapper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planner/mapper/mapper.go b/planner/mapper/mapper.go index 17b7f86611..a73b24f9c3 100644 --- a/planner/mapper/mapper.go +++ b/planner/mapper/mapper.go @@ -125,7 +125,7 @@ func toSelect( store, rootSelectType, collectionName, - definition.Schema, + definition, mapping, fields, ) @@ -1079,7 +1079,7 @@ func resolveSecondaryRelationIDs( store client.Store, rootSelectType SelectionType, collectionName string, - schema client.SchemaDescription, + schema client.CollectionDefinition, mapping *core.DocumentMapping, requestables []Requestable, ) ([]Requestable, error) { From bfbfc6d44635f0ebc60a162f81e5339acc9f1a84 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Mon, 15 Apr 2024 15:36:19 -0400 Subject: [PATCH 04/11] Rename tryGetFieldID Old name was incorrect, as it gets the field ID (hosted on collection) from the collection definition, not the schema. Should have been changed a while ago --- db/collection.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/collection.go b/db/collection.go index 7b2305364a..67b32f2d09 100644 --- a/db/collection.go +++ b/db/collection.go @@ -1886,7 +1886,7 @@ func (c *collection) getDataStoreKeyFromDocID(docID client.DocID) core.DataStore } func (c *collection) tryGetFieldKey(primaryKey core.PrimaryDataStoreKey, fieldName string) (core.DataStoreKey, bool) { - fieldId, hasField := c.tryGetSchemaFieldID(fieldName) + fieldId, hasField := c.tryGetFieldID(fieldName) if !hasField { return core.DataStoreKey{}, false } @@ -1898,9 +1898,9 @@ func (c *collection) tryGetFieldKey(primaryKey core.PrimaryDataStoreKey, fieldNa }, true } -// tryGetSchemaFieldID returns the FieldID of the given fieldName. +// tryGetFieldID returns the FieldID of the given fieldName. // Will return false if the field is not found. -func (c *collection) tryGetSchemaFieldID(fieldName string) (uint32, bool) { +func (c *collection) tryGetFieldID(fieldName string) (uint32, bool) { for _, field := range c.Definition().GetFields() { if field.Name == fieldName { if field.Kind.IsObject() || field.Kind.IsObjectArray() { From 0cfaaf42465a11b74d7fcc6f65e5193015292088 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Mon, 15 Apr 2024 15:39:53 -0400 Subject: [PATCH 05/11] Determine relationshipness in mapper from Kind Not from relation name, which is no longer required for relations --- planner/mapper/mapper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/mapper/mapper.go b/planner/mapper/mapper.go index a73b24f9c3..af3542c403 100644 --- a/planner/mapper/mapper.go +++ b/planner/mapper/mapper.go @@ -774,7 +774,7 @@ func getCollectionName( } hostFieldDesc, parentHasField := parentCollection.Definition().GetFieldByName(selectRequest.Name) - if parentHasField && hostFieldDesc.RelationName != "" { + if parentHasField && hostFieldDesc.Kind.IsObject() { // If this field exists on the parent, and it is a child object // then this collection name is the collection name of the child. return hostFieldDesc.Kind.Underlying(), nil From f168c1cd5f448b03bc82e921bad1ad5aa9db666d Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Mon, 15 Apr 2024 15:40:03 -0400 Subject: [PATCH 06/11] Move relation field properties onto collection From schema. --- cli/collection_create.go | 4 +- client/collection_description.go | 11 +- client/collection_field_description.go | 51 +- client/definitions.go | 94 ++- client/document.go | 34 +- client/document_test.go | 32 +- client/errors.go | 18 - client/schema_field_description.go | 17 +- db/backup.go | 6 +- db/backup_test.go | 32 +- db/collection.go | 248 ++++-- db/collection_get.go | 2 +- db/collection_index.go | 2 +- db/collection_update.go | 6 +- db/errors.go | 44 +- db/fetcher/encoded_doc.go | 4 +- db/indexed_docs_test.go | 16 +- db/schema.go | 2 +- db/view.go | 2 +- http/client_collection.go | 2 +- http/handler_ccip_test.go | 2 +- http/handler_collection.go | 4 +- net/client_test.go | 30 +- net/dag_test.go | 6 +- net/peer_test.go | 18 +- net/server_test.go | 6 +- planner/create.go | 2 +- planner/type_join.go | 58 +- request/graphql/schema/collection.go | 302 +++++--- request/graphql/schema/descriptions_test.go | 335 ++++---- request/graphql/schema/errors.go | 24 +- request/graphql/schema/generate.go | 2 +- request/graphql/schema/relations.go | 165 ---- tests/bench/bench_util.go | 2 +- tests/bench/collection/utils.go | 6 +- tests/clients/cli/wrapper_collection.go | 2 +- tests/gen/gen_auto.go | 10 +- tests/gen/gen_auto_config.go | 9 +- tests/gen/gen_auto_configurator.go | 12 +- tests/gen/gen_auto_test.go | 74 +- .../update/simple/with_doc_id_test.go | 2 +- .../update/simple/with_doc_ids_test.go | 4 +- .../update/simple/with_filter_test.go | 2 +- tests/integration/collection/utils.go | 2 +- .../events/simple/with_create_test.go | 4 +- .../events/simple/with_delete_test.go | 2 +- .../events/simple/with_update_test.go | 4 +- tests/integration/events/utils.go | 2 +- .../explain/default/type_join_many_test.go | 4 +- .../explain/default/type_join_one_test.go | 8 +- .../explain/default/type_join_test.go | 8 +- .../explain/default/with_average_join_test.go | 8 +- .../explain/default/with_count_join_test.go | 8 +- .../explain/default/with_sum_join_test.go | 10 +- .../one_to_many/with_show_deleted_test.go | 4 +- tests/integration/net/order/tcp_test.go | 2 +- tests/integration/net/order/utils.go | 2 +- .../query/one_to_many/with_id_field_test.go | 41 +- .../one_to_one/with_clashing_id_field_test.go | 17 +- tests/integration/schema/one_one_test.go | 2 +- tests/integration/schema/relations_test.go | 40 +- tests/integration/schema/simple_test.go | 2 +- .../field/kind/foreign_object_array_test.go | 718 +----------------- .../add/field/kind/foreign_object_test.go | 326 +------- .../updates/remove/fields/simple_test.go | 29 - .../schema/updates/test/field/simple_test.go | 4 +- tests/integration/utils2.go | 6 +- .../view/one_to_many/simple_test.go | 45 +- tests/predefined/gen_predefined.go | 14 +- tests/predefined/gen_predefined_test.go | 44 +- tests/predefined/util_test.go | 12 +- 71 files changed, 1121 insertions(+), 1951 deletions(-) delete mode 100644 request/graphql/schema/relations.go diff --git a/cli/collection_create.go b/cli/collection_create.go index c61a286326..df7d8794b5 100644 --- a/cli/collection_create.go +++ b/cli/collection_create.go @@ -69,14 +69,14 @@ Example: create from stdin: } if client.IsJSONArray(docData) { - docs, err := client.NewDocsFromJSON(docData, col.Schema()) + docs, err := client.NewDocsFromJSON(docData, col.Definition()) if err != nil { return err } return col.CreateMany(cmd.Context(), docs) } - doc, err := client.NewDocFromJSON(docData, col.Schema()) + doc, err := client.NewDocFromJSON(docData, col.Definition()) if err != nil { return err } diff --git a/client/collection_description.go b/client/collection_description.go index 2db34ddb8b..200ec82a7e 100644 --- a/client/collection_description.go +++ b/client/collection_description.go @@ -136,16 +136,15 @@ func (col CollectionDescription) GetFieldByRelation( relationName string, otherCollectionName string, otherFieldName string, - schema *SchemaDescription, -) (SchemaFieldDescription, bool) { - for _, field := range schema.Fields { - if field.RelationName == relationName && +) (CollectionFieldDescription, bool) { + for _, field := range col.Fields { + if field.RelationName.Value() == relationName && !(col.Name.Value() == otherCollectionName && otherFieldName == field.Name) && - field.Kind != FieldKind_DocID { + field.Kind.Value() != FieldKind_DocID { return field, true } } - return SchemaFieldDescription{}, false + return CollectionFieldDescription{}, false } // QuerySources returns all the Sources of type [QuerySource] diff --git a/client/collection_field_description.go b/client/collection_field_description.go index 048cde24c0..98b012d641 100644 --- a/client/collection_field_description.go +++ b/client/collection_field_description.go @@ -10,7 +10,12 @@ package client -import "fmt" +import ( + "encoding/json" + "fmt" + + "github.com/sourcenetwork/immutable" +) // FieldID is a unique identifier for a field in a schema. type FieldID uint32 @@ -22,8 +27,52 @@ type CollectionFieldDescription struct { // ID contains the local, internal ID of this field. ID FieldID + + // Kind contains the local field kind if this is a local-only field (e.g. the secondary + // side of a relation). + // + // If the field is globaly defined (on the Schema), this will be [None]. + Kind immutable.Option[FieldKind] + + // RelationName contains the name of this relation, if this field is part of a relationship. + // + // Otherwise will be [None]. + RelationName immutable.Option[string] } func (f FieldID) String() string { return fmt.Sprint(uint32(f)) } + +// collectionFieldDescription is a private type used to facilitate the unmarshalling +// of json to a [CollectionFieldDescription]. +type collectionFieldDescription struct { + Name string + ID FieldID + RelationName immutable.Option[string] + + // Properties below this line are unmarshalled using custom logic in [UnmarshalJSON] + Kind json.RawMessage +} + +func (f *CollectionFieldDescription) UnmarshalJSON(bytes []byte) error { + var descMap collectionFieldDescription + err := json.Unmarshal(bytes, &descMap) + if err != nil { + return err + } + + f.Name = descMap.Name + f.ID = descMap.ID + f.RelationName = descMap.RelationName + kind, err := parseFieldKind(descMap.Kind) + if err != nil { + return err + } + + if kind != FieldKind_None { + f.Kind = immutable.Some(kind) + } + + return nil +} diff --git a/client/definitions.go b/client/definitions.go index a8ee52d5af..c04159f679 100644 --- a/client/definitions.go +++ b/client/definitions.go @@ -25,16 +25,28 @@ type CollectionDefinition struct { // GetFieldByName returns the field for the given field name. If such a field is found it // will return it and true, if it is not found it will return false. func (def CollectionDefinition) GetFieldByName(fieldName string) (FieldDefinition, bool) { - collectionField, ok := def.Description.GetFieldByName(fieldName) - if ok { - schemaField, ok := def.Schema.GetFieldByName(fieldName) - if ok { - return NewFieldDefinition( - collectionField, - schemaField, - ), true - } + collectionField, existsOnCollection := def.Description.GetFieldByName(fieldName) + schemaField, existsOnSchema := def.Schema.GetFieldByName(fieldName) + + if existsOnCollection && existsOnSchema { + return NewFieldDefinition( + collectionField, + schemaField, + ), true + } else if existsOnCollection && !existsOnSchema { + // If the field exists only on the collection, it is a local only field, for example the + // secondary side of a relation. + return NewLocalFieldDefinition( + collectionField, + ), true + } else if !existsOnCollection && existsOnSchema { + // If the field only exist on the schema it is likely that this is a schema-only object + // definition, for example for an embedded object. + return NewSchemaOnlyFieldDefinition( + schemaField, + ), true } + return FieldDefinition{}, false } @@ -42,6 +54,8 @@ func (def CollectionDefinition) GetFieldByName(fieldName string) (FieldDefinitio // as a single set. func (def CollectionDefinition) GetFields() []FieldDefinition { fields := []FieldDefinition{} + localFieldNames := map[string]struct{}{} + for _, localField := range def.Description.Fields { globalField, ok := def.Schema.GetFieldByName(localField.Name) if ok { @@ -49,11 +63,41 @@ func (def CollectionDefinition) GetFields() []FieldDefinition { fields, NewFieldDefinition(localField, globalField), ) + } else { + // This must be a local only field, for example the secondary side of a relation. + fields = append( + fields, + NewLocalFieldDefinition(localField), + ) + } + localFieldNames[localField.Name] = struct{}{} + } + + for _, schemaField := range def.Schema.Fields { + if _, ok := localFieldNames[schemaField.Name]; ok { + continue } + // This must be a global only field, for example on an embedded object. + fields = append( + fields, + NewSchemaOnlyFieldDefinition(schemaField), + ) } + return fields } +// GetName gets the name of this definition. +// +// If the collection description has a name (e.g. it is an active collection) it will return that, +// otherwise it will return the schema name. +func (def CollectionDefinition) GetName() string { + if def.Description.Name.HasValue() { + return def.Description.Name.Value() + } + return def.Schema.Name +} + // FieldDefinition describes the combined local and global set of properties that constitutes // a field on a collection. // @@ -94,13 +138,39 @@ type FieldDefinition struct { // NewFieldDefinition returns a new [FieldDefinition], combining the given local and global elements // into a single object. func NewFieldDefinition(local CollectionFieldDescription, global SchemaFieldDescription) FieldDefinition { + var kind FieldKind + if local.Kind.HasValue() { + kind = local.Kind.Value() + } else { + kind = global.Kind + } + return FieldDefinition{ Name: global.Name, ID: local.ID, - Kind: global.Kind, - RelationName: global.RelationName, + Kind: kind, + RelationName: local.RelationName.Value(), Typ: global.Typ, - IsPrimaryRelation: global.IsPrimaryRelation, + IsPrimaryRelation: kind.IsObject() && !kind.IsArray(), + } +} + +// NewLocalFieldDefinition returns a new [FieldDefinition] from the given local [CollectionFieldDescription]. +func NewLocalFieldDefinition(local CollectionFieldDescription) FieldDefinition { + return FieldDefinition{ + Name: local.Name, + ID: local.ID, + Kind: local.Kind.Value(), + RelationName: local.RelationName.Value(), + } +} + +// NewSchemaOnlyFieldDefinition returns a new [FieldDefinition] from the given global [SchemaFieldDescription]. +func NewSchemaOnlyFieldDefinition(global SchemaFieldDescription) FieldDefinition { + return FieldDefinition{ + Name: global.Name, + Kind: global.Kind, + Typ: global.Typ, } } diff --git a/client/document.go b/client/document.go index 3631bb1906..2325328b13 100644 --- a/client/document.go +++ b/client/document.go @@ -66,28 +66,28 @@ type Document struct { // marks if document has unsaved changes isDirty bool - schemaDescription SchemaDescription + collectionDefinition CollectionDefinition } -func newEmptyDoc(sd SchemaDescription) *Document { +func newEmptyDoc(collectionDefinition CollectionDefinition) *Document { return &Document{ - fields: make(map[string]Field), - values: make(map[Field]*FieldValue), - schemaDescription: sd, + fields: make(map[string]Field), + values: make(map[Field]*FieldValue), + collectionDefinition: collectionDefinition, } } // NewDocWithID creates a new Document with a specified key. -func NewDocWithID(docID DocID, sd SchemaDescription) *Document { - doc := newEmptyDoc(sd) +func NewDocWithID(docID DocID, collectionDefinition CollectionDefinition) *Document { + doc := newEmptyDoc(collectionDefinition) doc.id = docID return doc } // NewDocFromMap creates a new Document from a data map. -func NewDocFromMap(data map[string]any, sd SchemaDescription) (*Document, error) { +func NewDocFromMap(data map[string]any, collectionDefinition CollectionDefinition) (*Document, error) { var err error - doc := newEmptyDoc(sd) + doc := newEmptyDoc(collectionDefinition) // check if document contains special _docID field k, hasDocID := data[request.DocIDFieldName] @@ -126,8 +126,8 @@ func IsJSONArray(obj []byte) bool { } // NewFromJSON creates a new instance of a Document from a raw JSON object byte array. -func NewDocFromJSON(obj []byte, sd SchemaDescription) (*Document, error) { - doc := newEmptyDoc(sd) +func NewDocFromJSON(obj []byte, collectionDefinition CollectionDefinition) (*Document, error) { + doc := newEmptyDoc(collectionDefinition) err := doc.SetWithJSON(obj) if err != nil { return nil, err @@ -141,7 +141,7 @@ func NewDocFromJSON(obj []byte, sd SchemaDescription) (*Document, error) { // ManyFromJSON creates a new slice of Documents from a raw JSON array byte array. // It will return an error if the given byte array is not a valid JSON array. -func NewDocsFromJSON(obj []byte, sd SchemaDescription) ([]*Document, error) { +func NewDocsFromJSON(obj []byte, collectionDefinition CollectionDefinition) ([]*Document, error) { v, err := fastjson.ParseBytes(obj) if err != nil { return nil, err @@ -157,7 +157,7 @@ func NewDocsFromJSON(obj []byte, sd SchemaDescription) ([]*Document, error) { if err != nil { return nil, err } - doc := newEmptyDoc(sd) + doc := newEmptyDoc(collectionDefinition) err = doc.setWithFastJSONObject(o) if err != nil { return nil, err @@ -176,7 +176,7 @@ func NewDocsFromJSON(obj []byte, sd SchemaDescription) ([]*Document, error) { // and ensures it matches the supplied field description. // It will do any minor parsing, like dates, and return // the typed value again as an interface. -func validateFieldSchema(val any, field SchemaFieldDescription) (NormalValue, error) { +func validateFieldSchema(val any, field FieldDefinition) (NormalValue, error) { if field.Kind.IsNillable() { if val == nil { return NewNormalNil(field.Kind) @@ -588,15 +588,15 @@ func (doc *Document) setWithFastJSONObject(obj *fastjson.Object) error { // Set the value of a field. func (doc *Document) Set(field string, value any) error { - fd, exists := doc.schemaDescription.GetFieldByName(field) + fd, exists := doc.collectionDefinition.GetFieldByName(field) if !exists { return NewErrFieldNotExist(field) } - if fd.IsRelation() && !fd.Kind.IsObjectArray() { + if fd.Kind.IsObject() && !fd.Kind.IsObjectArray() { if !strings.HasSuffix(field, request.RelatedObjectID) { field = field + request.RelatedObjectID } - fd, exists = doc.schemaDescription.GetFieldByName(field) + fd, exists = doc.collectionDefinition.GetFieldByName(field) if !exists { return NewErrFieldNotExist(field) } diff --git a/client/document_test.go b/client/document_test.go index 593876705f..a70e868e0e 100644 --- a/client/document_test.go +++ b/client/document_test.go @@ -16,6 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/sourcenetwork/immutable" + ccid "github.com/sourcenetwork/defradb/core/cid" ) @@ -27,8 +29,22 @@ var ( pref = ccid.NewDefaultSHA256PrefixV1() - schemaDescriptions = []SchemaDescription{ - { + def = CollectionDefinition{ + Description: CollectionDescription{ + Name: immutable.Some("User"), + Fields: []CollectionFieldDescription{ + { + Name: "Name", + }, + { + Name: "Age", + }, + { + Name: "Custom", + }, + }, + }, + Schema: SchemaDescription{ Name: "User", Fields: []SchemaFieldDescription{ { @@ -52,7 +68,7 @@ var ( ) func TestNewFromJSON(t *testing.T) { - doc, err := NewDocFromJSON(testJSONObj, schemaDescriptions[0]) + doc, err := NewDocFromJSON(testJSONObj, def) if err != nil { t.Error("Error creating new doc from JSON:", err) return @@ -90,7 +106,7 @@ func TestNewFromJSON(t *testing.T) { } func TestSetWithJSON(t *testing.T) { - doc, err := NewDocFromJSON(testJSONObj, schemaDescriptions[0]) + doc, err := NewDocFromJSON(testJSONObj, def) if err != nil { t.Error("Error creating new doc from JSON:", err) return @@ -137,7 +153,7 @@ func TestSetWithJSON(t *testing.T) { } func TestNewDocsFromJSON_WithObjectInsteadOfArray_Error(t *testing.T) { - _, err := NewDocsFromJSON(testJSONObj, schemaDescriptions[0]) + _, err := NewDocsFromJSON(testJSONObj, def) require.ErrorContains(t, err, "value doesn't contain array; it contains object") } @@ -147,7 +163,7 @@ func TestNewFromJSON_WithValidJSONFieldValue_NoError(t *testing.T) { "Age": 26, "Custom": "{\"tree\":\"maple\", \"age\": 260}" }`) - doc, err := NewDocFromJSON(objWithJSONField, schemaDescriptions[0]) + doc, err := NewDocFromJSON(objWithJSONField, def) if err != nil { t.Error("Error creating new doc from JSON:", err) return @@ -177,7 +193,7 @@ func TestNewFromJSON_WithInvalidJSONFieldValue_Error(t *testing.T) { "Age": 26, "Custom": "{\"tree\":\"maple, \"age\": 260}" }`) - _, err := NewDocFromJSON(objWithJSONField, schemaDescriptions[0]) + _, err := NewDocFromJSON(objWithJSONField, def) require.ErrorContains(t, err, "invalid JSON payload. Payload: {\"tree\":\"maple, \"age\": 260}") } @@ -187,6 +203,6 @@ func TestNewFromJSON_WithInvalidJSONFieldValueSimpleString_Error(t *testing.T) { "Age": 26, "Custom": "blah" }`) - _, err := NewDocFromJSON(objWithJSONField, schemaDescriptions[0]) + _, err := NewDocFromJSON(objWithJSONField, def) require.ErrorContains(t, err, "invalid JSON payload. Payload: blah") } diff --git a/client/errors.go b/client/errors.go index c9f7fa0b39..460392a030 100644 --- a/client/errors.go +++ b/client/errors.go @@ -22,7 +22,6 @@ const ( errParsingFailed string = "failed to parse argument" errUninitializeProperty string = "invalid state, required property is uninitialized" errMaxTxnRetries string = "reached maximum transaction reties" - errRelationOneSided string = "relation must be defined on both schemas" errCollectionNotFound string = "collection not found" errUnknownCRDT string = "unknown crdt" errCRDTKindMismatch string = "CRDT type %s can't be assigned to field kind %s" @@ -33,7 +32,6 @@ const ( errCanNotNormalizeValue string = "can not normalize value" errCanNotTurnNormalValueIntoArray string = "can not turn normal value into array" errCanNotMakeNormalNilFromFieldKind string = "can not make normal nil from field kind" - errPrimarySideNotDefined string = "primary side of relation not defined" ) // Errors returnable from this package. @@ -58,7 +56,6 @@ var ( ErrCanNotNormalizeValue = errors.New(errCanNotNormalizeValue) ErrCanNotTurnNormalValueIntoArray = errors.New(errCanNotTurnNormalValueIntoArray) ErrCanNotMakeNormalNilFromFieldKind = errors.New(errCanNotMakeNormalNilFromFieldKind) - ErrPrimarySideNotDefined = errors.New(errPrimarySideNotDefined) ) // NewErrFieldNotExist returns an error indicating that the given field does not exist. @@ -131,14 +128,6 @@ func NewErrMaxTxnRetries(inner error) error { return errors.Wrap(errMaxTxnRetries, inner) } -func NewErrRelationOneSided(fieldName string, typeName string) error { - return errors.New( - errRelationOneSided, - errors.NewKV("Field", fieldName), - errors.NewKV("Type", typeName), - ) -} - func NewErrCollectionNotFoundForSchemaVersion(schemaVersionID string) error { return errors.New( errCollectionNotFound, @@ -175,10 +164,3 @@ func NewErrCRDTKindMismatch(cType, kind string) error { func NewErrInvalidJSONPaylaod(payload string) error { return errors.New(errInvalidJSONPayload, errors.NewKV("Payload", payload)) } - -func NewErrPrimarySideNotDefined(relationName string) error { - return errors.New( - errPrimarySideNotDefined, - errors.NewKV("RelationName", relationName), - ) -} diff --git a/client/schema_field_description.go b/client/schema_field_description.go index 0e9fabc03b..f317ace116 100644 --- a/client/schema_field_description.go +++ b/client/schema_field_description.go @@ -53,17 +53,10 @@ type SchemaFieldDescription struct { // Must contain a valid value. It is currently immutable. Kind FieldKind - // RelationName the name of the relationship that this field represents if this field is - // a relation field. Otherwise this will be empty. - RelationName string - // The CRDT Type of this field. If no type has been provided it will default to [LWW_REGISTER]. // // It is currently immutable. Typ CType - - // If true, this is the primary half of a relation, otherwise is false. - IsPrimaryRelation bool } // ScalarKind represents singular scalar field kinds, such as `Int`. @@ -278,16 +271,14 @@ var FieldKindStringToEnumMapping = map[string]FieldKind{ // IsRelation returns true if this field is a relation. func (f SchemaFieldDescription) IsRelation() bool { - return f.RelationName != "" + return f.Kind.IsObject() } // schemaFieldDescription is a private type used to facilitate the unmarshalling // of json to a [SchemaFieldDescription]. type schemaFieldDescription struct { - Name string - RelationName string - Typ CType - IsPrimaryRelation bool + Name string + Typ CType // Properties below this line are unmarshalled using custom logic in [UnmarshalJSON] Kind json.RawMessage @@ -301,9 +292,7 @@ func (f *SchemaFieldDescription) UnmarshalJSON(bytes []byte) error { } f.Name = descMap.Name - f.RelationName = descMap.RelationName f.Typ = descMap.Typ - f.IsPrimaryRelation = descMap.IsPrimaryRelation f.Kind, err = parseFieldKind(descMap.Kind) if err != nil { return err diff --git a/db/backup.go b/db/backup.go index cc2f732d7e..1353376f34 100644 --- a/db/backup.go +++ b/db/backup.go @@ -84,7 +84,7 @@ func (db *db) basicImport(ctx context.Context, filepath string) (err error) { delete(docMap, request.DocIDFieldName) delete(docMap, request.NewDocIDFieldName) - doc, err := client.NewDocFromMap(docMap, col.Schema()) + doc, err := client.NewDocFromMap(docMap, col.Definition()) if err != nil { return NewErrDocFromMap(err) } @@ -257,7 +257,7 @@ func (db *db) basicExport(ctx context.Context, config *client.BackupConfig) (err refFieldName = field.Name + request.RelatedObjectID } - newForeignDoc, err := client.NewDocFromMap(oldForeignDoc, foreignCol.Schema()) + newForeignDoc, err := client.NewDocFromMap(oldForeignDoc, foreignCol.Definition()) if err != nil { return err } @@ -288,7 +288,7 @@ func (db *db) basicExport(ctx context.Context, config *client.BackupConfig) (err delete(docM, refFieldName) } - newDoc, err := client.NewDocFromMap(docM, col.Schema()) + newDoc, err := client.NewDocFromMap(docM, col.Definition()) if err != nil { return err } diff --git a/db/backup_test.go b/db/backup_test.go index ec9bc947b5..486080db81 100644 --- a/db/backup_test.go +++ b/db/backup_test.go @@ -41,10 +41,10 @@ func TestBasicExport_WithNormalFormatting_NoError(t *testing.T) { col1, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc1, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col1.Schema()) + doc1, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col1.Definition()) require.NoError(t, err) - doc2, err := client.NewDocFromJSON([]byte(`{"name": "Bob", "age": 40}`), col1.Schema()) + doc2, err := client.NewDocFromJSON([]byte(`{"name": "Bob", "age": 40}`), col1.Definition()) require.NoError(t, err) err = col1.Create(ctx, doc1) @@ -56,7 +56,7 @@ func TestBasicExport_WithNormalFormatting_NoError(t *testing.T) { col2, err := db.GetCollectionByName(ctx, "Address") require.NoError(t, err) - doc3, err := client.NewDocFromJSON([]byte(`{"street": "101 Maple St", "city": "Toronto"}`), col2.Schema()) + doc3, err := client.NewDocFromJSON([]byte(`{"street": "101 Maple St", "city": "Toronto"}`), col2.Definition()) require.NoError(t, err) err = col2.Create(ctx, doc3) @@ -106,10 +106,10 @@ func TestBasicExport_WithPrettyFormatting_NoError(t *testing.T) { col1, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc1, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col1.Schema()) + doc1, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col1.Definition()) require.NoError(t, err) - doc2, err := client.NewDocFromJSON([]byte(`{"name": "Bob", "age": 40}`), col1.Schema()) + doc2, err := client.NewDocFromJSON([]byte(`{"name": "Bob", "age": 40}`), col1.Definition()) require.NoError(t, err) err = col1.Create(ctx, doc1) @@ -121,7 +121,7 @@ func TestBasicExport_WithPrettyFormatting_NoError(t *testing.T) { col2, err := db.GetCollectionByName(ctx, "Address") require.NoError(t, err) - doc3, err := client.NewDocFromJSON([]byte(`{"street": "101 Maple St", "city": "Toronto"}`), col2.Schema()) + doc3, err := client.NewDocFromJSON([]byte(`{"street": "101 Maple St", "city": "Toronto"}`), col2.Definition()) require.NoError(t, err) err = col2.Create(ctx, doc3) @@ -171,10 +171,10 @@ func TestBasicExport_WithSingleCollection_NoError(t *testing.T) { col1, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc1, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col1.Schema()) + doc1, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col1.Definition()) require.NoError(t, err) - doc2, err := client.NewDocFromJSON([]byte(`{"name": "Bob", "age": 40}`), col1.Schema()) + doc2, err := client.NewDocFromJSON([]byte(`{"name": "Bob", "age": 40}`), col1.Definition()) require.NoError(t, err) err = col1.Create(ctx, doc1) @@ -186,7 +186,7 @@ func TestBasicExport_WithSingleCollection_NoError(t *testing.T) { col2, err := db.GetCollectionByName(ctx, "Address") require.NoError(t, err) - doc3, err := client.NewDocFromJSON([]byte(`{"street": "101 Maple St", "city": "Toronto"}`), col2.Schema()) + doc3, err := client.NewDocFromJSON([]byte(`{"street": "101 Maple St", "city": "Toronto"}`), col2.Definition()) require.NoError(t, err) err = col2.Create(ctx, doc3) @@ -237,10 +237,10 @@ func TestBasicExport_WithMultipleCollectionsAndUpdate_NoError(t *testing.T) { col1, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc1, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col1.Schema()) + doc1, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col1.Definition()) require.NoError(t, err) - doc2, err := client.NewDocFromJSON([]byte(`{"name": "Bob", "age": 31}`), col1.Schema()) + doc2, err := client.NewDocFromJSON([]byte(`{"name": "Bob", "age": 31}`), col1.Definition()) require.NoError(t, err) err = col1.Create(ctx, doc1) @@ -252,10 +252,10 @@ func TestBasicExport_WithMultipleCollectionsAndUpdate_NoError(t *testing.T) { col2, err := db.GetCollectionByName(ctx, "Book") require.NoError(t, err) - doc3, err := client.NewDocFromJSON([]byte(`{"name": "John and the sourcerers' stone", "author": "bae-e933420a-988a-56f8-8952-6c245aebd519"}`), col2.Schema()) + doc3, err := client.NewDocFromJSON([]byte(`{"name": "John and the sourcerers' stone", "author": "bae-e933420a-988a-56f8-8952-6c245aebd519"}`), col2.Definition()) require.NoError(t, err) - doc4, err := client.NewDocFromJSON([]byte(`{"name": "Game of chains", "author": "bae-e933420a-988a-56f8-8952-6c245aebd519"}`), col2.Schema()) + doc4, err := client.NewDocFromJSON([]byte(`{"name": "Game of chains", "author": "bae-e933420a-988a-56f8-8952-6c245aebd519"}`), col2.Definition()) require.NoError(t, err) err = col2.Create(ctx, doc3) @@ -313,10 +313,10 @@ func TestBasicExport_EnsureFileOverwrite_NoError(t *testing.T) { col1, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc1, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col1.Schema()) + doc1, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col1.Definition()) require.NoError(t, err) - doc2, err := client.NewDocFromJSON([]byte(`{"name": "Bob", "age": 40}`), col1.Schema()) + doc2, err := client.NewDocFromJSON([]byte(`{"name": "Bob", "age": 40}`), col1.Definition()) require.NoError(t, err) err = col1.Create(ctx, doc1) @@ -328,7 +328,7 @@ func TestBasicExport_EnsureFileOverwrite_NoError(t *testing.T) { col2, err := db.GetCollectionByName(ctx, "Address") require.NoError(t, err) - doc3, err := client.NewDocFromJSON([]byte(`{"street": "101 Maple St", "city": "Toronto"}`), col2.Schema()) + doc3, err := client.NewDocFromJSON([]byte(`{"street": "101 Maple St", "city": "Toronto"}`), col2.Definition()) require.NoError(t, err) err = col2.Create(ctx, doc3) diff --git a/db/collection.go b/db/collection.go index 67b32f2d09..e84530d3e7 100644 --- a/db/collection.go +++ b/db/collection.go @@ -85,6 +85,7 @@ func (c *collection) newFetcher() fetcher.Fetcher { func (db *db) createCollection( ctx context.Context, def client.CollectionDefinition, + newDefinitions []client.CollectionDefinition, ) (client.Collection, error) { schema := def.Schema desc := def.Description @@ -100,6 +101,36 @@ func (db *db) createCollection( } } + existingDefinitions, err := db.getAllActiveDefinitions(ctx) + if err != nil { + return nil, err + } + + schemaByName := map[string]client.SchemaDescription{} + for _, existingDefinition := range existingDefinitions { + schemaByName[existingDefinition.Schema.Name] = existingDefinition.Schema + } + for _, newDefinition := range newDefinitions { + schemaByName[newDefinition.Schema.Name] = newDefinition.Schema + } + + _, err = validateUpdateSchemaFields(schemaByName, client.SchemaDescription{}, schema) + if err != nil { + return nil, err + } + + definitionsByName := map[string]client.CollectionDefinition{} + for _, existingDefinition := range existingDefinitions { + definitionsByName[existingDefinition.GetName()] = existingDefinition + } + for _, newDefinition := range newDefinitions { + definitionsByName[newDefinition.GetName()] = newDefinition + } + err = db.validateNewCollection(def, definitionsByName) + if err != nil { + return nil, err + } + colSeq, err := db.getSequence(ctx, core.CollectionIDSequenceKey{}) if err != nil { return nil, err @@ -122,9 +153,9 @@ func (db *db) createCollection( return nil, err } desc.SchemaVersionID = schema.VersionID - for _, globalField := range schema.Fields { + for _, localField := range desc.Fields { var fieldID uint64 - if globalField.Name == request.DocIDFieldName { + if localField.Name == request.DocIDFieldName { // There is no hard technical requirement for this, we just think it looks nicer // if the doc id is at the zero index. It makes it look a little nicer in commit // queries too. @@ -136,13 +167,12 @@ func (db *db) createCollection( } } - desc.Fields = append( - desc.Fields, - client.CollectionFieldDescription{ - Name: globalField.Name, - ID: client.FieldID(fieldID), - }, - ) + for i := range desc.Fields { + if desc.Fields[i].Name == localField.Name { + desc.Fields[i].ID = client.FieldID(fieldID) + break + } + } } desc, err = description.SaveCollection(ctx, txn, desc) @@ -226,9 +256,8 @@ func (db *db) updateSchema( idFieldName := field.Name + "_id" if _, ok := schema.GetFieldByName(idFieldName); !ok { schema.Fields = append(schema.Fields, client.SchemaFieldDescription{ - Name: idFieldName, - Kind: client.FieldKind_DocID, - RelationName: field.RelationName, + Name: idFieldName, + Kind: client.FieldKind_DocID, }) } } @@ -459,22 +488,12 @@ func validateUpdateSchemaFields( hasChanged = hasChanged || !fieldAlreadyExists if !fieldAlreadyExists && proposedField.Kind.IsObject() { - relatedDesc, relatedDescFound := descriptionsByName[proposedField.Kind.Underlying()] + _, relatedDescFound := descriptionsByName[proposedField.Kind.Underlying()] if !relatedDescFound { return false, NewErrFieldKindNotFound(proposedField.Name, proposedField.Kind.Underlying()) } - if proposedField.RelationName == "" { - return false, NewErrRelationalFieldMissingRelationName(proposedField.Name) - } - - if proposedField.IsPrimaryRelation { - if proposedField.Kind.IsObjectArray() { - return false, NewErrPrimarySideOnMany(proposedField.Name) - } - } - if proposedField.Kind.IsObject() && !proposedField.Kind.IsArray() { idFieldName := proposedField.Name + request.RelatedObjectID idField, idFieldFound := proposedDesc.GetFieldByName(idFieldName) @@ -482,36 +501,12 @@ func validateUpdateSchemaFields( if idField.Kind != client.FieldKind_DocID { return false, NewErrRelationalFieldIDInvalidType(idField.Name, client.FieldKind_DocID, idField.Kind) } - - if idField.RelationName == "" { - return false, NewErrRelationalFieldMissingRelationName(idField.Name) - } } } + } - var relatedFieldFound bool - var relatedField client.SchemaFieldDescription - for _, field := range relatedDesc.Fields { - if field.RelationName == proposedField.RelationName && - field.Kind != client.FieldKind_DocID && - !(relatedDesc.Name == proposedDesc.Name && field.Name == proposedField.Name) { - relatedFieldFound = true - relatedField = field - break - } - } - - if !relatedFieldFound { - return false, client.NewErrRelationOneSided(proposedField.Name, proposedField.Kind.Underlying()) - } - - if !(proposedField.IsPrimaryRelation || relatedField.IsPrimaryRelation) { - return false, client.NewErrPrimarySideNotDefined(proposedField.RelationName) - } - - if proposedField.IsPrimaryRelation && relatedField.IsPrimaryRelation { - return false, NewErrBothSidesPrimary(proposedField.RelationName) - } + if proposedField.Kind.IsObjectArray() { + return false, NewErrSecondaryFieldOnSchema(proposedField.Name) } if _, isDuplicate := newFieldNames[proposedField.Name]; isDuplicate { @@ -671,6 +666,153 @@ func (db *db) validateCollectionChanges( return nil } +var newCollectionValidators = []func( + client.CollectionDefinition, + map[string]client.CollectionDefinition, +) error{ + validateSecondaryFieldsPairUp, + validateRelationPointsToValidKind, + validateSingleSidePrimary, +} + +func (db *db) validateNewCollection( + def client.CollectionDefinition, + defsByName map[string]client.CollectionDefinition, +) error { + for _, validators := range newCollectionValidators { + err := validators(def, defsByName) + if err != nil { + return err + } + } + + return nil +} + +func validateRelationPointsToValidKind( + def client.CollectionDefinition, + defsByName map[string]client.CollectionDefinition, +) error { + for _, field := range def.Description.Fields { + if !field.Kind.HasValue() { + continue + } + + if !field.Kind.Value().IsObject() { + continue + } + + underlying := field.Kind.Value().Underlying() + _, ok := defsByName[underlying] + if !ok { + return NewErrFieldKindNotFound(field.Name, underlying) + } + } + + return nil +} + +func validateSecondaryFieldsPairUp( + def client.CollectionDefinition, + defsByName map[string]client.CollectionDefinition, +) error { + for _, field := range def.Description.Fields { + if !field.Kind.HasValue() { + continue + } + + if !field.Kind.Value().IsObject() { + continue + } + + if !field.RelationName.HasValue() { + continue + } + + _, hasSchemaField := def.Schema.GetFieldByName(field.Name) + if hasSchemaField { + continue + } + + underlying := field.Kind.Value().Underlying() + otherDef, ok := defsByName[underlying] + if !ok { + continue + } + + if len(otherDef.Description.Fields) == 0 { + // Views/embedded objects do not require both sides of the relation to be defined. + continue + } + + otherField, ok := otherDef.Description.GetFieldByRelation( + field.RelationName.Value(), + def.GetName(), + field.Name, + ) + if !ok { + return NewErrRelationMissingField(underlying, field.RelationName.Value()) + } + + _, ok = otherDef.Schema.GetFieldByName(otherField.Name) + if !ok { + // This secondary is paired with another secondary, which is invalid + return NewErrRelationMissingField(underlying, field.RelationName.Value()) + } + } + + return nil +} + +func validateSingleSidePrimary( + def client.CollectionDefinition, + defsByName map[string]client.CollectionDefinition, +) error { + for _, field := range def.Description.Fields { + if !field.Kind.HasValue() { + continue + } + + if !field.Kind.Value().IsObject() { + continue + } + + if !field.RelationName.HasValue() { + continue + } + + _, hasSchemaField := def.Schema.GetFieldByName(field.Name) + if !hasSchemaField { + // This is a secondary field and thus passes this rule + continue + } + + underlying := field.Kind.Value().Underlying() + otherDef, ok := defsByName[underlying] + if !ok { + continue + } + + otherField, ok := otherDef.Description.GetFieldByRelation( + field.RelationName.Value(), + def.GetName(), + field.Name, + ) + if !ok { + // This must be a one-sided relation, in which case it passes this rule + continue + } + + _, ok = otherDef.Schema.GetFieldByName(otherField.Name) + if ok { + // This primary is paired with another primary, which is invalid + return ErrMultipleRelationPrimaries + } + } + + return nil +} + func validateCollectionNameUnique( oldColsByID map[uint32]client.CollectionDescription, newColsByID map[uint32]client.CollectionDescription, @@ -1705,14 +1847,14 @@ func (c *collection) validateOneToOneLinkDoesntAlreadyExist( if err != nil { return err } - otherSchema := otherCol.Schema() otherObjFieldDescription, _ := otherCol.Description().GetFieldByRelation( fieldDescription.RelationName, c.Name().Value(), objFieldDescription.Name, - &otherSchema, ) - if !(otherObjFieldDescription.Kind.IsObject() && !otherObjFieldDescription.Kind.IsArray()) { + if !(otherObjFieldDescription.Kind.HasValue() && + otherObjFieldDescription.Kind.Value().IsObject() && + !otherObjFieldDescription.Kind.Value().IsArray()) { // If the other field is not an object field then this is not a one to one relation and we can continue return nil } diff --git a/db/collection_get.go b/db/collection_get.go index 7f7d82f0ed..75d3d2826b 100644 --- a/db/collection_get.go +++ b/db/collection_get.go @@ -94,7 +94,7 @@ func (c *collection) get( return nil, nil } - doc, err := fetcher.Decode(encodedDoc, c.Schema()) + doc, err := fetcher.Decode(encodedDoc, c.Definition()) if err != nil { return nil, err } diff --git a/db/collection_index.go b/db/collection_index.go index 159e40b4e9..2327ae027a 100644 --- a/db/collection_index.go +++ b/db/collection_index.go @@ -358,7 +358,7 @@ func (c *collection) iterateAllDocs( break } - doc, err := fetcher.Decode(encodedDoc, c.Schema()) + doc, err := fetcher.Decode(encodedDoc, c.Definition()) if err != nil { return errors.Join(err, df.Close()) } diff --git a/db/collection_update.go b/db/collection_update.go index c4d56de158..9110976593 100644 --- a/db/collection_update.go +++ b/db/collection_update.go @@ -262,7 +262,7 @@ func (c *collection) updateWithFilter( // Get the document, and apply the patch docAsMap := docMap.ToMap(selectionPlan.Value()) - doc, err := client.NewDocFromMap(docAsMap, c.Schema()) + doc, err := client.NewDocFromMap(docAsMap, c.Definition()) if err != nil { return nil, err } @@ -323,13 +323,11 @@ func (c *collection) patchPrimaryDoc( if err != nil { return err } - primarySchema := primaryCol.Schema() primaryField, ok := primaryCol.Description().GetFieldByRelation( relationFieldDescription.RelationName, secondaryCollectionName, relationFieldDescription.Name, - &primarySchema, ) if !ok { return client.NewErrFieldNotExist(relationFieldDescription.RelationName) @@ -355,7 +353,7 @@ func (c *collection) patchPrimaryDoc( return nil } - pc := c.db.newCollection(primaryCol.Description(), primarySchema) + pc := c.db.newCollection(primaryCol.Description(), primaryCol.Schema()) err = pc.validateOneToOneLinkDoesntAlreadyExist( ctx, primaryDocID.String(), diff --git a/db/errors.go b/db/errors.go index da82fcb941..f917ee9724 100644 --- a/db/errors.go +++ b/db/errors.go @@ -30,9 +30,6 @@ const ( errCannotSetVersionID string = "setting the VersionID is not supported" errRelationalFieldInvalidRelationType string = "invalid RelationType" errRelationalFieldMissingIDField string = "missing id field for relation object field" - errRelationalFieldMissingRelationName string = "missing relation name" - errPrimarySideOnMany string = "cannot set the many side of a relation as primary" - errBothSidesPrimary string = "both sides of a relation cannot be primary" errRelatedFieldKindMismatch string = "invalid Kind of the related field" errRelatedFieldRelationTypeMismatch string = "invalid RelationType of the related field" errRelationalFieldIDInvalidType string = "relational id field of invalid kind" @@ -94,6 +91,8 @@ const ( errCollectionIDCannotBeZero string = "collection ID cannot be zero" errCollectionsCannotBeDeleted string = "collections cannot be deleted" errCanNotHavePolicyWithoutACP string = "can not specify policy on collection, without acp" + errSecondaryFieldOnSchema string = "secondary relation fields cannot be defined on the schema" + errRelationMissingField string = "relation missing field" ) var ( @@ -125,6 +124,9 @@ var ( ErrCollectionIDCannotBeZero = errors.New(errCollectionIDCannotBeZero) ErrCollectionsCannotBeDeleted = errors.New(errCollectionsCannotBeDeleted) ErrCanNotHavePolicyWithoutACP = errors.New(errCanNotHavePolicyWithoutACP) + ErrSecondaryFieldOnSchema = errors.New(errSecondaryFieldOnSchema) + ErrRelationMissingField = errors.New(errRelationMissingField) + ErrMultipleRelationPrimaries = errors.New("relation can only have a single field set as primary") ) // NewErrFailedToGetHeads returns a new error indicating that the heads of a document @@ -269,27 +271,6 @@ func NewErrRelationalFieldMissingIDField(name string, expectedName string) error ) } -func NewErrRelationalFieldMissingRelationName(name string) error { - return errors.New( - errRelationalFieldMissingRelationName, - errors.NewKV("Field", name), - ) -} - -func NewErrPrimarySideOnMany(name string) error { - return errors.New( - errPrimarySideOnMany, - errors.NewKV("Field", name), - ) -} - -func NewErrBothSidesPrimary(relationName string) error { - return errors.New( - errBothSidesPrimary, - errors.NewKV("RelationName", relationName), - ) -} - func NewErrRelatedFieldKindMismatch(relationName string, expected client.FieldKind, actual client.FieldKind) error { return errors.New( errRelatedFieldKindMismatch, @@ -628,3 +609,18 @@ func NewErrCollectionsCannotBeDeleted(colID uint32) error { errors.NewKV("CollectionID", colID), ) } + +func NewErrSecondaryFieldOnSchema(name string) error { + return errors.New( + errSecondaryFieldOnSchema, + errors.NewKV("Name", name), + ) +} + +func NewErrRelationMissingField(objectName, relationName string) error { + return errors.New( + errRelationMissingField, + errors.NewKV("Object", objectName), + errors.NewKV("RelationName", relationName), + ) +} diff --git a/db/fetcher/encoded_doc.go b/db/fetcher/encoded_doc.go index 889aea848a..cb4345abe1 100644 --- a/db/fetcher/encoded_doc.go +++ b/db/fetcher/encoded_doc.go @@ -106,13 +106,13 @@ func (encdoc *encodedDocument) Reset() { } // Decode returns a properly decoded document object -func Decode(encdoc EncodedDocument, sd client.SchemaDescription) (*client.Document, error) { +func Decode(encdoc EncodedDocument, collectionDefinition client.CollectionDefinition) (*client.Document, error) { docID, err := client.NewDocIDFromString(string(encdoc.ID())) if err != nil { return nil, err } - doc := client.NewDocWithID(docID, sd) + doc := client.NewDocWithID(docID, collectionDefinition) properties, err := encdoc.Properties(false) if err != nil { return nil, err diff --git a/db/indexed_docs_test.go b/db/indexed_docs_test.go index 86746a9558..c3c1c6de7b 100644 --- a/db/indexed_docs_test.go +++ b/db/indexed_docs_test.go @@ -60,7 +60,7 @@ func (f *indexTestFixture) newUserDoc(name string, age int, col client.Collectio data, err := json.Marshal(d) require.NoError(f.t, err) - doc, err := client.NewDocFromJSON(data, col.Schema()) + doc, err := client.NewDocFromJSON(data, col.Definition()) require.NoError(f.t, err) return doc } @@ -70,7 +70,7 @@ func (f *indexTestFixture) newProdDoc(id int, price float64, cat string, col cli data, err := json.Marshal(d) require.NoError(f.t, err) - doc, err := client.NewDocFromJSON(data, col.Schema()) + doc, err := client.NewDocFromJSON(data, col.Definition()) require.NoError(f.t, err) return doc } @@ -339,7 +339,7 @@ func TestNonUnique_IfDocDoesNotHaveIndexedField_SkipIndex(t *testing.T) { }{Age: 21, Weight: 154.1}) require.NoError(f.t, err) - doc, err := client.NewDocFromJSON(data, f.users.Schema()) + doc, err := client.NewDocFromJSON(data, f.users.Definition()) require.NoError(f.t, err) err = f.users.Create(f.ctx, doc) @@ -549,7 +549,7 @@ func TestNonUnique_IfIndexedFieldIsNil_StoreItAsNil(t *testing.T) { }{Age: 44}) require.NoError(f.t, err) - doc, err := client.NewDocFromJSON(docJSON, f.users.Schema()) + doc, err := client.NewDocFromJSON(docJSON, f.users.Definition()) require.NoError(f.t, err) f.saveDocToCollection(doc, f.users) @@ -1070,7 +1070,7 @@ func TestNonUpdate_IfIndexedFieldWasNil_ShouldDeleteIt(t *testing.T) { }{Age: 44}) require.NoError(f.t, err) - doc, err := client.NewDocFromJSON(docJSON, f.users.Schema()) + doc, err := client.NewDocFromJSON(docJSON, f.users.Definition()) require.NoError(f.t, err) f.saveDocToCollection(doc, f.users) @@ -1156,7 +1156,7 @@ func TestUnique_IfIndexedFieldIsNil_StoreItAsNil(t *testing.T) { }{Age: 44}) require.NoError(f.t, err) - doc, err := client.NewDocFromJSON(docJSON, f.users.Schema()) + doc, err := client.NewDocFromJSON(docJSON, f.users.Definition()) require.NoError(f.t, err) f.saveDocToCollection(doc, f.users) @@ -1270,7 +1270,7 @@ func TestComposite_IfIndexedFieldIsNil_StoreItAsNil(t *testing.T) { }{Age: 44}) require.NoError(f.t, err) - doc, err := client.NewDocFromJSON(docJSON, f.users.Schema()) + doc, err := client.NewDocFromJSON(docJSON, f.users.Definition()) require.NoError(f.t, err) f.saveDocToCollection(doc, f.users) @@ -1334,7 +1334,7 @@ func TestUniqueComposite_IfNilUpdateToValue_ShouldUpdateIndexStored(t *testing.T require.NoError(f.t, err) f.commitTxn() - doc, err := client.NewDocFromJSON([]byte(tc.Doc), f.users.Schema()) + doc, err := client.NewDocFromJSON([]byte(tc.Doc), f.users.Definition()) require.NoError(f.t, err) f.saveDocToCollection(doc, f.users) diff --git a/db/schema.go b/db/schema.go index 6d52a92aee..756c02f1ff 100644 --- a/db/schema.go +++ b/db/schema.go @@ -51,7 +51,7 @@ func (db *db) addSchema( return nil, err } - col, err := db.createCollection(ctx, definition) + col, err := db.createCollection(ctx, definition, newDefinitions) if err != nil { return nil, err } diff --git a/db/view.go b/db/view.go index 5a778efd53..7cf040cbc5 100644 --- a/db/view.go +++ b/db/view.go @@ -80,7 +80,7 @@ func (db *db) addView( Schema: schema, } } else { - col, err := db.createCollection(ctx, definition) + col, err := db.createCollection(ctx, definition, newDefinitions) if err != nil { return nil, err } diff --git a/http/client_collection.go b/http/client_collection.go index d91601fbeb..a9f0681df7 100644 --- a/http/client_collection.go +++ b/http/client_collection.go @@ -398,7 +398,7 @@ func (c *Collection) Get( if err != nil { return nil, err } - doc := client.NewDocWithID(docID, c.def.Schema) + doc := client.NewDocWithID(docID, c.def) err = doc.SetWithJSON(data) if err != nil { return nil, err diff --git a/http/handler_ccip_test.go b/http/handler_ccip_test.go index 2a2cc4f077..b89517b975 100644 --- a/http/handler_ccip_test.go +++ b/http/handler_ccip_test.go @@ -203,7 +203,7 @@ func setupDatabase(t *testing.T) client.DB { col, err := cdb.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "bob"}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "bob"}`), col.Definition()) require.NoError(t, err) err = col.Create(ctx, doc) diff --git a/http/handler_collection.go b/http/handler_collection.go index 745a05740b..bbcbaab365 100644 --- a/http/handler_collection.go +++ b/http/handler_collection.go @@ -49,7 +49,7 @@ func (s *collectionHandler) Create(rw http.ResponseWriter, req *http.Request) { switch { case client.IsJSONArray(data): - docList, err := client.NewDocsFromJSON(data, col.Schema()) + docList, err := client.NewDocsFromJSON(data, col.Definition()) if err != nil { responseJSON(rw, http.StatusBadRequest, errorResponse{err}) return @@ -61,7 +61,7 @@ func (s *collectionHandler) Create(rw http.ResponseWriter, req *http.Request) { } rw.WriteHeader(http.StatusOK) default: - doc, err := client.NewDocFromJSON(data, col.Schema()) + doc, err := client.NewDocFromJSON(data, col.Definition()) if err != nil { responseJSON(rw, http.StatusBadRequest, errorResponse{err}) return diff --git a/net/client_test.go b/net/client_test.go index 89c26e06b5..bedd28437d 100644 --- a/net/client_test.go +++ b/net/client_test.go @@ -22,13 +22,23 @@ import ( "github.com/sourcenetwork/defradb/events" ) -var sd = client.SchemaDescription{ - Name: "test", - Fields: []client.SchemaFieldDescription{ - { - Name: "test", - Kind: client.FieldKind_NILLABLE_STRING, - Typ: client.LWW_REGISTER, +var def = client.CollectionDefinition{ + Description: client.CollectionDescription{ + Fields: []client.CollectionFieldDescription{ + { + ID: 1, + Name: "test", + }, + }, + }, + Schema: client.SchemaDescription{ + Name: "test", + Fields: []client.SchemaFieldDescription{ + { + Name: "test", + Kind: client.FieldKind_NILLABLE_STRING, + Typ: client.LWW_REGISTER, + }, }, }, } @@ -38,7 +48,7 @@ func TestPushlogWithDialFailure(t *testing.T) { _, n := newTestNode(ctx, t) defer n.Close() - doc, err := client.NewDocFromJSON([]byte(`{"test": "test"}`), sd) + doc, err := client.NewDocFromJSON([]byte(`{"test": "test"}`), def) require.NoError(t, err) id, err := doc.GenerateDocID() require.NoError(t, err) @@ -67,7 +77,7 @@ func TestPushlogWithInvalidPeerID(t *testing.T) { _, n := newTestNode(ctx, t) defer n.Close() - doc, err := client.NewDocFromJSON([]byte(`{"test": "test"}`), sd) + doc, err := client.NewDocFromJSON([]byte(`{"test": "test"}`), def) require.NoError(t, err) id, err := doc.GenerateDocID() require.NoError(t, err) @@ -110,7 +120,7 @@ func TestPushlogW_WithValidPeerID_NoError(t *testing.T) { col, err := n1.db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "test"}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "test"}`), col.Definition()) require.NoError(t, err) err = col.Save(ctx, doc) diff --git a/net/dag_test.go b/net/dag_test.go index ddd9e9aab3..2072122b2d 100644 --- a/net/dag_test.go +++ b/net/dag_test.go @@ -63,7 +63,7 @@ func TestSendJobWorker_WithNewJob_NoError(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) dsKey := core.DataStoreKeyFromDocID(doc.ID()) @@ -107,7 +107,7 @@ func TestSendJobWorker_WithCloseJob_NoError(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) dsKey := core.DataStoreKeyFromDocID(doc.ID()) @@ -168,7 +168,7 @@ func TestSendJobWorker_WithPeer_NoError(t *testing.T) { col, err := db1.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) dsKey := core.DataStoreKeyFromDocID(doc.ID()) diff --git a/net/peer_test.go b/net/peer_test.go index ba06b40447..2ad5db9037 100644 --- a/net/peer_test.go +++ b/net/peer_test.go @@ -168,7 +168,7 @@ func TestNewPeer_WithExistingTopic_TopicAlreadyExistsError(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) err = col.Create(ctx, doc) @@ -333,7 +333,7 @@ func TestRegisterNewDocument_NoError(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) cid, err := createCID(doc) @@ -357,7 +357,7 @@ func TestRegisterNewDocument_RPCTopicAlreadyRegisteredError(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) _, err = rpc.NewTopic(ctx, n.Peer.ps, n.Peer.host.ID(), doc.ID().String(), true) @@ -575,7 +575,7 @@ func TestPushToReplicator_SingleDocumentNoPeer_FailedToReplicateLogError(t *test col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) err = col.Create(ctx, doc) @@ -940,7 +940,7 @@ func TestHandleDocCreateLog_NoError(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) err = col.Create(ctx, doc) @@ -993,7 +993,7 @@ func TestHandleDocCreateLog_WithExistingTopic_TopicExistsError(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) err = col.Create(ctx, doc) @@ -1023,7 +1023,7 @@ func TestHandleDocUpdateLog_NoError(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) err = col.Create(ctx, doc) @@ -1076,7 +1076,7 @@ func TestHandleDocUpdateLog_WithExistingDocIDTopic_TopicExistsError(t *testing.T col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) err = col.Create(ctx, doc) @@ -1120,7 +1120,7 @@ func TestHandleDocUpdateLog_WithExistingSchemaTopic_TopicExistsError(t *testing. col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) err = col.Create(ctx, doc) diff --git a/net/server_test.go b/net/server_test.go index a1d2eeeb57..916e234109 100644 --- a/net/server_test.go +++ b/net/server_test.go @@ -133,7 +133,7 @@ func TestNewServerWithAddTopicError(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) err = col.Create(ctx, doc) @@ -179,7 +179,7 @@ func TestNewServerWithEmitterError(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) err = col.Create(ctx, doc) @@ -262,7 +262,7 @@ func TestPushLog(t *testing.T) { col, err := db.GetCollectionByName(ctx, "User") require.NoError(t, err) - doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(`{"name": "John", "age": 30}`), col.Definition()) require.NoError(t, err) cid, err := createCID(doc) diff --git a/planner/create.go b/planner/create.go index 2918e9ee46..addf8e4d97 100644 --- a/planner/create.go +++ b/planner/create.go @@ -57,7 +57,7 @@ func (n *createNode) Kind() string { return "createNode" } func (n *createNode) Init() error { return nil } func (n *createNode) Start() error { - doc, err := client.NewDocFromMap(n.input, n.collection.Schema()) + doc, err := client.NewDocFromMap(n.input, n.collection.Definition()) if err != nil { n.err = err return err diff --git a/planner/type_join.go b/planner/type_join.go index dd2fae8e77..be1ebb628e 100644 --- a/planner/type_join.go +++ b/planner/type_join.go @@ -80,7 +80,7 @@ func (p *Planner) makeTypeIndexJoin( var joinPlan planNode var err error - typeFieldDesc, ok := parent.collection.Schema().GetFieldByName(subType.Name) + typeFieldDesc, ok := parent.collection.Definition().GetFieldByName(subType.Name) if !ok { return nil, client.NewErrFieldNotExist(subType.Name) } @@ -239,7 +239,7 @@ func (p *Planner) makeTypeJoinOne( } // get the correct sub field schema type (collection) - subTypeFieldDesc, ok := parent.collection.Schema().GetFieldByName(subType.Name) + subTypeFieldDesc, ok := parent.collection.Definition().GetFieldByName(subType.Name) if !ok { return nil, client.NewErrFieldNotExist(subType.Name) } @@ -248,13 +248,11 @@ func (p *Planner) makeTypeJoinOne( if err != nil { return nil, err } - subTypeSchema := subTypeCol.Schema() subTypeField, subTypeFieldNameFound := subTypeCol.Description().GetFieldByRelation( subTypeFieldDesc.RelationName, parent.collection.Name().Value(), subTypeFieldDesc.Name, - &subTypeSchema, ) if !subTypeFieldNameFound { return nil, client.NewErrFieldNotExist(subTypeFieldDesc.RelationName) @@ -271,7 +269,7 @@ func (p *Planner) makeTypeJoinOne( dir := joinDirection{ firstNode: source, secondNode: selectPlan, - secondaryField: subTypeField.Name + request.RelatedObjectID, + secondaryField: immutable.Some(subTypeField.Name + request.RelatedObjectID), primaryField: subTypeFieldDesc.Name + request.RelatedObjectID, } @@ -281,7 +279,7 @@ func (p *Planner) makeTypeJoinOne( root: source, subType: selectPlan, subSelect: subType, - rootName: subTypeField.Name, + rootName: immutable.Some(subTypeField.Name), subTypeName: subType.Name, isSecondary: !subTypeFieldDesc.IsPrimaryRelation, secondaryFieldIndex: secondaryFieldIndex, @@ -374,7 +372,7 @@ func (p *Planner) makeTypeJoinMany( return nil, err } - subTypeFieldDesc, ok := parent.collection.Schema().GetFieldByName(subType.Name) + subTypeFieldDesc, ok := parent.collection.Definition().GetFieldByName(subType.Name) if !ok { return nil, client.NewErrFieldNotExist(subType.Name) } @@ -383,23 +381,25 @@ func (p *Planner) makeTypeJoinMany( if err != nil { return nil, err } - subTypeSchema := subTypeCol.Schema() - rootField, rootNameFound := subTypeCol.Description().GetFieldByRelation( - subTypeFieldDesc.RelationName, - parent.collection.Name().Value(), - subTypeFieldDesc.Name, - &subTypeSchema, - ) - - if !rootNameFound { - return nil, client.NewErrFieldNotExist(subTypeFieldDesc.RelationName) + var secondaryFieldName immutable.Option[string] + var rootName immutable.Option[string] + if subTypeFieldDesc.RelationName != "" { + rootField, rootNameFound := subTypeCol.Description().GetFieldByRelation( + subTypeFieldDesc.RelationName, + parent.collection.Name().Value(), + subTypeFieldDesc.Name, + ) + if rootNameFound { + rootName = immutable.Some(rootField.Name) + secondaryFieldName = immutable.Some(rootField.Name + request.RelatedObjectID) + } } dir := joinDirection{ firstNode: source, secondNode: selectPlan, - secondaryField: rootField.Name + request.RelatedObjectID, + secondaryField: secondaryFieldName, primaryField: subTypeFieldDesc.Name + request.RelatedObjectID, } @@ -409,7 +409,7 @@ func (p *Planner) makeTypeJoinMany( root: source, subType: selectPlan, subSelect: subType, - rootName: rootField.Name, + rootName: rootName, isSecondary: true, subTypeName: subType.Name, secondaryFetchLimit: 0, @@ -457,15 +457,19 @@ func fetchPrimaryDoc(node, subNode planNode, parentProp string) (bool, error) { type joinDirection struct { firstNode planNode secondNode planNode - secondaryField string + secondaryField immutable.Option[string] primaryField string isInverted bool } func (dir *joinDirection) invert() { + if !dir.secondaryField.HasValue() { + // If the secondary field has no value it cannot be inverted + return + } dir.isInverted = !dir.isInverted dir.firstNode, dir.secondNode = dir.secondNode, dir.firstNode - dir.secondaryField, dir.primaryField = dir.primaryField, dir.secondaryField + dir.secondaryField, dir.primaryField = immutable.Some(dir.primaryField), dir.secondaryField.Value() } type invertibleTypeJoin struct { @@ -474,7 +478,7 @@ type invertibleTypeJoin struct { root planNode subType planNode - rootName string + rootName immutable.Option[string] subTypeName string subSelect *mapper.Select @@ -563,7 +567,9 @@ func (join *invertibleTypeJoin) Next() (bool, error) { if join.isSecondary { secondDocs, err := fetchDocsWithFieldValue( join.dir.secondNode, - join.dir.secondaryField, + // As the join is from the secondary field, we know that [join.dir.secondaryField] must have a value + // otherwise the user would not have been able to request it. + join.dir.secondaryField.Value(), firstDoc.GetID(), join.secondaryFetchLimit, ) @@ -599,8 +605,12 @@ func (join *invertibleTypeJoin) invertJoinDirectionWithIndex( fieldFilter *mapper.Filter, index client.IndexDescription, ) error { + if !join.rootName.HasValue() { + // If the root field has no value it cannot be inverted + return nil + } subScan := getScanNode(join.subType) - subScan.tryAddField(join.rootName + request.RelatedObjectID) + subScan.tryAddField(join.rootName.Value() + request.RelatedObjectID) subScan.filter = fieldFilter subScan.initFetcher(immutable.Option[string]{}, immutable.Some(index)) diff --git a/request/graphql/schema/collection.go b/request/graphql/schema/collection.go index 00a4f6503c..a15c32a061 100644 --- a/request/graphql/schema/collection.go +++ b/request/graphql/schema/collection.go @@ -14,6 +14,7 @@ import ( "context" "fmt" "sort" + "strings" "github.com/sourcenetwork/graphql-go/language/ast" gqlp "github.com/sourcenetwork/graphql-go/language/parser" @@ -51,13 +52,13 @@ func fromAst(doc *ast.Document) ( []client.CollectionDefinition, error, ) { - relationManager := NewRelationManager() definitions := []client.CollectionDefinition{} + cTypeByFieldNameByObjName := map[string]map[string]client.CType{} for _, def := range doc.Definitions { switch defType := def.(type) { case *ast.ObjectDefinition: - description, err := collectionFromAstDefinition(relationManager, defType) + description, err := collectionFromAstDefinition(defType, cTypeByFieldNameByObjName) if err != nil { return nil, err } @@ -65,7 +66,7 @@ func fromAst(doc *ast.Document) ( definitions = append(definitions, description) case *ast.InterfaceDefinition: - description, err := schemaFromAstDefinition(relationManager, defType) + description, err := schemaFromAstDefinition(defType, cTypeByFieldNameByObjName) if err != nil { return nil, err } @@ -87,7 +88,7 @@ func fromAst(doc *ast.Document) ( // The details on the relations between objects depend on both sides // of the relationship. The relation manager handles this, and must be applied // after all the collections have been processed. - err := finalizeRelations(relationManager, definitions) + err := finalizeRelations(definitions, cTypeByFieldNameByObjName) if err != nil { return nil, err } @@ -97,27 +98,38 @@ func fromAst(doc *ast.Document) ( // collectionFromAstDefinition parses a AST object definition into a set of collection descriptions. func collectionFromAstDefinition( - relationManager *RelationManager, def *ast.ObjectDefinition, + cTypeByFieldNameByObjName map[string]map[string]client.CType, ) (client.CollectionDefinition, error) { - fieldDescriptions := []client.SchemaFieldDescription{ + schemaFieldDescriptions := []client.SchemaFieldDescription{ { Name: request.DocIDFieldName, Kind: client.FieldKind_DocID, Typ: client.NONE_CRDT, }, } + collectionFieldDescriptions := []client.CollectionFieldDescription{ + { + Name: request.DocIDFieldName, + }, + } policyDescription := immutable.None[client.PolicyDescription]() indexDescriptions := []client.IndexDescription{} for _, field := range def.Fields { - tmpFieldsDescriptions, err := fieldsFromAST(field, relationManager, def.Name.Value) + tmpSchemaFieldDescriptions, tmpCollectionFieldDescriptions, err := fieldsFromAST( + field, + def.Name.Value, + cTypeByFieldNameByObjName, + false, + ) if err != nil { return client.CollectionDefinition{}, err } - fieldDescriptions = append(fieldDescriptions, tmpFieldsDescriptions...) + schemaFieldDescriptions = append(schemaFieldDescriptions, tmpSchemaFieldDescriptions...) + collectionFieldDescriptions = append(collectionFieldDescriptions, tmpCollectionFieldDescriptions...) for _, directive := range field.Directives { if directive.Name.Value == types.IndexDirectiveLabel { @@ -131,14 +143,23 @@ func collectionFromAstDefinition( } // sort the fields lexicographically - sort.Slice(fieldDescriptions, func(i, j int) bool { + sort.Slice(schemaFieldDescriptions, func(i, j int) bool { // make sure that the _docID is always at the beginning - if fieldDescriptions[i].Name == request.DocIDFieldName { + if schemaFieldDescriptions[i].Name == request.DocIDFieldName { return true - } else if fieldDescriptions[j].Name == request.DocIDFieldName { + } else if schemaFieldDescriptions[j].Name == request.DocIDFieldName { return false } - return fieldDescriptions[i].Name < fieldDescriptions[j].Name + return schemaFieldDescriptions[i].Name < schemaFieldDescriptions[j].Name + }) + sort.Slice(collectionFieldDescriptions, func(i, j int) bool { + // make sure that the _docID is always at the beginning + if collectionFieldDescriptions[i].Name == request.DocIDFieldName { + return true + } else if collectionFieldDescriptions[j].Name == request.DocIDFieldName { + return false + } + return collectionFieldDescriptions[i].Name < collectionFieldDescriptions[j].Name }) for _, directive := range def.Directives { @@ -163,22 +184,24 @@ func collectionFromAstDefinition( Name: immutable.Some(def.Name.Value), Indexes: indexDescriptions, Policy: policyDescription, + Fields: collectionFieldDescriptions, }, Schema: client.SchemaDescription{ Name: def.Name.Value, - Fields: fieldDescriptions, + Fields: schemaFieldDescriptions, }, }, nil } func schemaFromAstDefinition( - relationManager *RelationManager, def *ast.InterfaceDefinition, + cTypeByFieldNameByObjName map[string]map[string]client.CType, ) (client.SchemaDescription, error) { fieldDescriptions := []client.SchemaFieldDescription{} for _, field := range def.Fields { - tmpFieldsDescriptions, err := fieldsFromAST(field, relationManager, def.Name.Value) + // schema-only types do not have collection fields, so we can safely discard any returned here + tmpFieldsDescriptions, _, err := fieldsFromAST(field, def.Name.Value, cTypeByFieldNameByObjName, true) if err != nil { return client.SchemaDescription{}, err } @@ -322,75 +345,110 @@ func indexFromAST(directive *ast.Directive) (client.IndexDescription, error) { return desc, nil } -func fieldsFromAST(field *ast.FieldDefinition, - relationManager *RelationManager, +func fieldsFromAST( + field *ast.FieldDefinition, hostObjectName string, -) ([]client.SchemaFieldDescription, error) { + cTypeByFieldNameByObjName map[string]map[string]client.CType, + schemaOnly bool, +) ([]client.SchemaFieldDescription, []client.CollectionFieldDescription, error) { kind, err := astTypeToKind(field.Type) if err != nil { - return nil, err + return nil, nil, err + } + + cType, err := setCRDTType(field, kind) + if err != nil { + return nil, nil, err } - schema := "" - relationName := "" - relationType := relationType(0) + hostMap := cTypeByFieldNameByObjName[hostObjectName] + if hostMap == nil { + hostMap = map[string]client.CType{} + cTypeByFieldNameByObjName[hostObjectName] = hostMap + } + hostMap[field.Name.Value] = cType - fieldDescriptions := []client.SchemaFieldDescription{} + schemaFieldDescriptions := []client.SchemaFieldDescription{} + collectionFieldDescriptions := []client.CollectionFieldDescription{} if kind.IsObject() { - if !kind.IsArray() { - schema = field.Type.(*ast.Named).Name.Value - relationType = relation_Type_ONE - if _, exists := findDirective(field, "primary"); exists { - relationType |= relation_Type_Primary + relationName, err := getRelationshipName(field, hostObjectName, kind.Underlying()) + if err != nil { + return nil, nil, err + } + + if kind.IsArray() { + if schemaOnly { // todo - document and/or do better + schemaFieldDescriptions = append( + schemaFieldDescriptions, + client.SchemaFieldDescription{ + Name: field.Name.Value, + Kind: kind, + }, + ) + } else { + collectionFieldDescriptions = append( + collectionFieldDescriptions, + client.CollectionFieldDescription{ + Name: field.Name.Value, + Kind: immutable.Some(kind), + RelationName: immutable.Some(relationName), + }, + ) } } else { - schema = field.Type.(*ast.List).Type.(*ast.Named).Name.Value - relationType = relation_Type_MANY - } + idFieldName := fmt.Sprintf("%s_id", field.Name.Value) + + collectionFieldDescriptions = append( + collectionFieldDescriptions, + client.CollectionFieldDescription{ + Name: idFieldName, + Kind: immutable.Some[client.FieldKind](client.FieldKind_DocID), + RelationName: immutable.Some(relationName), + }, + ) - relationName, err = getRelationshipName(field, hostObjectName, schema) - if err != nil { - return nil, err - } + collectionFieldDescriptions = append( + collectionFieldDescriptions, + client.CollectionFieldDescription{ + Name: field.Name.Value, + Kind: immutable.Some(kind), + RelationName: immutable.Some(relationName), + }, + ) - if !kind.IsArray() { - // An _id field is added for every 1-N relationship from this object. - fieldDescriptions = append(fieldDescriptions, client.SchemaFieldDescription{ - Name: fmt.Sprintf("%s_id", field.Name.Value), - Kind: client.FieldKind_DocID, - Typ: defaultCRDTForFieldKind[client.FieldKind_DocID], - RelationName: relationName, - }) + if _, exists := findDirective(field, "primary"); exists { + // Only primary fields exist on the schema. If primary is automatically set + // (e.g. for one-many) a later step will add this property. + schemaFieldDescriptions = append( + schemaFieldDescriptions, + client.SchemaFieldDescription{ + Name: field.Name.Value, + Kind: kind, + Typ: cType, + }, + ) + } } - - // Register the relationship so that the relationship manager can evaluate - // relationsip properties dependent on both collections in the relationship. - _, err := relationManager.RegisterSingle( - relationName, - schema, - field.Name.Value, - relationType, + } else { + schemaFieldDescriptions = append( + schemaFieldDescriptions, + client.SchemaFieldDescription{ + Name: field.Name.Value, + Kind: kind, + Typ: cType, + }, ) - if err != nil { - return nil, err - } - } - cType, err := setCRDTType(field, kind) - if err != nil { - return nil, err - } - - fieldDescription := client.SchemaFieldDescription{ - Name: field.Name.Value, - Kind: kind, - Typ: cType, - RelationName: relationName, + collectionFieldDescriptions = append( + collectionFieldDescriptions, + client.CollectionFieldDescription{ + Name: field.Name.Value, + }, + ) } - fieldDescriptions = append(fieldDescriptions, fieldDescription) - return fieldDescriptions, nil + return schemaFieldDescriptions, collectionFieldDescriptions, nil } // policyFromAST returns the policy description after parsing but the validation @@ -556,7 +614,23 @@ func getRelationshipName( return genRelationName(hostName, targetName) } -func finalizeRelations(relationManager *RelationManager, definitions []client.CollectionDefinition) error { +func genRelationName(t1, t2 string) (string, error) { + if t1 == "" || t2 == "" { + return "", client.NewErrUninitializeProperty("genRelationName", "relation types") + } + t1 = strings.ToLower(t1) + t2 = strings.ToLower(t2) + + if i := strings.Compare(t1, t2); i < 0 { + return fmt.Sprintf("%s_%s", t1, t2), nil + } + return fmt.Sprintf("%s_%s", t2, t1), nil +} + +func finalizeRelations( + definitions []client.CollectionDefinition, + cTypeByFieldNameByObjName map[string]map[string]client.CType, +) error { embeddedObjNames := map[string]struct{}{} for _, def := range definitions { if !def.Description.Name.HasValue() { @@ -564,35 +638,91 @@ func finalizeRelations(relationManager *RelationManager, definitions []client.Co } } - for _, definition := range definitions { - for i, field := range definition.Schema.Fields { - if field.RelationName == "" || field.Kind == client.FieldKind_DocID { + for i, definition := range definitions { + if _, ok := embeddedObjNames[definition.Description.Name.Value()]; ok { + // Embedded objects are simpler and require no addition work + continue + } + + for _, field := range definition.Description.Fields { + if !field.Kind.HasValue() || !field.Kind.Value().IsObject() || field.Kind.Value().IsArray() { + // We only need to process the primary side of a relation here, if the field is not a relation + // or if it is an array, we can skip it. continue } - rel, err := relationManager.GetRelation(field.RelationName) - if err != nil { - return err + var otherColDefinition immutable.Option[client.CollectionDefinition] + for _, otherDef := range definitions { + // Check the 'other' schema name, there can only be a one-one mapping in an SDL + // appart from embedded, which will be schema only. + if otherDef.Schema.Name == field.Kind.Value().Underlying() { + otherColDefinition = immutable.Some(otherDef) + break + } } - _, fieldRelationType, ok := rel.getField(field.Kind.Underlying(), field.Name) - if !ok { - return NewErrRelationMissingField(field.Kind.Underlying(), field.Name) + if !otherColDefinition.HasValue() { + // If the other collection is not found here we skip this field. Whilst this almost certainly means the SDL + // is invalid, validating anything beyond SDL syntax is not the responsibility of this package. + continue } - // if not finalized then we are missing one side of the relationship - // unless this is an embedded object, which only have single-sided relations - _, shouldBeOneSidedRelation := embeddedObjNames[field.Kind.Underlying()] - if shouldBeOneSidedRelation && rel.finalized { - return NewErrViewRelationMustBeOneSided(field.Name, field.Kind.Underlying()) + var otherColFieldDescription immutable.Option[client.CollectionFieldDescription] + for _, otherField := range otherColDefinition.Value().Description.Fields { + if otherField.RelationName.Value() == field.RelationName.Value() { + otherColFieldDescription = immutable.Some(otherField) + break + } + } + + if !otherColFieldDescription.HasValue() || otherColFieldDescription.Value().Kind.Value().IsArray() { + // Relations only defined on one side of the object are possible, and so if this is one of them + // or if the other side is an array, we need to add the field to the schema (is primary side). + definition.Schema.Fields = append( + definition.Schema.Fields, + client.SchemaFieldDescription{ + Name: field.Name, + Kind: field.Kind.Value(), + Typ: cTypeByFieldNameByObjName[definition.Schema.Name][field.Name], + }, + ) } - if !shouldBeOneSidedRelation && !rel.finalized { - return client.NewErrRelationOneSided(field.Name, field.Kind.Underlying()) + otherIsEmbedded := len(otherColDefinition.Value().Description.Fields) == 0 + if !otherIsEmbedded { + var schemaFieldIndex int + var schemaFieldExists bool + for i, schemaField := range definition.Schema.Fields { + if schemaField.Name == field.Name { + schemaFieldIndex = i + schemaFieldExists = true + break + } + } + + if schemaFieldExists { + idFieldName := fmt.Sprintf("%s_id", field.Name) + + if _, idFieldExists := definition.Schema.GetFieldByName(idFieldName); !idFieldExists { + existingFields := definition.Schema.Fields + definition.Schema.Fields = make([]client.SchemaFieldDescription, len(definition.Schema.Fields)+1) + copy(definition.Schema.Fields, existingFields[:schemaFieldIndex+1]) + copy(definition.Schema.Fields[schemaFieldIndex+2:], existingFields[schemaFieldIndex+1:]) + + // An _id field is added for every 1-1 or 1-N relationship from this object if the relation + // does not point to an embedded object. + // + // It is inserted immediately after the object field for make things nicer for the user. + definition.Schema.Fields[schemaFieldIndex+1] = client.SchemaFieldDescription{ + Name: idFieldName, + Kind: client.FieldKind_DocID, + Typ: defaultCRDTForFieldKind[client.FieldKind_DocID], + } + } + } } - field.IsPrimaryRelation = fieldRelationType.isSet(relation_Type_Primary) - definition.Schema.Fields[i] = field + definitions[i] = definition } } diff --git a/request/graphql/schema/descriptions_test.go b/request/graphql/schema/descriptions_test.go index 354109965c..320bef158a 100644 --- a/request/graphql/schema/descriptions_test.go +++ b/request/graphql/schema/descriptions_test.go @@ -36,6 +36,20 @@ func TestSingleSimpleType(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("User"), Indexes: []client.IndexDescription{}, + Fields: []client.CollectionFieldDescription{ + { + Name: "_docID", + }, + { + Name: "age", + }, + { + Name: "name", + }, + { + Name: "verified", + }, + }, }, Schema: client.SchemaDescription{ Name: "User", @@ -85,6 +99,20 @@ func TestSingleSimpleType(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("User"), Indexes: []client.IndexDescription{}, + Fields: []client.CollectionFieldDescription{ + { + Name: "_docID", + }, + { + Name: "age", + }, + { + Name: "name", + }, + { + Name: "verified", + }, + }, }, Schema: client.SchemaDescription{ Name: "User", @@ -116,6 +144,20 @@ func TestSingleSimpleType(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("Author"), Indexes: []client.IndexDescription{}, + Fields: []client.CollectionFieldDescription{ + { + Name: "_docID", + }, + { + Name: "name", + }, + { + Name: "publisher", + }, + { + Name: "rating", + }, + }, }, Schema: client.SchemaDescription{ Name: "Author", @@ -165,131 +207,75 @@ func TestSingleSimpleType(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("Book"), Indexes: []client.IndexDescription{}, - }, - Schema: client.SchemaDescription{ - Name: "Book", - Fields: []client.SchemaFieldDescription{ + Fields: []client.CollectionFieldDescription{ { Name: "_docID", - Kind: client.FieldKind_DocID, - Typ: client.NONE_CRDT, }, { Name: "author", - RelationName: "author_book", - Kind: client.ObjectKind("Author"), - Typ: client.NONE_CRDT, + Kind: immutable.Some[client.FieldKind](client.ObjectKind("Author")), + RelationName: immutable.Some("author_book"), }, { - Name: "author_id", - Kind: client.FieldKind_DocID, - Typ: client.LWW_REGISTER, + Name: "author_id", + Kind: immutable.Some[client.FieldKind](client.FieldKind_DocID), + RelationName: immutable.Some("author_book"), }, { Name: "name", - Kind: client.FieldKind_NILLABLE_STRING, - Typ: client.LWW_REGISTER, }, { Name: "rating", - Kind: client.FieldKind_NILLABLE_FLOAT, - Typ: client.LWW_REGISTER, }, }, }, - }, - { - Description: client.CollectionDescription{ - Name: immutable.Some("Author"), - Indexes: []client.IndexDescription{}, - }, Schema: client.SchemaDescription{ - Name: "Author", + Name: "Book", Fields: []client.SchemaFieldDescription{ { Name: "_docID", Kind: client.FieldKind_DocID, Typ: client.NONE_CRDT, }, - { - Name: "age", - Kind: client.FieldKind_NILLABLE_INT, - Typ: client.LWW_REGISTER, - }, { Name: "name", Kind: client.FieldKind_NILLABLE_STRING, Typ: client.LWW_REGISTER, }, { - Name: "published", - RelationName: "author_book", - Kind: client.ObjectKind("Book"), - Typ: client.NONE_CRDT, - IsPrimaryRelation: true, - }, - { - Name: "published_id", - Kind: client.FieldKind_DocID, + Name: "rating", + Kind: client.FieldKind_NILLABLE_FLOAT, Typ: client.LWW_REGISTER, }, }, }, }, - }, - }, - { - description: "Multiple simple types", - sdl: ` - type User { - name: String - age: Int - verified: Boolean - } - - type Author { - name: String - publisher: String - rating: Float - } - `, - targetDescs: []client.CollectionDefinition{ { Description: client.CollectionDescription{ - Name: immutable.Some("User"), + Name: immutable.Some("Author"), Indexes: []client.IndexDescription{}, - }, - Schema: client.SchemaDescription{ - Name: "User", - Fields: []client.SchemaFieldDescription{ + Fields: []client.CollectionFieldDescription{ { Name: "_docID", - Kind: client.FieldKind_DocID, - Typ: client.NONE_CRDT, }, { Name: "age", - Kind: client.FieldKind_NILLABLE_INT, - Typ: client.LWW_REGISTER, }, { Name: "name", - Kind: client.FieldKind_NILLABLE_STRING, - Typ: client.LWW_REGISTER, }, { - Name: "verified", - Kind: client.FieldKind_NILLABLE_BOOL, - Typ: client.LWW_REGISTER, + Name: "published", + Kind: immutable.Some[client.FieldKind](client.ObjectKind("Book")), + RelationName: immutable.Some("author_book"), + }, + { + Name: "published_id", + Kind: immutable.Some[client.FieldKind](client.FieldKind_DocID), + RelationName: immutable.Some("author_book"), }, }, }, - }, - { - Description: client.CollectionDescription{ - Name: immutable.Some("Author"), - Indexes: []client.IndexDescription{}, - }, Schema: client.SchemaDescription{ Name: "Author", Fields: []client.SchemaFieldDescription{ @@ -298,19 +284,24 @@ func TestSingleSimpleType(t *testing.T) { Kind: client.FieldKind_DocID, Typ: client.NONE_CRDT, }, + { + Name: "age", + Kind: client.FieldKind_NILLABLE_INT, + Typ: client.LWW_REGISTER, + }, { Name: "name", Kind: client.FieldKind_NILLABLE_STRING, Typ: client.LWW_REGISTER, }, { - Name: "publisher", - Kind: client.FieldKind_NILLABLE_STRING, + Name: "published", + Kind: client.ObjectKind("Book"), Typ: client.LWW_REGISTER, }, { - Name: "rating", - Kind: client.FieldKind_NILLABLE_FLOAT, + Name: "published_id", + Kind: client.FieldKind_DocID, Typ: client.LWW_REGISTER, }, }, @@ -338,25 +329,35 @@ func TestSingleSimpleType(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("Book"), Indexes: []client.IndexDescription{}, - }, - Schema: client.SchemaDescription{ - Name: "Book", - Fields: []client.SchemaFieldDescription{ + Fields: []client.CollectionFieldDescription{ { Name: "_docID", - Kind: client.FieldKind_DocID, - Typ: client.NONE_CRDT, }, { Name: "author", - RelationName: "book_authors", - Kind: client.ObjectKind("Author"), - Typ: client.NONE_CRDT, + Kind: immutable.Some[client.FieldKind](client.ObjectKind("Author")), + RelationName: immutable.Some("book_authors"), }, { - Name: "author_id", + Name: "author_id", + Kind: immutable.Some[client.FieldKind](client.FieldKind_DocID), + RelationName: immutable.Some("book_authors"), + }, + { + Name: "name", + }, + { + Name: "rating", + }, + }, + }, + Schema: client.SchemaDescription{ + Name: "Book", + Fields: []client.SchemaFieldDescription{ + { + Name: "_docID", Kind: client.FieldKind_DocID, - Typ: client.LWW_REGISTER, + Typ: client.NONE_CRDT, }, { Name: "name", @@ -375,6 +376,27 @@ func TestSingleSimpleType(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("Author"), Indexes: []client.IndexDescription{}, + Fields: []client.CollectionFieldDescription{ + { + Name: "_docID", + }, + { + Name: "age", + }, + { + Name: "name", + }, + { + Name: "published", + Kind: immutable.Some[client.FieldKind](client.ObjectKind("Book")), + RelationName: immutable.Some("book_authors"), + }, + { + Name: "published_id", + Kind: immutable.Some[client.FieldKind](client.FieldKind_DocID), + RelationName: immutable.Some("book_authors"), + }, + }, }, Schema: client.SchemaDescription{ Name: "Author", @@ -395,11 +417,9 @@ func TestSingleSimpleType(t *testing.T) { Typ: client.LWW_REGISTER, }, { - Name: "published", - RelationName: "book_authors", - Kind: client.ObjectKind("Book"), - Typ: client.NONE_CRDT, - IsPrimaryRelation: true, + Name: "published", + Kind: client.ObjectKind("Book"), + Typ: client.LWW_REGISTER, }, { Name: "published_id", @@ -431,6 +451,27 @@ func TestSingleSimpleType(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("Book"), Indexes: []client.IndexDescription{}, + Fields: []client.CollectionFieldDescription{ + { + Name: "_docID", + }, + { + Name: "author", + Kind: immutable.Some[client.FieldKind](client.ObjectKind("Author")), + RelationName: immutable.Some("author_book"), + }, + { + Name: "author_id", + Kind: immutable.Some[client.FieldKind](client.FieldKind_DocID), + RelationName: immutable.Some("author_book"), + }, + { + Name: "name", + }, + { + Name: "rating", + }, + }, }, Schema: client.SchemaDescription{ Name: "Book", @@ -441,11 +482,9 @@ func TestSingleSimpleType(t *testing.T) { Typ: client.NONE_CRDT, }, { - Name: "author", - RelationName: "author_book", - Kind: client.ObjectKind("Author"), - Typ: client.NONE_CRDT, - IsPrimaryRelation: true, + Name: "author", + Kind: client.ObjectKind("Author"), + Typ: client.LWW_REGISTER, }, { Name: "author_id", @@ -469,6 +508,27 @@ func TestSingleSimpleType(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("Author"), Indexes: []client.IndexDescription{}, + Fields: []client.CollectionFieldDescription{ + { + Name: "_docID", + }, + { + Name: "age", + }, + { + Name: "name", + }, + { + Name: "published", + Kind: immutable.Some[client.FieldKind](client.ObjectKind("Book")), + RelationName: immutable.Some("author_book"), + }, + { + Name: "published_id", + Kind: immutable.Some[client.FieldKind](client.FieldKind_DocID), + RelationName: immutable.Some("author_book"), + }, + }, }, Schema: client.SchemaDescription{ Name: "Author", @@ -488,17 +548,6 @@ func TestSingleSimpleType(t *testing.T) { Kind: client.FieldKind_NILLABLE_STRING, Typ: client.LWW_REGISTER, }, - { - Name: "published", - RelationName: "author_book", - Kind: client.ObjectKind("Book"), - Typ: client.NONE_CRDT, - }, - { - Name: "published_id", - Kind: client.FieldKind_DocID, - Typ: client.LWW_REGISTER, - }, }, }, }, @@ -524,6 +573,27 @@ func TestSingleSimpleType(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("Book"), Indexes: []client.IndexDescription{}, + Fields: []client.CollectionFieldDescription{ + { + Name: "_docID", + }, + { + Name: "author", + Kind: immutable.Some[client.FieldKind](client.ObjectKind("Author")), + RelationName: immutable.Some("author_book"), + }, + { + Name: "author_id", + Kind: immutable.Some[client.FieldKind](client.FieldKind_DocID), + RelationName: immutable.Some("author_book"), + }, + { + Name: "name", + }, + { + Name: "rating", + }, + }, }, Schema: client.SchemaDescription{ Name: "Book", @@ -534,25 +604,23 @@ func TestSingleSimpleType(t *testing.T) { Typ: client.NONE_CRDT, }, { - Name: "author", - RelationName: "author_book", - Kind: client.ObjectKind("Author"), - Typ: client.NONE_CRDT, - IsPrimaryRelation: true, + Name: "name", + Kind: client.FieldKind_NILLABLE_STRING, + Typ: client.LWW_REGISTER, }, { - Name: "author_id", - Kind: client.FieldKind_DocID, + Name: "rating", + Kind: client.FieldKind_NILLABLE_FLOAT, Typ: client.LWW_REGISTER, }, { - Name: "name", - Kind: client.FieldKind_NILLABLE_STRING, + Name: "author", + Kind: client.ObjectKind("Author"), Typ: client.LWW_REGISTER, }, { - Name: "rating", - Kind: client.FieldKind_NILLABLE_FLOAT, + Name: "author_id", + Kind: client.FieldKind_DocID, Typ: client.LWW_REGISTER, }, }, @@ -562,6 +630,22 @@ func TestSingleSimpleType(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("Author"), Indexes: []client.IndexDescription{}, + Fields: []client.CollectionFieldDescription{ + { + Name: "_docID", + }, + { + Name: "age", + }, + { + Name: "name", + }, + { + Name: "published", + Kind: immutable.Some[client.FieldKind](client.ObjectArrayKind("Book")), + RelationName: immutable.Some("author_book"), + }, + }, }, Schema: client.SchemaDescription{ Name: "Author", @@ -581,12 +665,6 @@ func TestSingleSimpleType(t *testing.T) { Kind: client.FieldKind_NILLABLE_STRING, Typ: client.LWW_REGISTER, }, - { - Name: "published", - RelationName: "author_book", - Kind: client.ObjectArrayKind("Book"), - Typ: client.NONE_CRDT, - }, }, }, }, @@ -608,6 +686,7 @@ func runCreateDescriptionTest(t *testing.T, testcase descriptionTestCase) { for i, d := range descs { assert.Equal(t, testcase.targetDescs[i].Description, d.Description, testcase.description) + assert.Equal(t, testcase.targetDescs[i].Schema, d.Schema, testcase.description) } } diff --git a/request/graphql/schema/errors.go b/request/graphql/schema/errors.go index 01f6e9bc9b..304df792e6 100644 --- a/request/graphql/schema/errors.go +++ b/request/graphql/schema/errors.go @@ -30,7 +30,6 @@ const ( errPolicyUnknownArgument string = "policy with unknown argument" errPolicyInvalidIDProp string = "policy directive with invalid id property" errPolicyInvalidResourceProp string = "policy directive with invalid resource property" - errViewRelationMustBeOneSided string = "relations in views must only be defined on one schema" ) var ( @@ -50,14 +49,13 @@ var ( ErrMultipleRelationPrimaries = errors.New("relation can only have a single field set as primary") // NonNull is the literal name of the GQL type, so we have to disable the linter //nolint:revive - ErrNonNullNotSupported = errors.New("NonNull fields are not currently supported") - ErrIndexMissingFields = errors.New(errIndexMissingFields) - ErrIndexWithUnknownArg = errors.New(errIndexUnknownArgument) - ErrIndexWithInvalidArg = errors.New(errIndexInvalidArgument) - ErrPolicyWithUnknownArg = errors.New(errPolicyUnknownArgument) - ErrPolicyInvalidIDProp = errors.New(errPolicyInvalidIDProp) - ErrPolicyInvalidResourceProp = errors.New(errPolicyInvalidResourceProp) - ErrViewRelationMustBeOneSided = errors.New(errViewRelationMustBeOneSided) + ErrNonNullNotSupported = errors.New("NonNull fields are not currently supported") + ErrIndexMissingFields = errors.New(errIndexMissingFields) + ErrIndexWithUnknownArg = errors.New(errIndexUnknownArgument) + ErrIndexWithInvalidArg = errors.New(errIndexInvalidArgument) + ErrPolicyWithUnknownArg = errors.New(errPolicyUnknownArgument) + ErrPolicyInvalidIDProp = errors.New(errPolicyInvalidIDProp) + ErrPolicyInvalidResourceProp = errors.New(errPolicyInvalidResourceProp) ) func NewErrDuplicateField(objectName, fieldName string) error { @@ -138,11 +136,3 @@ func NewErrRelationNotFound(relationName string) error { errors.NewKV("RelationName", relationName), ) } - -func NewErrViewRelationMustBeOneSided(fieldName string, typeName string) error { - return errors.New( - errViewRelationMustBeOneSided, - errors.NewKV("Field", fieldName), - errors.NewKV("Type", typeName), - ) -} diff --git a/request/graphql/schema/generate.go b/request/graphql/schema/generate.go index fc706041d8..4b0b2bdec2 100644 --- a/request/graphql/schema/generate.go +++ b/request/graphql/schema/generate.go @@ -414,7 +414,7 @@ func (g *Generator) buildTypes( // will be reassigned before the thunk is run // TODO remove when Go 1.22 collection := c - fieldDescriptions := collection.Schema.Fields + fieldDescriptions := collection.GetFields() isEmbeddedObject := !collection.Description.Name.HasValue() isQuerySource := len(collection.Description.QuerySources()) > 0 isViewObject := isEmbeddedObject || isQuerySource diff --git a/request/graphql/schema/relations.go b/request/graphql/schema/relations.go deleted file mode 100644 index 6d548ceebe..0000000000 --- a/request/graphql/schema/relations.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2022 Democratized Data Foundation -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package schema - -import ( - "fmt" - "strings" - - "github.com/sourcenetwork/defradb/client" -) - -// relationType describes the type of relation between two types. -type relationType uint8 - -const ( - relation_Type_ONE relationType = 1 // 0b0000 0001 - relation_Type_MANY relationType = 2 // 0b0000 0010 - relation_Type_Primary relationType = 128 // 0b1000 0000 Primary reference entity on relation -) - -// IsSet returns true if the target relation type is set. -func (m relationType) isSet(target relationType) bool { - return m&target > 0 -} - -// RelationManager keeps track of all the relations that exist -// between schema types -type RelationManager struct { - relations map[string]*Relation -} - -func NewRelationManager() *RelationManager { - return &RelationManager{ - relations: make(map[string]*Relation), - } -} - -func (rm *RelationManager) GetRelation(name string) (*Relation, error) { - rel, ok := rm.relations[name] - if !ok { - return nil, NewErrRelationNotFound(name) - } - return rel, nil -} - -// RegisterSingle is used if you only know a single side of the relation -// at a time. It allows you to iteratively, across two calls, build the relation. -// If the relation exists and is finalized, then nothing is done. Returns true -// if nothing is done or the relation is successfully registered. -func (rm *RelationManager) RegisterSingle( - name string, - schemaType string, - schemaField string, - relType relationType, -) (bool, error) { - if name == "" { - return false, client.NewErrUninitializeProperty("RegisterSingle", "name") - } - - rel, ok := rm.relations[name] - if !ok { - // If a relation doesn't exist then make one. - rm.relations[name] = &Relation{ - name: name, - types: []relationType{relType}, - schemaTypes: []string{schemaType}, - fields: []string{schemaField}, - } - return true, nil - } - - if !rel.finalized { - // If a relation exists, and is not finalized, then finalizing it. - rel.types = append(rel.types, relType) - rel.schemaTypes = append(rel.schemaTypes, schemaType) - rel.fields = append(rel.fields, schemaField) - - if err := rel.finalize(); err != nil { - return false, err - } - rm.relations[name] = rel - } - - return true, nil -} - -type Relation struct { - name string - types []relationType - schemaTypes []string - fields []string - - // finalized indicates if we've properly - // updated both sides of the relation - finalized bool -} - -func (r *Relation) finalize() error { - // make sure all the types/fields are set - if len(r.types) != 2 || len(r.schemaTypes) != 2 || len(r.fields) != 2 { - return ErrRelationMissingTypes - } - - if isOne(r.types[0]) && isMany(r.types[1]) { - r.types[0] |= relation_Type_Primary // set primary on one - r.types[1] &^= relation_Type_Primary // clear primary on many - } else if isOne(r.types[1]) && isMany(r.types[0]) { - r.types[1] |= relation_Type_Primary // set primary on one - r.types[0] &^= relation_Type_Primary // clear primary on many - } else if isOne(r.types[1]) && isOne(r.types[0]) { - t1, t2 := r.types[0], r.types[1] - aBit := t1 & t2 - xBit := t1 ^ t2 - - // both types have primary set - if aBit.isSet(relation_Type_Primary) { - return ErrMultipleRelationPrimaries - } else if !xBit.isSet(relation_Type_Primary) { - return client.NewErrPrimarySideNotDefined(r.name) - } - } - - r.finalized = true - return nil -} - -func (r Relation) getField(schemaType string, field string) (string, relationType, bool) { - for i, f := range r.fields { - if f == field && r.schemaTypes[i] == schemaType { - return f, r.types[i], true - } - } - return "", relationType(0), false -} - -func genRelationName(t1, t2 string) (string, error) { - if t1 == "" || t2 == "" { - return "", client.NewErrUninitializeProperty("genRelationName", "relation types") - } - t1 = strings.ToLower(t1) - t2 = strings.ToLower(t2) - - if i := strings.Compare(t1, t2); i < 0 { - return fmt.Sprintf("%s_%s", t1, t2), nil - } - return fmt.Sprintf("%s_%s", t2, t1), nil -} - -// isOne returns true if the Relation_ONE bit is set -func isOne(fieldmeta relationType) bool { - return fieldmeta.isSet(relation_Type_ONE) -} - -// isMany returns true if the Relation_ONE bit is set -func isMany(fieldmeta relationType) bool { - return fieldmeta.isSet(relation_Type_MANY) -} diff --git a/tests/bench/bench_util.go b/tests/bench/bench_util.go index dac81d0ce2..186dbc0f3e 100644 --- a/tests/bench/bench_util.go +++ b/tests/bench/bench_util.go @@ -159,7 +159,7 @@ func BackfillBenchmarkDB( // create the documents docIDs := make([]client.DocID, numTypes) for j := 0; j < numTypes; j++ { - doc, err := client.NewDocFromJSON([]byte(docs[j]), cols[j].Schema()) + doc, err := client.NewDocFromJSON([]byte(docs[j]), cols[j].Definition()) if err != nil { errCh <- errors.Wrap("failed to create document from fixture", err) return diff --git a/tests/bench/collection/utils.go b/tests/bench/collection/utils.go index 59ab0577ba..24c90b28b5 100644 --- a/tests/bench/collection/utils.go +++ b/tests/bench/collection/utils.go @@ -178,7 +178,7 @@ func runCollectionBenchCreateMany( docs := make([]*client.Document, opCount) for j := 0; j < opCount; j++ { d, _ := fixture.GenerateDocs() - docs[j], _ = client.NewDocFromJSON([]byte(d[0]), collections[0].Schema()) + docs[j], _ = client.NewDocFromJSON([]byte(d[0]), collections[0].Definition()) } collections[0].CreateMany(ctx, docs) //nolint:errcheck @@ -201,7 +201,7 @@ func runCollectionBenchCreateSync(b *testing.B, for j := 0; j < runs; j++ { docs, _ := fixture.GenerateDocs() for k := 0; k < numTypes; k++ { - doc, _ := client.NewDocFromJSON([]byte(docs[k]), collections[k].Schema()) + doc, _ := client.NewDocFromJSON([]byte(docs[k]), collections[k].Definition()) collections[k].Create(ctx, doc) //nolint:errcheck } } @@ -240,7 +240,7 @@ func runCollectionBenchCreateAsync(b *testing.B, docs, _ := fixture.GenerateDocs() // create the documents for j := 0; j < numTypes; j++ { - doc, _ := client.NewDocFromJSON([]byte(docs[j]), collections[j].Schema()) + doc, _ := client.NewDocFromJSON([]byte(docs[j]), collections[j].Definition()) collections[j].Create(ctx, doc) //nolint:errcheck } diff --git a/tests/clients/cli/wrapper_collection.go b/tests/clients/cli/wrapper_collection.go index 4ff8692561..6a1764cc27 100644 --- a/tests/clients/cli/wrapper_collection.go +++ b/tests/clients/cli/wrapper_collection.go @@ -395,7 +395,7 @@ func (c *Collection) Get( if err != nil { return nil, err } - doc := client.NewDocWithID(docID, c.Schema()) + doc := client.NewDocWithID(docID, c.Definition()) err = doc.SetWithJSON(data) if err != nil { return nil, err diff --git a/tests/gen/gen_auto.go b/tests/gen/gen_auto.go index 9b4acc440d..487558e934 100644 --- a/tests/gen/gen_auto.go +++ b/tests/gen/gen_auto.go @@ -119,7 +119,7 @@ func (g *randomDocGenerator) getMaxTotalDemand() int { } // getNextPrimaryDocID returns the docID of the next primary document to be used as a relation. -func (g *randomDocGenerator) getNextPrimaryDocID(secondaryType string, field *client.SchemaFieldDescription) string { +func (g *randomDocGenerator) getNextPrimaryDocID(secondaryType string, field *client.FieldDefinition) string { ind := g.configurator.usageCounter.getNextTypeIndForField(secondaryType, field) return g.generatedDocs[field.Kind.Underlying()][ind].docID } @@ -134,12 +134,12 @@ func (g *randomDocGenerator) generateRandomDocs(order []string) error { totalDemand := currentTypeDemand.getAverage() for i := 0; i < totalDemand; i++ { newDoc := make(map[string]any) - for _, field := range typeDef.Schema.Fields { + for _, field := range typeDef.GetFields() { if field.Name == request.DocIDFieldName { continue } if field.IsRelation() { - if field.IsPrimaryRelation { + if field.IsPrimaryRelation && field.Kind.IsObject() { if strings.HasSuffix(field.Name, request.RelatedObjectID) { newDoc[field.Name] = g.getNextPrimaryDocID(typeName, &field) } else { @@ -151,7 +151,7 @@ func (g *randomDocGenerator) generateRandomDocs(order []string) error { newDoc[field.Name] = g.generateRandomValue(typeName, field.Kind, fieldConf) } } - doc, err := client.NewDocFromMap(newDoc, typeDef.Schema) + doc, err := client.NewDocFromMap(newDoc, typeDef) if err != nil { return err } @@ -221,7 +221,7 @@ func validateDefinitions(definitions []client.CollectionDefinition) error { if def.Description.Name.Value() != def.Schema.Name { return NewErrIncompleteColDefinition("description name and schema name do not match") } - for _, field := range def.Schema.Fields { + for _, field := range def.GetFields() { if field.Name == "" { return NewErrIncompleteColDefinition("field name is empty") } diff --git a/tests/gen/gen_auto_config.go b/tests/gen/gen_auto_config.go index eab85dd318..b69dfb0b98 100644 --- a/tests/gen/gen_auto_config.go +++ b/tests/gen/gen_auto_config.go @@ -58,11 +58,12 @@ func validateConfig(types map[string]client.CollectionDefinition, configsMap con return newNotDefinedTypeErr(typeName) } for fieldName, fieldConfig := range typeConfigs { - fieldDef, hasField := typeDef.Schema.GetFieldByName(fieldName) + fieldDef, hasField := typeDef.GetFieldByName(fieldName) if !hasField { return NewErrInvalidConfiguration("field " + fieldName + " is not defined in the schema for type " + typeName) } + err := checkAndValidateMinMax(&fieldDef, &fieldConfig) if err != nil { return err @@ -82,7 +83,7 @@ func validateConfig(types map[string]client.CollectionDefinition, configsMap con return nil } -func checkAndValidateMinMax(field *client.SchemaFieldDescription, conf *genConfig) error { +func checkAndValidateMinMax(field *client.FieldDefinition, conf *genConfig) error { _, hasMin := conf.props["min"] if hasMin { var err error @@ -100,7 +101,7 @@ func checkAndValidateMinMax(field *client.SchemaFieldDescription, conf *genConfi return nil } -func checkAndValidateLen(field *client.SchemaFieldDescription, conf *genConfig) error { +func checkAndValidateLen(field *client.FieldDefinition, conf *genConfig) error { lenConf, hasLen := conf.props["len"] if hasLen { if field.Kind != client.FieldKind_NILLABLE_STRING { @@ -117,7 +118,7 @@ func checkAndValidateLen(field *client.SchemaFieldDescription, conf *genConfig) return nil } -func checkAndValidateRatio(field *client.SchemaFieldDescription, conf *genConfig) error { +func checkAndValidateRatio(field *client.FieldDefinition, conf *genConfig) error { ratioConf, hasRatio := conf.props["ratio"] if hasRatio { if field.Kind != client.FieldKind_NILLABLE_BOOL { diff --git a/tests/gen/gen_auto_configurator.go b/tests/gen/gen_auto_configurator.go index 7a17d74989..ec8c1ea881 100644 --- a/tests/gen/gen_auto_configurator.go +++ b/tests/gen/gen_auto_configurator.go @@ -65,7 +65,7 @@ func newTypeUsageCounter(random *rand.Rand) typeUsageCounters { // addRelationUsage adds a relation usage tracker for a foreign field. func (c *typeUsageCounters) addRelationUsage( secondaryType string, - field client.SchemaFieldDescription, + field client.FieldDefinition, minPerDoc, maxPerDoc, numDocs int, ) { primaryType := field.Kind.Underlying() @@ -81,7 +81,7 @@ func (c *typeUsageCounters) addRelationUsage( } // getNextTypeIndForField returns the next index to be used for a foreign field. -func (c *typeUsageCounters) getNextTypeIndForField(secondaryType string, field *client.SchemaFieldDescription) int { +func (c *typeUsageCounters) getNextTypeIndForField(secondaryType string, field *client.FieldDefinition) int { current := c.m[field.Kind.Underlying()][secondaryType][field.Name] return current.useNextDocIDIndex() } @@ -272,7 +272,7 @@ func (g *docsGenConfigurator) getDemandForPrimaryType( primaryGraph map[string][]string, ) (typeDemand, error) { primaryTypeDef := g.types[primaryType] - for _, field := range primaryTypeDef.Schema.Fields { + for _, field := range primaryTypeDef.GetFields() { if field.Kind.IsObject() && field.Kind.Underlying() == secondaryType { primaryDemand := typeDemand{min: secondaryDemand.min, max: secondaryDemand.max} minPerDoc, maxPerDoc := 1, 1 @@ -338,7 +338,7 @@ func (g *docsGenConfigurator) calculateDemandForSecondaryTypes( primaryGraph map[string][]string, ) error { typeDef := g.types[typeName] - for _, field := range typeDef.Schema.Fields { + for _, field := range typeDef.GetFields() { if field.Kind.IsObject() && !field.IsPrimaryRelation { primaryDocDemand := g.docsDemand[typeName] newSecDemand := typeDemand{min: primaryDocDemand.min, max: primaryDocDemand.max} @@ -401,7 +401,7 @@ func (g *docsGenConfigurator) calculateDemandForSecondaryTypes( func (g *docsGenConfigurator) initRelationUsages(secondaryType, primaryType string, minPerDoc, maxPerDoc int) { secondaryTypeDef := g.types[secondaryType] - for _, secondaryTypeField := range secondaryTypeDef.Schema.Fields { + for _, secondaryTypeField := range secondaryTypeDef.GetFields() { if secondaryTypeField.Kind.Underlying() == primaryType { g.usageCounter.addRelationUsage(secondaryType, secondaryTypeField, minPerDoc, maxPerDoc, g.docsDemand[primaryType].getAverage()) @@ -422,7 +422,7 @@ func getRelationGraph(types map[string]client.CollectionDefinition) map[string][ } for typeName, typeDef := range types { - for _, field := range typeDef.Schema.Fields { + for _, field := range typeDef.GetFields() { if field.Kind.IsObject() { if field.IsPrimaryRelation { primaryGraph[typeName] = appendUnique(primaryGraph[typeName], field.Kind.Underlying()) diff --git a/tests/gen/gen_auto_test.go b/tests/gen/gen_auto_test.go index 54212509e0..02cb45331b 100644 --- a/tests/gen/gen_auto_test.go +++ b/tests/gen/gen_auto_test.go @@ -1203,6 +1203,15 @@ func TestAutoGenerate_IfCollectionDefinitionIsIncomplete_ReturnError(t *testing. Description: client.CollectionDescription{ Name: immutable.Some("User"), ID: 0, + Fields: []client.CollectionFieldDescription{ + { + Name: "name", + }, + { + Name: "device", + Kind: immutable.Some[client.FieldKind](client.ObjectKind("Device")), + }, + }, }, Schema: client.SchemaDescription{ Name: "User", @@ -1211,10 +1220,6 @@ func TestAutoGenerate_IfCollectionDefinitionIsIncomplete_ReturnError(t *testing. Name: "name", Kind: client.FieldKind_NILLABLE_INT, }, - { - Name: "device", - Kind: client.ObjectKind("Device"), - }, }, }, }, @@ -1222,6 +1227,15 @@ func TestAutoGenerate_IfCollectionDefinitionIsIncomplete_ReturnError(t *testing. Description: client.CollectionDescription{ Name: immutable.Some("Device"), ID: 1, + Fields: []client.CollectionFieldDescription{ + { + Name: "model", + }, + { + Name: "owner", + Kind: immutable.Some[client.FieldKind](client.ObjectKind("User")), + }, + }, }, Schema: client.SchemaDescription{ Name: "Device", @@ -1231,9 +1245,8 @@ func TestAutoGenerate_IfCollectionDefinitionIsIncomplete_ReturnError(t *testing. Kind: client.FieldKind_NILLABLE_STRING, }, { - Name: "owner", - Kind: client.ObjectKind("User"), - IsPrimaryRelation: true, + Name: "owner", + Kind: client.ObjectKind("User"), }, }, }, @@ -1267,6 +1280,7 @@ func TestAutoGenerate_IfCollectionDefinitionIsIncomplete_ReturnError(t *testing. name: "field name is empty", changeDefs: func(defs []client.CollectionDefinition) { defs[0].Schema.Fields[0].Name = "" + defs[0].Description.Fields[0].Name = "" }, }, { @@ -1304,6 +1318,22 @@ func TestAutoGenerate_IfColDefinitionsAreValid_ShouldGenerate(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("User"), ID: 0, + Fields: []client.CollectionFieldDescription{ + { + Name: "name", + }, + { + Name: "age", + }, + { + Name: "rating", + }, + { + Name: "devices", + Kind: immutable.Some[client.FieldKind](client.ObjectArrayKind("Device")), + RelationName: immutable.Some("Device_owner"), + }, + }, }, Schema: client.SchemaDescription{ Name: "User", @@ -1320,11 +1350,6 @@ func TestAutoGenerate_IfColDefinitionsAreValid_ShouldGenerate(t *testing.T) { Name: "rating", Kind: client.FieldKind_NILLABLE_FLOAT, }, - { - Name: "devices", - Kind: client.ObjectArrayKind("Device"), - RelationName: "Device_owner", - }, }, }, }, @@ -1332,6 +1357,20 @@ func TestAutoGenerate_IfColDefinitionsAreValid_ShouldGenerate(t *testing.T) { Description: client.CollectionDescription{ Name: immutable.Some("Device"), ID: 1, + Fields: []client.CollectionFieldDescription{ + { + Name: "model", + }, + { + Name: "owner", + Kind: immutable.Some[client.FieldKind](client.ObjectKind("User")), + RelationName: immutable.Some("Device_owner"), + }, + { + Name: "owner_id", + RelationName: immutable.Some("Device_owner"), + }, + }, }, Schema: client.SchemaDescription{ Name: "Device", @@ -1341,9 +1380,14 @@ func TestAutoGenerate_IfColDefinitionsAreValid_ShouldGenerate(t *testing.T) { Kind: client.FieldKind_NILLABLE_STRING, }, { - Name: "owner_id", - Kind: client.FieldKind_DocID, - RelationName: "Device_owner", + Name: "owner", + Kind: client.ObjectKind("User"), + Typ: client.LWW_REGISTER, + }, + { + Name: "owner_id", + Kind: client.FieldKind_DocID, + Typ: client.LWW_REGISTER, }, }, }, diff --git a/tests/integration/collection/update/simple/with_doc_id_test.go b/tests/integration/collection/update/simple/with_doc_id_test.go index cea7117682..c5e402e5f4 100644 --- a/tests/integration/collection/update/simple/with_doc_id_test.go +++ b/tests/integration/collection/update/simple/with_doc_id_test.go @@ -26,7 +26,7 @@ func TestUpdateWithDocID(t *testing.T) { "age": 21 }` - doc, err := client.NewDocFromJSON([]byte(docStr), colDefMap["Users"].Schema) + doc, err := client.NewDocFromJSON([]byte(docStr), colDefMap["Users"]) if err != nil { assert.Fail(t, err.Error()) } diff --git a/tests/integration/collection/update/simple/with_doc_ids_test.go b/tests/integration/collection/update/simple/with_doc_ids_test.go index 2469eeee56..880ae3d603 100644 --- a/tests/integration/collection/update/simple/with_doc_ids_test.go +++ b/tests/integration/collection/update/simple/with_doc_ids_test.go @@ -26,7 +26,7 @@ func TestUpdateWithDocIDs(t *testing.T) { "age": 21 }` - doc1, err := client.NewDocFromJSON([]byte(docStr1), colDefMap["Users"].Schema) + doc1, err := client.NewDocFromJSON([]byte(docStr1), colDefMap["Users"]) if err != nil { assert.Fail(t, err.Error()) } @@ -36,7 +36,7 @@ func TestUpdateWithDocIDs(t *testing.T) { "age": 32 }` - doc2, err := client.NewDocFromJSON([]byte(docStr2), colDefMap["Users"].Schema) + doc2, err := client.NewDocFromJSON([]byte(docStr2), colDefMap["Users"]) if err != nil { assert.Fail(t, err.Error()) } diff --git a/tests/integration/collection/update/simple/with_filter_test.go b/tests/integration/collection/update/simple/with_filter_test.go index bbcfc5b8bc..ebe45e0b4f 100644 --- a/tests/integration/collection/update/simple/with_filter_test.go +++ b/tests/integration/collection/update/simple/with_filter_test.go @@ -74,7 +74,7 @@ func TestUpdateWithFilter(t *testing.T) { "age": 21 }` - doc, err := client.NewDocFromJSON([]byte(docStr), colDefMap["Users"].Schema) + doc, err := client.NewDocFromJSON([]byte(docStr), colDefMap["Users"]) if err != nil { assert.Fail(t, err.Error()) } diff --git a/tests/integration/collection/utils.go b/tests/integration/collection/utils.go index b8bf1cf46b..497637a5c3 100644 --- a/tests/integration/collection/utils.go +++ b/tests/integration/collection/utils.go @@ -86,7 +86,7 @@ func setupDatabase( } for _, docStr := range docs { - doc, err := client.NewDocFromJSON([]byte(docStr), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(docStr), col.Definition()) if assertError(t, testCase.Description, err, testCase.ExpectedError) { return } diff --git a/tests/integration/events/simple/with_create_test.go b/tests/integration/events/simple/with_create_test.go index ec5c174106..c3f88eea58 100644 --- a/tests/integration/events/simple/with_create_test.go +++ b/tests/integration/events/simple/with_create_test.go @@ -28,7 +28,7 @@ func TestEventsSimpleWithCreate(t *testing.T) { "name": "John" }`, ), - colDefMap["Users"].Schema, + colDefMap["Users"], ) assert.Nil(t, err) docID1 := doc1.ID().String() @@ -39,7 +39,7 @@ func TestEventsSimpleWithCreate(t *testing.T) { "name": "Shahzad" }`, ), - colDefMap["Users"].Schema, + colDefMap["Users"], ) assert.Nil(t, err) docID2 := doc2.ID().String() diff --git a/tests/integration/events/simple/with_delete_test.go b/tests/integration/events/simple/with_delete_test.go index b02b2505e1..141965966f 100644 --- a/tests/integration/events/simple/with_delete_test.go +++ b/tests/integration/events/simple/with_delete_test.go @@ -28,7 +28,7 @@ func TestEventsSimpleWithDelete(t *testing.T) { "name": "John" }`, ), - colDefMap["Users"].Schema, + colDefMap["Users"], ) assert.Nil(t, err) docID1 := doc1.ID().String() diff --git a/tests/integration/events/simple/with_update_test.go b/tests/integration/events/simple/with_update_test.go index 723421f91b..6ad73d6ce1 100644 --- a/tests/integration/events/simple/with_update_test.go +++ b/tests/integration/events/simple/with_update_test.go @@ -28,7 +28,7 @@ func TestEventsSimpleWithUpdate(t *testing.T) { "name": "John" }`, ), - colDefMap["Users"].Schema, + colDefMap["Users"], ) assert.Nil(t, err) docID1 := doc1.ID().String() @@ -39,7 +39,7 @@ func TestEventsSimpleWithUpdate(t *testing.T) { "name": "Shahzad" }`, ), - colDefMap["Users"].Schema, + colDefMap["Users"], ) assert.Nil(t, err) docID2 := doc2.ID().String() diff --git a/tests/integration/events/utils.go b/tests/integration/events/utils.go index d2bf418294..8b998d0051 100644 --- a/tests/integration/events/utils.go +++ b/tests/integration/events/utils.go @@ -149,7 +149,7 @@ func setupDatabase( require.NoError(t, err) for _, docStr := range docs { - doc, err := client.NewDocFromJSON([]byte(docStr), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(docStr), col.Definition()) require.NoError(t, err) err = col.Save(ctx, doc) diff --git a/tests/integration/explain/default/type_join_many_test.go b/tests/integration/explain/default/type_join_many_test.go index 3b700b132b..031b509950 100644 --- a/tests/integration/explain/default/type_join_many_test.go +++ b/tests/integration/explain/default/type_join_many_test.go @@ -13,6 +13,8 @@ package test_explain_default import ( "testing" + "github.com/sourcenetwork/immutable" + testUtils "github.com/sourcenetwork/defradb/tests/integration" explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain" ) @@ -53,7 +55,7 @@ func TestDefaultExplainRequestWithAOneToManyJoin(t *testing.T) { IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "articles", }, }, diff --git a/tests/integration/explain/default/type_join_one_test.go b/tests/integration/explain/default/type_join_one_test.go index 8a7fac0925..3059bf8528 100644 --- a/tests/integration/explain/default/type_join_one_test.go +++ b/tests/integration/explain/default/type_join_one_test.go @@ -13,6 +13,8 @@ package test_explain_default import ( "testing" + "github.com/sourcenetwork/immutable" + testUtils "github.com/sourcenetwork/defradb/tests/integration" explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain" ) @@ -54,7 +56,7 @@ func TestDefaultExplainRequestWithAOneToOneJoin(t *testing.T) { ExpectedAttributes: dataMap{ "direction": "primary", "joinType": "typeJoinOne", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "contact", }, }, @@ -163,7 +165,7 @@ func TestDefaultExplainRequestWithTwoLevelDeepNestedJoins(t *testing.T) { ExpectedAttributes: dataMap{ "direction": "primary", "joinType": "typeJoinOne", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "contact", }, }, @@ -196,7 +198,7 @@ func TestDefaultExplainRequestWithTwoLevelDeepNestedJoins(t *testing.T) { ExpectedAttributes: dataMap{ "direction": "primary", "joinType": "typeJoinOne", - "rootName": "contact", + "rootName": immutable.Some("contact"), "subTypeName": "address", }, }, diff --git a/tests/integration/explain/default/type_join_test.go b/tests/integration/explain/default/type_join_test.go index fd1676aed9..c09c1b0f12 100644 --- a/tests/integration/explain/default/type_join_test.go +++ b/tests/integration/explain/default/type_join_test.go @@ -13,6 +13,8 @@ package test_explain_default import ( "testing" + "github.com/sourcenetwork/immutable" + testUtils "github.com/sourcenetwork/defradb/tests/integration" explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain" ) @@ -86,7 +88,7 @@ func TestDefaultExplainRequestWith2SingleJoinsAnd1ManyJoin(t *testing.T) { ExpectedAttributes: dataMap{ "direction": "primary", "joinType": "typeJoinOne", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "contact", }, }, @@ -144,7 +146,7 @@ func TestDefaultExplainRequestWith2SingleJoinsAnd1ManyJoin(t *testing.T) { IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "articles", }, }, @@ -204,7 +206,7 @@ func TestDefaultExplainRequestWith2SingleJoinsAnd1ManyJoin(t *testing.T) { ExpectedAttributes: dataMap{ "direction": "primary", "joinType": "typeJoinOne", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "contact", }, }, diff --git a/tests/integration/explain/default/with_average_join_test.go b/tests/integration/explain/default/with_average_join_test.go index 265ca932ce..d1cd68046e 100644 --- a/tests/integration/explain/default/with_average_join_test.go +++ b/tests/integration/explain/default/with_average_join_test.go @@ -13,6 +13,8 @@ package test_explain_default import ( "testing" + "github.com/sourcenetwork/immutable" + testUtils "github.com/sourcenetwork/defradb/tests/integration" explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain" ) @@ -96,7 +98,7 @@ func TestDefaultExplainRequestWithAverageOnJoinedField(t *testing.T) { IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "books", }, }, @@ -253,7 +255,7 @@ func TestDefaultExplainRequestWithAverageOnMultipleJoinedFieldsWithFilter(t *tes IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "books", }, }, @@ -299,7 +301,7 @@ func TestDefaultExplainRequestWithAverageOnMultipleJoinedFieldsWithFilter(t *tes IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "articles", }, }, diff --git a/tests/integration/explain/default/with_count_join_test.go b/tests/integration/explain/default/with_count_join_test.go index 3f7802820d..4833354bba 100644 --- a/tests/integration/explain/default/with_count_join_test.go +++ b/tests/integration/explain/default/with_count_join_test.go @@ -13,6 +13,8 @@ package test_explain_default import ( "testing" + "github.com/sourcenetwork/immutable" + testUtils "github.com/sourcenetwork/defradb/tests/integration" explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain" ) @@ -66,7 +68,7 @@ func TestDefaultExplainRequestWithCountOnOneToManyJoinedField(t *testing.T) { IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "books", }, }, @@ -175,7 +177,7 @@ func TestDefaultExplainRequestWithCountOnOneToManyJoinedFieldWithManySources(t * IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "books", }, }, @@ -217,7 +219,7 @@ func TestDefaultExplainRequestWithCountOnOneToManyJoinedFieldWithManySources(t * IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "articles", }, }, diff --git a/tests/integration/explain/default/with_sum_join_test.go b/tests/integration/explain/default/with_sum_join_test.go index 5117031959..0889b3bd85 100644 --- a/tests/integration/explain/default/with_sum_join_test.go +++ b/tests/integration/explain/default/with_sum_join_test.go @@ -13,6 +13,8 @@ package test_explain_default import ( "testing" + "github.com/sourcenetwork/immutable" + testUtils "github.com/sourcenetwork/defradb/tests/integration" explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain" ) @@ -70,7 +72,7 @@ func TestDefaultExplainRequestWithSumOnOneToManyJoinedField(t *testing.T) { IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "books", }, }, @@ -165,7 +167,7 @@ func TestDefaultExplainRequestWithSumOnOneToManyJoinedFieldWithFilter(t *testing IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "articles", }, }, @@ -280,7 +282,7 @@ func TestDefaultExplainRequestWithSumOnOneToManyJoinedFieldWithManySources(t *te IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "books", }, }, @@ -322,7 +324,7 @@ func TestDefaultExplainRequestWithSumOnOneToManyJoinedFieldWithManySources(t *te IncludeChildNodes: false, ExpectedAttributes: dataMap{ "joinType": "typeJoinMany", - "rootName": "author", + "rootName": immutable.Some("author"), "subTypeName": "articles", }, }, diff --git a/tests/integration/mutation/delete/field_kinds/one_to_many/with_show_deleted_test.go b/tests/integration/mutation/delete/field_kinds/one_to_many/with_show_deleted_test.go index bee050d1ae..260a9a7b70 100644 --- a/tests/integration/mutation/delete/field_kinds/one_to_many/with_show_deleted_test.go +++ b/tests/integration/mutation/delete/field_kinds/one_to_many/with_show_deleted_test.go @@ -41,7 +41,7 @@ func TestDeletionOfADocumentUsingSingleDocIDWithShowDeletedDocumentQuery(t *test "name": "John", "age": 30 }` - doc1, err := client.NewDocFromJSON([]byte(jsonString1), colDefMap["Author"].Schema) + doc1, err := client.NewDocFromJSON([]byte(jsonString1), colDefMap["Author"]) require.NoError(t, err) jsonString2 := fmt.Sprintf(`{ @@ -49,7 +49,7 @@ func TestDeletionOfADocumentUsingSingleDocIDWithShowDeletedDocumentQuery(t *test "rating": 9.9, "author_id": "%s" }`, doc1.ID()) - doc2, err := client.NewDocFromJSON([]byte(jsonString2), colDefMap["Book"].Schema) + doc2, err := client.NewDocFromJSON([]byte(jsonString2), colDefMap["Book"]) require.NoError(t, err) jsonString3 := fmt.Sprintf(`{ diff --git a/tests/integration/net/order/tcp_test.go b/tests/integration/net/order/tcp_test.go index 256db2f442..ef18668d20 100644 --- a/tests/integration/net/order/tcp_test.go +++ b/tests/integration/net/order/tcp_test.go @@ -141,7 +141,7 @@ func TestP2FullPReplicator(t *testing.T) { doc, err := client.NewDocFromJSON([]byte(`{ "Name": "John", "Age": 21 - }`), colDefMap[userCollection].Schema) + }`), colDefMap[userCollection]) require.NoError(t, err) test := P2PTestCase{ diff --git a/tests/integration/net/order/utils.go b/tests/integration/net/order/utils.go index e744c4735d..2373037b62 100644 --- a/tests/integration/net/order/utils.go +++ b/tests/integration/net/order/utils.go @@ -140,7 +140,7 @@ func seedDocument( return client.DocID{}, err } - doc, err := client.NewDocFromJSON([]byte(document), col.Schema()) + doc, err := client.NewDocFromJSON([]byte(document), col.Definition()) if err != nil { return client.DocID{}, err } diff --git a/tests/integration/query/one_to_many/with_id_field_test.go b/tests/integration/query/one_to_many/with_id_field_test.go index 8a16f1c49a..9f70b0d1b3 100644 --- a/tests/integration/query/one_to_many/with_id_field_test.go +++ b/tests/integration/query/one_to_many/with_id_field_test.go @@ -42,46 +42,7 @@ func TestQueryOneToManyWithIdFieldOnPrimary(t *testing.T) { published: [Book] } `, - }, - testUtils.CreateDoc{ - // bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "Painted House", - "author_id": 123456 - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "A Time for Mercy", - "author_id": "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - }`, - ExpectedError: "value doesn't contain number; it contains string", - }, - testUtils.Request{ - Request: `query { - Book { - name - author_id - author { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Painted House", - "author_id": int64(123456), - "author": nil, - }, - }, + ExpectedError: "relational id field of invalid kind. Field: author_id, Expected: ID, Actual: Int", }, }, } diff --git a/tests/integration/query/one_to_one/with_clashing_id_field_test.go b/tests/integration/query/one_to_one/with_clashing_id_field_test.go index f563f1e358..1dd97572ca 100644 --- a/tests/integration/query/one_to_one/with_clashing_id_field_test.go +++ b/tests/integration/query/one_to_one/with_clashing_id_field_test.go @@ -94,22 +94,7 @@ func TestQueryOneToOneWithClashingIdFieldOnPrimary(t *testing.T) { published: Book } `, - }, - testUtils.CreateDoc{ - // bae-d82dbe47-9df1-5e33-bd87-f92e9c378161 - CollectionID: 0, - Doc: `{ - "name": "Painted House", - "author_id": 123456 - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham", - "published_id": "bae-d82dbe47-9df1-5e33-bd87-f92e9c378161" - }`, - ExpectedError: "target document is already linked to another document.", + ExpectedError: "relational id field of invalid kind. Field: author_id, Expected: ID, Actual: Int", }, }, } diff --git a/tests/integration/schema/one_one_test.go b/tests/integration/schema/one_one_test.go index e14792f75e..b5bc75bb48 100644 --- a/tests/integration/schema/one_one_test.go +++ b/tests/integration/schema/one_one_test.go @@ -30,7 +30,7 @@ func TestSchemaOneOne_NoPrimary_Errors(t *testing.T) { owner: User } `, - ExpectedError: "primary side of relation not defined. RelationName: dog_user", + ExpectedError: "relation missing field. Object: Dog, RelationName: dog_user", }, }, } diff --git a/tests/integration/schema/relations_test.go b/tests/integration/schema/relations_test.go index ade67c689a..892c6e67ac 100644 --- a/tests/integration/schema/relations_test.go +++ b/tests/integration/schema/relations_test.go @@ -135,45 +135,7 @@ func TestSchemaRelationErrorsGivenOneSidedManyRelationField(t *testing.T) { dogs: [Dog] } `, - ExpectedError: "relation must be defined on both schemas. Field: dogs, Type: Dog", - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaRelationErrorsGivenOneSidedRelationField(t *testing.T) { - test := testUtils.TestCase{ - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Dog { - name: String - } - type User { - dog: Dog - } - `, - ExpectedError: "relation must be defined on both schemas. Field: dog, Type: Dog", - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaRelation_GivenSelfReferemceRelationField_ReturnError(t *testing.T) { - test := testUtils.TestCase{ - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Dog { - name: String - bestMate: Dog - } - `, - ExpectedError: "relation must be defined on both schemas. Field: bestMate, Type: Dog", + ExpectedError: "relation missing field. Object: Dog, RelationName: dog_user", }, }, } diff --git a/tests/integration/schema/simple_test.go b/tests/integration/schema/simple_test.go index 854321a170..c0f615e6eb 100644 --- a/tests/integration/schema/simple_test.go +++ b/tests/integration/schema/simple_test.go @@ -180,7 +180,7 @@ func TestSchemaSimpleErrorsGivenTypeWithInvalidFieldType(t *testing.T) { name: NotAType } `, - ExpectedError: "relation must be defined on both schemas. Field: name, Type: NotAType", + ExpectedError: "no type found for given name. Field: name, Kind: NotAType", }, }, } diff --git a/tests/integration/schema/updates/add/field/kind/foreign_object_array_test.go b/tests/integration/schema/updates/add/field/kind/foreign_object_array_test.go index 4b1247718d..abeff648fd 100644 --- a/tests/integration/schema/updates/add/field/kind/foreign_object_array_test.go +++ b/tests/integration/schema/updates/add/field/kind/foreign_object_array_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Democratized Data Foundation +// Copyright 2024 Democratized Data Foundation // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt. @@ -11,495 +11,14 @@ package kind import ( - "fmt" "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" ) -func TestSchemaUpdatesAddFieldKindForeignObjectArray(t *testing.T) { +func TestSchemaUpdatesAddFieldKindForeignObjectArray_UnknownSchema(t *testing.T) { test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo", "Kind": 17} } - ] - `, - ExpectedError: "no type found for given name. Type: 17", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_MissingRelationName(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array (17), missing relation name", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "[Users]" - }} - ] - `, - ExpectedError: "missing relation name. Field: foo", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_IDFieldMissingKind(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array (17), id field missing kind", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo_id"} } - ] - `, - ExpectedError: "relational id field of invalid kind. Field: foo_id, Expected: ID, Actual: 0", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_IDFieldInvalidKind(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array, id field invalid kind", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo_id", "Kind": 2} } - ] - `, - ExpectedError: "relational id field of invalid kind. Field: foo_id, Expected: ID, Actual: Boolean", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_IDFieldMissingRelationName(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array, id field missing relation name", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo_id", "Kind": 1} } - ] - `, - ExpectedError: "missing relation name. Field: foo_id", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_OnlyHalfRelationDefined(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array, only half relation defined", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }} - ] - `, - ExpectedError: "relation must be defined on both schemas. Field: foo, Type: Users", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_NoPrimaryDefined(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array, no primary defined", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "[Users]", "RelationName": "foo" - }} - ] - `, - ExpectedError: "primary side of relation not defined. RelationName: foo", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_PrimaryDefinedOnManySide(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array, no primary defined", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "[Users]", "IsPrimaryRelation": true, "RelationName": "foo" - }} - ] - `, - ExpectedError: "cannot set the many side of a relation as primary. Field: foobar", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_Succeeds(t *testing.T) { - key1 := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" - - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array, valid, functional", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "[Users]", "RelationName": "foo" - }} - ] - `, - }, - testUtils.Request{ - Request: `mutation { - create_Users(input: {name: "John"}) { - _docID - } - }`, - Results: []map[string]any{ - { - "_docID": key1, - }, - }, - }, - testUtils.Request{ - Request: fmt.Sprintf(`mutation { - create_Users(input: {name: "Keenan", foo: "%s"}) { - name - foo { - name - } - } - }`, - key1, - ), - Results: []map[string]any{ - { - "name": "Keenan", - "foo": map[string]any{ - "name": "John", - }, - }, - }, - }, - testUtils.Request{ - Request: `query { - Users { - name - foo { - name - } - foobar { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Keenan", - "foo": map[string]any{ - "name": "John", - }, - "foobar": []map[string]any{}, - }, - { - "name": "John", - "foo": nil, - "foobar": []map[string]any{ - { - "name": "Keenan", - }, - }, - }, - }, - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_SinglePrimaryObjectKindSubstitution(t *testing.T) { - key1 := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" - - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array, with single object Kind substitution", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "[Users]", "RelationName": "foo" - }} - ] - `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf(`{ - "name": "Keenan", - "foo": "%s" - }`, - key1, - ), - }, - testUtils.Request{ - Request: `query { - Users { - name - foo { - name - } - foobar { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Keenan", - "foo": map[string]any{ - "name": "John", - }, - "foobar": []map[string]any{}, - }, - { - "name": "John", - "foo": nil, - "foobar": []map[string]any{ - { - "name": "Keenan", - }, - }, - }, - }, - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_SingleSecondaryObjectKindSubstitution(t *testing.T) { - key1 := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" - - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array, with single object Kind substitution", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "[Users]", "RelationName": "foo" - }} - ] - `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf(`{ - "name": "Keenan", - "foo_id": "%s" - }`, - key1, - ), - }, - testUtils.Request{ - Request: `query { - Users { - name - foo { - name - } - foobar { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Keenan", - "foo": map[string]any{ - "name": "John", - }, - "foobar": []map[string]any{}, - }, - { - "name": "John", - "foo": nil, - "foobar": []map[string]any{ - { - "name": "Keenan", - }, - }, - }, - }, - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_ObjectKindSubstitution(t *testing.T) { - key1 := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" - - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array, with object Kind substitution", + Description: "Test schema update, add field with kind foreign object array, unknown schema", Actions: []any{ testUtils.SchemaUpdate{ Schema: ` @@ -512,73 +31,20 @@ func TestSchemaUpdatesAddFieldKindForeignObjectArray_ObjectKindSubstitution(t *t Patch: ` [ { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "[Users]", "RelationName": "foo" + "Name": "foo", "Kind": "[Unknown]" }} ] `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf(`{ - "name": "Keenan", - "foo": "%s" - }`, - key1, - ), - }, - testUtils.Request{ - Request: `query { - Users { - name - foo { - name - } - foobar { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Keenan", - "foo": map[string]any{ - "name": "John", - }, - "foobar": []map[string]any{}, - }, - { - "name": "John", - "foo": nil, - "foobar": []map[string]any{ - { - "name": "Keenan", - }, - }, - }, - }, + ExpectedError: "no type found for given name. Field: foo, Kind: Unknown", }, }, } testUtils.ExecuteTestCase(t, test) } -func TestSchemaUpdatesAddFieldKindForeignObjectArray_ObjectKindSubstitutionWithAutoSchemaValues(t *testing.T) { - key1 := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" - +func TestSchemaUpdatesAddFieldKindForeignObjectArray_KnownSchema(t *testing.T) { test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array (17), with object Kind substitution", + Description: "Test schema update, add field with kind foreign object array, known schema", Actions: []any{ testUtils.SchemaUpdate{ Schema: ` @@ -591,177 +57,11 @@ func TestSchemaUpdatesAddFieldKindForeignObjectArray_ObjectKindSubstitutionWithA Patch: ` [ { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "[Users]", "RelationName": "foo" - }} - ] - `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf(`{ - "name": "Keenan", - "foo": "%s" - }`, - key1, - ), - }, - testUtils.Request{ - Request: `query { - Users { - name - foo { - name - } - foobar { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Keenan", - "foo": map[string]any{ - "name": "John", - }, - "foobar": []map[string]any{}, - }, - { - "name": "John", - "foo": nil, - "foobar": []map[string]any{ - { - "name": "Keenan", - }, - }, - }, - }, - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_MissingPrimaryIDField(t *testing.T) { - key1 := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" - - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array (17), with auto id field generation", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "[Users]", "RelationName": "foo" - }} - ] - `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf(`{ - "name": "Keenan", - "foo": "%s" - }`, - key1, - ), - }, - testUtils.Request{ - Request: `query { - Users { - name - foo_id - foo { - name - } - foobar { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Keenan", - "foo_id": key1, - "foo": map[string]any{ - "name": "John", - }, - "foobar": []map[string]any{}, - }, - { - "name": "John", - "foo": nil, - "foo_id": nil, - "foobar": []map[string]any{ - { - "name": "Keenan", - }, - }, - }, - }, - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObjectArray_MissingPrimaryIDField_DoesNotCreateIdOnManySide(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object array (17), with auto id field generation", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "[Users]", "RelationName": "foo" + "Name": "foo", "Kind": "[Users]" }} ] `, - }, - testUtils.Request{ - Request: `query { - Users { - foobar_id - } - }`, - ExpectedError: `Cannot query field "foobar_id" on type "Users"`, + ExpectedError: "secondary relation fields cannot be defined on the schema. Name: foo", }, }, } diff --git a/tests/integration/schema/updates/add/field/kind/foreign_object_test.go b/tests/integration/schema/updates/add/field/kind/foreign_object_test.go index af51ec335d..56bfbd2131 100644 --- a/tests/integration/schema/updates/add/field/kind/foreign_object_test.go +++ b/tests/integration/schema/updates/add/field/kind/foreign_object_test.go @@ -67,32 +67,6 @@ func TestSchemaUpdatesAddFieldKindForeignObject_UnknownSchema(t *testing.T) { testUtils.ExecuteTestCase(t, test) } -func TestSchemaUpdatesAddFieldKindForeignObject_MissingRelationName(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object, missing relation name", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users" - }} - ] - `, - ExpectedError: "missing relation name. Field: foo", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - func TestSchemaUpdatesAddFieldKindForeignObject_IDFieldMissingKind(t *testing.T) { test := testUtils.TestCase{ Description: "Test schema update, add field with kind foreign object, id field missing kind", @@ -108,7 +82,7 @@ func TestSchemaUpdatesAddFieldKindForeignObject_IDFieldMissingKind(t *testing.T) Patch: ` [ { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users","IsPrimaryRelation": true, "RelationName": "foo" + "Name": "foo", "Kind": "Users" }}, { "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo_id"} } ] @@ -135,7 +109,7 @@ func TestSchemaUpdatesAddFieldKindForeignObject_IDFieldInvalidKind(t *testing.T) Patch: ` [ { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" + "Name": "foo", "Kind": "Users" }}, { "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo_id", "Kind": 2} } ] @@ -147,129 +121,6 @@ func TestSchemaUpdatesAddFieldKindForeignObject_IDFieldInvalidKind(t *testing.T) testUtils.ExecuteTestCase(t, test) } -func TestSchemaUpdatesAddFieldKindForeignObject_IDFieldMissingRelationName(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object, id field missing relation name", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo_id", "Kind": 1} } - ] - `, - ExpectedError: "missing relation name. Field: foo_id", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObject_OnlyHalfRelationDefined(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object, only half relation defined", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }} - ] - `, - ExpectedError: "relation must be defined on both schemas. Field: foo, Type: Users", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObject_NoPrimaryDefined(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object, no primary defined", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "Users", "RelationName": "foo" - }} - ] - `, - ExpectedError: "primary side of relation not defined. RelationName: foo", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObject_BothSidesPrimary(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object, both sides primary", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar_id", "Kind": 1, "RelationName": "foo" - }} - ] - `, - ExpectedError: "both sides of a relation cannot be primary. RelationName: foo", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} - func TestSchemaUpdatesAddFieldKindForeignObject_Succeeds(t *testing.T) { key1 := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" @@ -287,16 +138,10 @@ func TestSchemaUpdatesAddFieldKindForeignObject_Succeeds(t *testing.T) { Patch: ` [ { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "Users", "RelationName": "foo" + "Name": "foo", "Kind": "Users" }}, { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar_id", "Kind": 1, "RelationName": "foo" + "Name": "foo_id", "Kind": 1 }} ] `, @@ -340,9 +185,6 @@ func TestSchemaUpdatesAddFieldKindForeignObject_Succeeds(t *testing.T) { foo { name } - foobar { - name - } } }`, Results: []map[string]any{ @@ -351,14 +193,10 @@ func TestSchemaUpdatesAddFieldKindForeignObject_Succeeds(t *testing.T) { "foo": map[string]any{ "name": "John", }, - "foobar": nil, }, { "name": "John", "foo": nil, - "foobar": map[string]any{ - "name": "Keenan", - }, }, }, }, @@ -366,159 +204,3 @@ func TestSchemaUpdatesAddFieldKindForeignObject_Succeeds(t *testing.T) { } testUtils.ExecuteTestCase(t, test) } - -func TestSchemaUpdatesAddFieldKindForeignObject_MissingPrimaryIDField(t *testing.T) { - key1 := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" - - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object (16), with auto primary ID field creation", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "Users", "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar_id", "Kind": 1, "RelationName": "foo" - }} - ] - `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf(`{ - "name": "Keenan", - "foo": "%s" - }`, - key1, - ), - }, - testUtils.Request{ - Request: `query { - Users { - name - foo { - name - } - foobar { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Keenan", - "foo": map[string]any{ - "name": "John", - }, - "foobar": nil, - }, - { - "name": "John", - "foo": nil, - "foobar": map[string]any{ - "name": "Keenan", - }, - }, - }, - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} - -func TestSchemaUpdatesAddFieldKindForeignObject_MissingSecondaryIDField(t *testing.T) { - key1 := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" - - test := testUtils.TestCase{ - Description: "Test schema update, add field with kind foreign object (16), with auto secondary ID field creation", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo", "Kind": "Users", "IsPrimaryRelation": true, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foo_id", "Kind": 1, "RelationName": "foo" - }}, - { "op": "add", "path": "/Users/Fields/-", "value": { - "Name": "foobar", "Kind": "Users", "RelationName": "foo" - }} - ] - `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf(`{ - "name": "Keenan", - "foo": "%s" - }`, - key1, - ), - }, - testUtils.Request{ - Request: `query { - Users { - name - foo { - name - } - foobar { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Keenan", - "foo": map[string]any{ - "name": "John", - }, - "foobar": nil, - }, - { - "name": "John", - "foo": nil, - "foobar": map[string]any{ - "name": "Keenan", - }, - }, - }, - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} diff --git a/tests/integration/schema/updates/remove/fields/simple_test.go b/tests/integration/schema/updates/remove/fields/simple_test.go index fae9b85dc7..ce9b8112f0 100644 --- a/tests/integration/schema/updates/remove/fields/simple_test.go +++ b/tests/integration/schema/updates/remove/fields/simple_test.go @@ -140,32 +140,3 @@ func TestSchemaUpdatesRemoveFieldTypErrors(t *testing.T) { } testUtils.ExecuteTestCase(t, test) } - -func TestSchemaUpdatesRemoveFieldRelationNameErrors(t *testing.T) { - test := testUtils.TestCase{ - Description: "Test schema update, remove field RelationName", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Author { - name: String - book: [Book] - } - type Book { - name: String - author: Author - } - `, - }, - testUtils.SchemaPatch{ - Patch: ` - [ - { "op": "remove", "path": "/Author/Fields/1/RelationName" } - ] - `, - ExpectedError: "mutating an existing field is not supported. ProposedName: book", - }, - }, - } - testUtils.ExecuteTestCase(t, test) -} diff --git a/tests/integration/schema/updates/test/field/simple_test.go b/tests/integration/schema/updates/test/field/simple_test.go index effdb162fe..35cba3ec29 100644 --- a/tests/integration/schema/updates/test/field/simple_test.go +++ b/tests/integration/schema/updates/test/field/simple_test.go @@ -102,7 +102,7 @@ func TestSchemaUpdatesTestFieldPasses(t *testing.T) { Patch: ` [ { "op": "test", "path": "/Users/Fields/1", "value": { - "Name": "name", "Kind": 11, "IsPrimaryRelation":false, "RelationName":"", "Typ":1 + "Name": "name", "Kind": 11, "Typ":1 } } ] `, @@ -127,7 +127,7 @@ func TestSchemaUpdatesTestFieldPasses_UsingFieldNameAsIndex(t *testing.T) { Patch: ` [ { "op": "test", "path": "/Users/Fields/name", "value": { - "Kind": 11, "IsPrimaryRelation":false, "RelationName":"", "Typ":1 + "Kind": 11, "Typ":1 } } ] `, diff --git a/tests/integration/utils2.go b/tests/integration/utils2.go index b699ed9f7f..2e36bfecf1 100644 --- a/tests/integration/utils2.go +++ b/tests/integration/utils2.go @@ -841,7 +841,7 @@ func refreshDocuments( // We need to add the existing documents in the order in which the test case lists them // otherwise they cannot be referenced correctly by other actions. - doc, err := client.NewDocFromJSON([]byte(action.Doc), collection.Schema()) + doc, err := client.NewDocFromJSON([]byte(action.Doc), collection.Definition()) if err != nil { // If an err has been returned, ignore it - it may be expected and if not // the test will fail later anyway @@ -1195,7 +1195,7 @@ func createDocViaColSave( collections []client.Collection, ) (*client.Document, error) { var err error - doc, err := client.NewDocFromJSON([]byte(action.Doc), collections[action.CollectionID].Schema()) + doc, err := client.NewDocFromJSON([]byte(action.Doc), collections[action.CollectionID].Definition()) if err != nil { return nil, err } @@ -1215,7 +1215,7 @@ func createDocViaColCreate( collections []client.Collection, ) (*client.Document, error) { var err error - doc, err := client.NewDocFromJSON([]byte(action.Doc), collections[action.CollectionID].Schema()) + doc, err := client.NewDocFromJSON([]byte(action.Doc), collections[action.CollectionID].Definition()) if err != nil { return nil, err } diff --git a/tests/integration/view/one_to_many/simple_test.go b/tests/integration/view/one_to_many/simple_test.go index f6ccd699b8..30f76987a2 100644 --- a/tests/integration/view/one_to_many/simple_test.go +++ b/tests/integration/view/one_to_many/simple_test.go @@ -122,7 +122,7 @@ func TestView_OneToManyWithMixedSDL_Errors(t *testing.T) { books: [Book] } `, - ExpectedError: "relation must be defined on both schemas. Field: books, Type: Book", + ExpectedError: "relation missing field. Object: Book, RelationName: authorview_book", }, }, } @@ -457,46 +457,3 @@ func TestView_OneToManyWithDoubleSidedRelation_Errors(t *testing.T) { testUtils.ExecuteTestCase(t, test) } - -func TestView_OneToManyViewOfView(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to many view of view", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Author { - name: String - books: [Book] - } - type Book { - name: String - author: Author - } - `, - }, - testUtils.CreateView{ - Query: ` - Author { - name - books { - name - } - } - `, - SDL: ` - type AuthorView { - name: String - books: [BookView] - } - interface BookView { - name: String - author: AuthorView - } - `, - ExpectedError: "relations in views must only be defined on one schema", - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} diff --git a/tests/predefined/gen_predefined.go b/tests/predefined/gen_predefined.go index d83d1594fd..34d575098e 100644 --- a/tests/predefined/gen_predefined.go +++ b/tests/predefined/gen_predefined.go @@ -109,7 +109,7 @@ type docGenerator struct { // It doesn't not modify the original doc. func toRequestedDoc(doc map[string]any, typeDef *client.CollectionDefinition) map[string]any { result := make(map[string]any) - for _, field := range typeDef.Schema.Fields { + for _, field := range typeDef.GetFields() { if field.IsRelation() || field.Name == request.DocIDFieldName { continue } @@ -131,7 +131,7 @@ func (this *docGenerator) generatePrimary( ) (map[string]any, []gen.GeneratedDoc, error) { result := []gen.GeneratedDoc{} requestedSecondary := toRequestedDoc(secDocMap, secType) - for _, secDocField := range secType.Schema.Fields { + for _, secDocField := range secType.GetFields() { if secDocField.IsRelation() { if secDocMapField, hasField := secDocMap[secDocField.Name]; hasField { if secDocField.IsPrimaryRelation { @@ -141,7 +141,7 @@ func (this *docGenerator) generatePrimary( if err != nil { return nil, nil, NewErrFailedToGenerateDoc(err) } - primDoc, err := client.NewDocFromMap(primDocMap, primType.Schema) + primDoc, err := client.NewDocFromMap(primDocMap, primType) if err != nil { return nil, nil, NewErrFailedToGenerateDoc(err) } @@ -174,7 +174,7 @@ func (this *docGenerator) generateRelatedDocs(docMap map[string]any, typeName st if err != nil { return nil, err } - doc, err := client.NewDocFromMap(requested, typeDef.Schema) + doc, err := client.NewDocFromMap(requested, typeDef) if err != nil { return nil, NewErrFailedToGenerateDoc(err) } @@ -196,7 +196,7 @@ func (this *docGenerator) generateSecondaryDocs( parentTypeName string, ) ([]gen.GeneratedDoc, error) { result := []gen.GeneratedDoc{} - for _, field := range primaryType.Schema.Fields { + for _, field := range primaryType.GetFields() { if field.IsRelation() { if _, hasProp := primaryDocMap[field.Name]; hasProp { if !field.IsPrimaryRelation && @@ -218,13 +218,13 @@ func (this *docGenerator) generateSecondaryDocs( func (this *docGenerator) generateSecondaryDocsForField( primaryDoc map[string]any, primaryTypeName string, - relField *client.SchemaFieldDescription, + relField *client.FieldDefinition, primaryDocID string, ) ([]gen.GeneratedDoc, error) { result := []gen.GeneratedDoc{} relTypeDef := this.types[relField.Kind.Underlying()] primaryPropName := "" - for _, relDocField := range relTypeDef.Schema.Fields { + for _, relDocField := range relTypeDef.GetFields() { if relDocField.Kind.Underlying() == primaryTypeName && relDocField.IsPrimaryRelation { primaryPropName = relDocField.Name + request.RelatedObjectID switch relVal := primaryDoc[relField.Name].(type) { diff --git a/tests/predefined/gen_predefined_test.go b/tests/predefined/gen_predefined_test.go index 94b261059e..30cd446697 100644 --- a/tests/predefined/gen_predefined_test.go +++ b/tests/predefined/gen_predefined_test.go @@ -39,7 +39,7 @@ func TestGeneratePredefinedFromSchema_Simple(t *testing.T) { colDefMap, err := parseSDL(schema) require.NoError(t, err) - errorMsg := assertDocs(mustAddDocIDsToDocs(docsList.Docs, colDefMap["User"].Schema), docs) + errorMsg := assertDocs(mustAddDocIDsToDocs(docsList.Docs, colDefMap["User"]), docs) if errorMsg != "" { t.Error(errorMsg) } @@ -66,7 +66,7 @@ func TestGeneratePredefinedFromSchema_StripExcessiveFields(t *testing.T) { errorMsg := assertDocs(mustAddDocIDsToDocs([]map[string]any{ {"name": "John"}, {"name": "Fred"}, - }, colDefMap["User"].Schema), docs) + }, colDefMap["User"]), docs) if errorMsg != "" { t.Error(errorMsg) } @@ -108,18 +108,18 @@ func TestGeneratePredefinedFromSchema_OneToOne(t *testing.T) { userDocs := mustAddDocIDsToDocs([]map[string]any{ {"name": "John"}, {"name": "Fred"}, - }, colDefMap["User"].Schema) + }, colDefMap["User"]) deviceDocs := mustAddDocIDsToDocs([]map[string]any{ { "model": "iPhone", - "owner_id": mustGetDocIDFromDocMap(map[string]any{"name": "John"}, colDefMap["User"].Schema), + "owner_id": mustGetDocIDFromDocMap(map[string]any{"name": "John"}, colDefMap["User"]), }, { "model": "MacBook", - "owner_id": mustGetDocIDFromDocMap(map[string]any{"name": "Fred"}, colDefMap["User"].Schema), + "owner_id": mustGetDocIDFromDocMap(map[string]any{"name": "Fred"}, colDefMap["User"]), }, - }, colDefMap["Device"].Schema) + }, colDefMap["Device"]) errorMsg := assertDocs(append(userDocs, deviceDocs...), docs) if errorMsg != "" { @@ -163,17 +163,17 @@ func TestGeneratePredefinedFromSchema_OneToOnePrimary(t *testing.T) { userDocs := mustAddDocIDsToDocs([]map[string]any{ { "name": "John", - "device_id": mustGetDocIDFromDocMap(map[string]any{"model": "iPhone"}, colDefMap["Device"].Schema), + "device_id": mustGetDocIDFromDocMap(map[string]any{"model": "iPhone"}, colDefMap["Device"]), }, { "name": "Fred", - "device_id": mustGetDocIDFromDocMap(map[string]any{"model": "MacBook"}, colDefMap["Device"].Schema), + "device_id": mustGetDocIDFromDocMap(map[string]any{"model": "MacBook"}, colDefMap["Device"]), }, - }, colDefMap["User"].Schema) + }, colDefMap["User"]) deviceDocs := mustAddDocIDsToDocs([]map[string]any{ {"model": "iPhone"}, {"model": "MacBook"}, - }, colDefMap["Device"].Schema) + }, colDefMap["Device"]) errorMsg := assertDocs(append(userDocs, deviceDocs...), docs) if errorMsg != "" { @@ -216,15 +216,15 @@ func TestGeneratePredefinedFromSchema_OneToOneToOnePrimary(t *testing.T) { colDefMap, err := parseSDL(schema) require.NoError(t, err) - specsDoc := mustAddDocIDToDoc(map[string]any{"OS": "iOS"}, colDefMap["Specs"].Schema) + specsDoc := mustAddDocIDToDoc(map[string]any{"OS": "iOS"}, colDefMap["Specs"]) deviceDoc := mustAddDocIDToDoc(map[string]any{ "model": "iPhone", "specs_id": specsDoc[request.DocIDFieldName], - }, colDefMap["Device"].Schema) + }, colDefMap["Device"]) userDoc := mustAddDocIDToDoc(map[string]any{ "name": "John", "device_id": deviceDoc[request.DocIDFieldName], - }, colDefMap["User"].Schema) + }, colDefMap["User"]) errorMsg := assertDocs([]map[string]any{userDoc, deviceDoc, specsDoc}, docs) if errorMsg != "" { @@ -267,13 +267,13 @@ func TestGeneratePredefinedFromSchema_TwoPrimaryToOneMiddle(t *testing.T) { colDefMap, err := parseSDL(schema) require.NoError(t, err) - specsDoc := mustAddDocIDToDoc(map[string]any{"OS": "iOS"}, colDefMap["Specs"].Schema) - userDoc := mustAddDocIDToDoc(map[string]any{"name": "John"}, colDefMap["User"].Schema) + specsDoc := mustAddDocIDToDoc(map[string]any{"OS": "iOS"}, colDefMap["Specs"]) + userDoc := mustAddDocIDToDoc(map[string]any{"name": "John"}, colDefMap["User"]) deviceDoc := mustAddDocIDToDoc(map[string]any{ "model": "iPhone", "specs_id": specsDoc[request.DocIDFieldName], "owner_id": userDoc[request.DocIDFieldName], - }, colDefMap["Device"].Schema) + }, colDefMap["Device"]) errorMsg := assertDocs([]map[string]any{userDoc, deviceDoc, specsDoc}, docs) if errorMsg != "" { @@ -316,15 +316,15 @@ func TestGeneratePredefinedFromSchema_OneToTwoPrimary(t *testing.T) { colDefMap, err := parseSDL(schema) require.NoError(t, err) - deviceDoc := mustAddDocIDToDoc(map[string]any{"model": "iPhone"}, colDefMap["Device"].Schema) + deviceDoc := mustAddDocIDToDoc(map[string]any{"model": "iPhone"}, colDefMap["Device"]) specsDoc := mustAddDocIDToDoc(map[string]any{ "OS": "iOS", "device_id": deviceDoc[request.DocIDFieldName], - }, colDefMap["Specs"].Schema) + }, colDefMap["Specs"]) userDoc := mustAddDocIDToDoc(map[string]any{ "name": "John", "device_id": deviceDoc[request.DocIDFieldName], - }, colDefMap["User"].Schema) + }, colDefMap["User"]) errorMsg := assertDocs([]map[string]any{userDoc, deviceDoc, specsDoc}, docs) if errorMsg != "" { @@ -367,13 +367,13 @@ func TestGeneratePredefinedFromSchema_TwoPrimaryToOneRoot(t *testing.T) { colDefMap, err := parseSDL(schema) require.NoError(t, err) - deviceDoc := mustAddDocIDToDoc(map[string]any{"model": "iPhone"}, colDefMap["Device"].Schema) - addressDoc := mustAddDocIDToDoc(map[string]any{"street": "Backer"}, colDefMap["Address"].Schema) + deviceDoc := mustAddDocIDToDoc(map[string]any{"model": "iPhone"}, colDefMap["Device"]) + addressDoc := mustAddDocIDToDoc(map[string]any{"street": "Backer"}, colDefMap["Address"]) userDoc := mustAddDocIDToDoc(map[string]any{ "name": "John", "device_id": deviceDoc[request.DocIDFieldName], "address_id": addressDoc[request.DocIDFieldName], - }, colDefMap["User"].Schema) + }, colDefMap["User"]) errorMsg := assertDocs([]map[string]any{userDoc, deviceDoc, addressDoc}, docs) if errorMsg != "" { diff --git a/tests/predefined/util_test.go b/tests/predefined/util_test.go index f155062503..0160470b53 100644 --- a/tests/predefined/util_test.go +++ b/tests/predefined/util_test.go @@ -68,22 +68,22 @@ outer: return "" } -func mustGetDocIDFromDocMap(docMap map[string]any, sd client.SchemaDescription) string { - doc, err := client.NewDocFromMap(docMap, sd) +func mustGetDocIDFromDocMap(docMap map[string]any, collectionDefinition client.CollectionDefinition) string { + doc, err := client.NewDocFromMap(docMap, collectionDefinition) if err != nil { panic("can not get doc from map" + err.Error()) } return doc.ID().String() } -func mustAddDocIDToDoc(doc map[string]any, sd client.SchemaDescription) map[string]any { - doc[request.DocIDFieldName] = mustGetDocIDFromDocMap(doc, sd) +func mustAddDocIDToDoc(doc map[string]any, collectionDefinition client.CollectionDefinition) map[string]any { + doc[request.DocIDFieldName] = mustGetDocIDFromDocMap(doc, collectionDefinition) return doc } -func mustAddDocIDsToDocs(docs []map[string]any, sd client.SchemaDescription) []map[string]any { +func mustAddDocIDsToDocs(docs []map[string]any, collectionDefinition client.CollectionDefinition) []map[string]any { for i := range docs { - mustAddDocIDToDoc(docs[i], sd) + mustAddDocIDToDoc(docs[i], collectionDefinition) } return docs } From 76077b11f89e940623e2a3cd4f748945b04be031 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Fri, 12 Apr 2024 13:28:42 -0400 Subject: [PATCH 07/11] FIXUP - Fix schema version id tests Broken out of 'Move relation field properties onto collection' as to not clutter the diff for reviewers. --- acp/README.md | 2 +- .../events/simple/with_update_test.go | 4 +- .../mutation/create/with_version_test.go | 2 +- .../peer/subscribe/with_add_get_test.go | 2 +- .../simple/replicator/with_create_test.go | 4 +- .../integration/query/commits/simple_test.go | 50 +++++++------- .../query/commits/with_cid_test.go | 8 +-- .../query/commits/with_depth_test.go | 34 +++++----- .../query/commits/with_doc_id_cid_test.go | 4 +- .../query/commits/with_doc_id_count_test.go | 6 +- .../query/commits/with_doc_id_field_test.go | 4 +- .../commits/with_doc_id_limit_offset_test.go | 4 +- .../query/commits/with_doc_id_limit_test.go | 4 +- .../with_doc_id_order_limit_offset_test.go | 4 +- .../query/commits/with_doc_id_order_test.go | 66 +++++++++--------- .../query/commits/with_doc_id_test.go | 46 ++++++------- .../commits/with_doc_id_typename_test.go | 6 +- .../query/commits/with_field_test.go | 8 +-- .../query/commits/with_group_test.go | 16 ++--- .../latest_commits/with_doc_id_field_test.go | 8 +-- .../query/latest_commits/with_doc_id_test.go | 10 +-- .../query/one_to_many/with_cid_doc_id_test.go | 8 +-- .../query/simple/with_cid_doc_id_test.go | 20 +++--- .../query/simple/with_version_test.go | 38 +++++------ tests/integration/schema/crdt_type_test.go | 8 +-- tests/integration/schema/get_schema_test.go | 14 ++-- .../schema/migrations/query/simple_test.go | 68 +++++++++---------- .../migrations/query/with_doc_id_test.go | 8 +-- .../migrations/query/with_inverse_test.go | 10 +-- .../query/with_p2p_schema_branch_test.go | 4 +- .../schema/migrations/query/with_p2p_test.go | 20 +++--- .../migrations/query/with_restart_test.go | 8 +-- .../query/with_schema_branch_test.go | 2 +- .../migrations/query/with_set_default_test.go | 10 +-- .../schema/migrations/query/with_txn_test.go | 8 +-- .../migrations/query/with_update_test.go | 8 +-- .../schema/migrations/simple_test.go | 8 +-- tests/integration/schema/simple_test.go | 2 +- .../updates/add/field/create_update_test.go | 8 +-- .../schema/updates/add/field/simple_test.go | 8 +-- .../schema/updates/move/simple_test.go | 2 +- .../schema/updates/with_schema_branch_test.go | 30 ++++---- .../schema/with_update_set_default_test.go | 4 +- 43 files changed, 294 insertions(+), 294 deletions(-) diff --git a/acp/README.md b/acp/README.md index 3fb49968f8..697a60a0c2 100644 --- a/acp/README.md +++ b/acp/README.md @@ -212,7 +212,7 @@ Result: "Name": "Users", "ID": 1, "RootID": 1, - "SchemaVersionID": "bafkreibthhctfd3rykinfa6ivvkhegp7sbhk5yvujdkhase7ilj5dz5gqi", + "SchemaVersionID": "bafkreihhd6bqrjhl5zidwztgxzeseveplv3cj3fwtn3unjkdx7j2vr2vrq", "Sources": [], "Fields": [ { diff --git a/tests/integration/events/simple/with_update_test.go b/tests/integration/events/simple/with_update_test.go index 6ad73d6ce1..d224690827 100644 --- a/tests/integration/events/simple/with_update_test.go +++ b/tests/integration/events/simple/with_update_test.go @@ -66,14 +66,14 @@ func TestEventsSimpleWithUpdate(t *testing.T) { ExpectedUpdates: []testUtils.ExpectedUpdate{ { DocID: immutable.Some(docID1), - Cid: immutable.Some("bafybeidlsifvletowavkcihp2d4k62ayuznumttxsseqynatufwnahiste"), + Cid: immutable.Some("bafybeif757a4mdwimqwl24ujjnao6xlajiajz2hwuleopnptusuttri6zu"), }, { DocID: immutable.Some(docID2), }, { DocID: immutable.Some(docID1), - Cid: immutable.Some("bafybeidpwcpixokptqamh7qvngbrm335mvrzs3skrlwdmkq6nmqesoj4sm"), + Cid: immutable.Some("bafybeifhmjw6ay5rvwznqh37ogcw5hrmqtxrnredoh6psn7lhgtdc253km"), }, }, } diff --git a/tests/integration/mutation/create/with_version_test.go b/tests/integration/mutation/create/with_version_test.go index b500ce1daf..943916f1ed 100644 --- a/tests/integration/mutation/create/with_version_test.go +++ b/tests/integration/mutation/create/with_version_test.go @@ -39,7 +39,7 @@ func TestMutationCreate_ReturnsVersionCID(t *testing.T) { { "_version": []map[string]any{ { - "cid": "bafybeidlsifvletowavkcihp2d4k62ayuznumttxsseqynatufwnahiste", + "cid": "bafybeif757a4mdwimqwl24ujjnao6xlajiajz2hwuleopnptusuttri6zu", }, }, }, diff --git a/tests/integration/net/state/simple/peer/subscribe/with_add_get_test.go b/tests/integration/net/state/simple/peer/subscribe/with_add_get_test.go index 8fd73fe06a..b5990a050f 100644 --- a/tests/integration/net/state/simple/peer/subscribe/with_add_get_test.go +++ b/tests/integration/net/state/simple/peer/subscribe/with_add_get_test.go @@ -76,7 +76,7 @@ func TestP2PSubscribeAddGetMultiple(t *testing.T) { }, testUtils.GetAllP2PCollections{ NodeID: 1, - ExpectedCollectionIDs: []int{2, 0}, + ExpectedCollectionIDs: []int{0, 2}, }, }, } diff --git a/tests/integration/net/state/simple/replicator/with_create_test.go b/tests/integration/net/state/simple/replicator/with_create_test.go index 9fee99880a..0d3dbad143 100644 --- a/tests/integration/net/state/simple/replicator/with_create_test.go +++ b/tests/integration/net/state/simple/replicator/with_create_test.go @@ -492,7 +492,7 @@ func TestP2POneToOneReplicatorOrderIndependent(t *testing.T) { "name": "John", "_version": []map[string]any{ { - "schemaVersionId": "bafkreibthhctfd3rykinfa6ivvkhegp7sbhk5yvujdkhase7ilj5dz5gqi", + "schemaVersionId": "bafkreihhd6bqrjhl5zidwztgxzeseveplv3cj3fwtn3unjkdx7j2vr2vrq", }, }, }, @@ -552,7 +552,7 @@ func TestP2POneToOneReplicatorOrderIndependentDirectCreate(t *testing.T) { "_docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7", "_version": []map[string]any{ { - "schemaVersionId": "bafkreibthhctfd3rykinfa6ivvkhegp7sbhk5yvujdkhase7ilj5dz5gqi", + "schemaVersionId": "bafkreihhd6bqrjhl5zidwztgxzeseveplv3cj3fwtn3unjkdx7j2vr2vrq", }, }, }, diff --git a/tests/integration/query/commits/simple_test.go b/tests/integration/query/commits/simple_test.go index 7297f7fa4a..b90d5d0ea4 100644 --- a/tests/integration/query/commits/simple_test.go +++ b/tests/integration/query/commits/simple_test.go @@ -36,13 +36,13 @@ func TestQueryCommits(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", }, }, }, @@ -79,22 +79,22 @@ func TestQueryCommitsMultipleDocs(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeiev2thtqxttuhr3aq5dvyb3aif4cey7werksskw5xuetmwxjxi7ty", + "cid": "bafybeihnalsemihsyycy3vaxbhq6iqrixmsk5k3idq52u76h2f5wkvobx4", }, { - "cid": "bafybeifos5iir63tmp3bdoj7zr5aand4ud2tf2qfnjlh6nvrzw3knkewuy", + "cid": "bafybeifxk5rhzuemqn2o35hh7346gydqlfmhkdzeguiqo5vczgyz4xz7rm", }, { - "cid": "bafybeicjb4x47xk6koh4uhgokhjr5zbg3bhbcfoa4um4vdktnbhrsx6d2a", + "cid": "bafybeig36zwhejk54nvvey5wsfbl7rzm7xscsyji5uqp6j4hw4zh7dhep4", }, { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", }, }, }, @@ -125,16 +125,16 @@ func TestQueryCommitsWithSchemaVersionIdField(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", - "schemaVersionId": "bafkreibpk53kumv6q3kkc3hz2y57tnbgizpodk3vleyc3h5muv6vm4pdoe", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", + "schemaVersionId": "bafkreicprhqxzlw3akyssz2v6pifwfueavp7jq2yj3dghapi3qcq6achs4", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", - "schemaVersionId": "bafkreibpk53kumv6q3kkc3hz2y57tnbgizpodk3vleyc3h5muv6vm4pdoe", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", + "schemaVersionId": "bafkreicprhqxzlw3akyssz2v6pifwfueavp7jq2yj3dghapi3qcq6achs4", }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", - "schemaVersionId": "bafkreibpk53kumv6q3kkc3hz2y57tnbgizpodk3vleyc3h5muv6vm4pdoe", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", + "schemaVersionId": "bafkreicprhqxzlw3akyssz2v6pifwfueavp7jq2yj3dghapi3qcq6achs4", }, }, }, @@ -349,7 +349,7 @@ func TestQuery_CommitsWithAllFieldsWithUpdate_NoError(t *testing.T) { `, Results: []map[string]any{ { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", "collectionID": int64(1), "delta": testUtils.CBORValue(22), "docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7", @@ -358,13 +358,13 @@ func TestQuery_CommitsWithAllFieldsWithUpdate_NoError(t *testing.T) { "height": int64(2), "links": []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "name": "_head", }, }, }, { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "collectionID": int64(1), "delta": testUtils.CBORValue(21), "docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7", @@ -374,7 +374,7 @@ func TestQuery_CommitsWithAllFieldsWithUpdate_NoError(t *testing.T) { "links": []map[string]any{}, }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "collectionID": int64(1), "delta": testUtils.CBORValue("John"), "docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7", @@ -384,7 +384,7 @@ func TestQuery_CommitsWithAllFieldsWithUpdate_NoError(t *testing.T) { "links": []map[string]any{}, }, { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "collectionID": int64(1), "delta": nil, "docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7", @@ -393,17 +393,17 @@ func TestQuery_CommitsWithAllFieldsWithUpdate_NoError(t *testing.T) { "height": int64(2), "links": []map[string]any{ { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "name": "_head", }, { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", "name": "age", }, }, }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "collectionID": int64(1), "delta": nil, "docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7", @@ -412,11 +412,11 @@ func TestQuery_CommitsWithAllFieldsWithUpdate_NoError(t *testing.T) { "height": int64(1), "links": []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "name": "age", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "name": "name", }, }, diff --git a/tests/integration/query/commits/with_cid_test.go b/tests/integration/query/commits/with_cid_test.go index 30eab52b47..22f2caa5c2 100644 --- a/tests/integration/query/commits/with_cid_test.go +++ b/tests/integration/query/commits/with_cid_test.go @@ -38,14 +38,14 @@ func TestQueryCommitsWithCid(t *testing.T) { testUtils.Request{ Request: `query { commits( - cid: "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva" + cid: "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq" ) { cid } }`, Results: []map[string]any{ { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", }, }, }, @@ -71,14 +71,14 @@ func TestQueryCommitsWithCidForFieldCommit(t *testing.T) { testUtils.Request{ Request: `query { commits( - cid: "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva" + cid: "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq" ) { cid } }`, Results: []map[string]any{ { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", }, }, }, diff --git a/tests/integration/query/commits/with_depth_test.go b/tests/integration/query/commits/with_depth_test.go index e31a18c9c7..3475985174 100644 --- a/tests/integration/query/commits/with_depth_test.go +++ b/tests/integration/query/commits/with_depth_test.go @@ -36,13 +36,13 @@ func TestQueryCommitsWithDepth1(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", }, }, }, @@ -81,16 +81,16 @@ func TestQueryCommitsWithDepth1WithUpdate(t *testing.T) { Results: []map[string]any{ { // "Age" field head - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", "height": int64(2), }, { // "Name" field head (unchanged from create) - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "height": int64(1), }, { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "height": int64(2), }, }, @@ -137,27 +137,27 @@ func TestQueryCommitsWithDepth2WithUpdate(t *testing.T) { Results: []map[string]any{ { // Composite head - "cid": "bafybeiewgawahat7sxdoafvu77uvsaaj2ttatqllj2qvnqhornzxl2gteq", + "cid": "bafybeigzaxekosbmrfrzjhkztodipzmz3voiqnia275347b6vkq5keouf4", "height": int64(3), }, { // Composite head -1 - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", "height": int64(2), }, { // "Name" field head (unchanged from create) - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "height": int64(1), }, { // "Age" field head - "cid": "bafybeid44afmsi6hh6yasgcjncnlvdpqsu2durizsxhdmhsbrqekypf6aa", + "cid": "bafybeifwa5vgfvnrdwzqmojsxilwbg2k37axh2fs57zfmddz3l5yivn4la", "height": int64(3), }, { // "Age" field head -1 - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "height": int64(2), }, }, @@ -195,22 +195,22 @@ func TestQueryCommitsWithDepth1AndMultipleDocs(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieepmzk3s5dzxztfq5zi5e5g3mnb6yfumx3euknnbur4x3a5neidq", + "cid": "bafybeicacj5fmr267b6kkmv4ck3g5cm5odca7hu7ajwagfttpspbsu7n5u", }, { - "cid": "bafybeifcxdrzqfj54w5mls7mf6nhxtjnweoevves7rwzsda6gmvzqc4t7y", + "cid": "bafybeiexu7xpwhyo2azo2ap2nbny5d4chhr725xrhmxnt5ebabucyjlfqu", }, { - "cid": "bafybeihavavtkfgaevtnzbabdwmgpamgbpkonw4ardalsamcitspqaxhs4", + "cid": "bafybeibbp6jn7y2t6jakbdtvboruieo3iobyuumppbwbw7rwkmz4tdh5yq", }, { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", }, }, }, diff --git a/tests/integration/query/commits/with_doc_id_cid_test.go b/tests/integration/query/commits/with_doc_id_cid_test.go index abaaa4b434..9f61805048 100644 --- a/tests/integration/query/commits/with_doc_id_cid_test.go +++ b/tests/integration/query/commits/with_doc_id_cid_test.go @@ -104,14 +104,14 @@ func TestQueryCommitsWithDocIDAndCidWithUpdate(t *testing.T) { Request: ` { commits( docID: "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7", - cid: "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4" + cid: "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm" ) { cid } }`, Results: []map[string]any{ { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", }, }, }, diff --git a/tests/integration/query/commits/with_doc_id_count_test.go b/tests/integration/query/commits/with_doc_id_count_test.go index da28665990..89ba666163 100644 --- a/tests/integration/query/commits/with_doc_id_count_test.go +++ b/tests/integration/query/commits/with_doc_id_count_test.go @@ -37,15 +37,15 @@ func TestQueryCommitsWithDocIDAndLinkCount(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "_count": 0, }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "_count": 0, }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "_count": 2, }, }, diff --git a/tests/integration/query/commits/with_doc_id_field_test.go b/tests/integration/query/commits/with_doc_id_field_test.go index 790fa672a1..65fb4a5637 100644 --- a/tests/integration/query/commits/with_doc_id_field_test.go +++ b/tests/integration/query/commits/with_doc_id_field_test.go @@ -118,7 +118,7 @@ func TestQueryCommitsWithDocIDAndFieldId(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", }, }, }, @@ -150,7 +150,7 @@ func TestQueryCommitsWithDocIDAndCompositeFieldId(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", }, }, }, diff --git a/tests/integration/query/commits/with_doc_id_limit_offset_test.go b/tests/integration/query/commits/with_doc_id_limit_offset_test.go index 84be4f5682..47b21aaf08 100644 --- a/tests/integration/query/commits/with_doc_id_limit_offset_test.go +++ b/tests/integration/query/commits/with_doc_id_limit_offset_test.go @@ -57,10 +57,10 @@ func TestQueryCommitsWithDocIDAndLimitAndOffset(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeiewgawahat7sxdoafvu77uvsaaj2ttatqllj2qvnqhornzxl2gteq", + "cid": "bafybeigzaxekosbmrfrzjhkztodipzmz3voiqnia275347b6vkq5keouf4", }, { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", }, }, }, diff --git a/tests/integration/query/commits/with_doc_id_limit_test.go b/tests/integration/query/commits/with_doc_id_limit_test.go index a84344a402..938ce72ea9 100644 --- a/tests/integration/query/commits/with_doc_id_limit_test.go +++ b/tests/integration/query/commits/with_doc_id_limit_test.go @@ -50,10 +50,10 @@ func TestQueryCommitsWithDocIDAndLimit(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeiewgawahat7sxdoafvu77uvsaaj2ttatqllj2qvnqhornzxl2gteq", + "cid": "bafybeigzaxekosbmrfrzjhkztodipzmz3voiqnia275347b6vkq5keouf4", }, { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", }, }, }, diff --git a/tests/integration/query/commits/with_doc_id_order_limit_offset_test.go b/tests/integration/query/commits/with_doc_id_order_limit_offset_test.go index 6ccf0cca44..058825acca 100644 --- a/tests/integration/query/commits/with_doc_id_order_limit_offset_test.go +++ b/tests/integration/query/commits/with_doc_id_order_limit_offset_test.go @@ -58,11 +58,11 @@ func TestQueryCommitsWithDocIDAndOrderAndLimitAndOffset(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "height": int64(2), }, { - "cid": "bafybeiewgawahat7sxdoafvu77uvsaaj2ttatqllj2qvnqhornzxl2gteq", + "cid": "bafybeigzaxekosbmrfrzjhkztodipzmz3voiqnia275347b6vkq5keouf4", "height": int64(3), }, }, diff --git a/tests/integration/query/commits/with_doc_id_order_test.go b/tests/integration/query/commits/with_doc_id_order_test.go index 02f4426958..70ab643688 100644 --- a/tests/integration/query/commits/with_doc_id_order_test.go +++ b/tests/integration/query/commits/with_doc_id_order_test.go @@ -44,23 +44,23 @@ func TestQueryCommitsWithDocIDAndOrderHeightDesc(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", "height": int64(2), }, { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "height": int64(2), }, { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "height": int64(1), }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "height": int64(1), }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "height": int64(1), }, }, @@ -99,23 +99,23 @@ func TestQueryCommitsWithDocIDAndOrderHeightAsc(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "height": int64(1), }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "height": int64(1), }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "height": int64(1), }, { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", "height": int64(2), }, { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "height": int64(2), }, }, @@ -154,24 +154,24 @@ func TestQueryCommitsWithDocIDAndOrderCidDesc(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "height": int64(1), }, { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "height": int64(1), }, { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "height": int64(2), }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", - "height": int64(1), + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", + "height": int64(2), }, { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", - "height": int64(2), + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", + "height": int64(1), }, }, }, @@ -209,23 +209,23 @@ func TestQueryCommitsWithDocIDAndOrderCidAsc(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", - "height": int64(2), + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", + "height": int64(1), }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", - "height": int64(1), + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", + "height": int64(2), }, { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "height": int64(2), }, { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "height": int64(1), }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "height": int64(1), }, }, @@ -278,39 +278,39 @@ func TestQueryCommitsWithDocIDAndOrderAndMultiUpdatesCidAsc(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "height": int64(1), }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "height": int64(1), }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "height": int64(1), }, { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", "height": int64(2), }, { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "height": int64(2), }, { - "cid": "bafybeiewgawahat7sxdoafvu77uvsaaj2ttatqllj2qvnqhornzxl2gteq", + "cid": "bafybeigzaxekosbmrfrzjhkztodipzmz3voiqnia275347b6vkq5keouf4", "height": int64(3), }, { - "cid": "bafybeid44afmsi6hh6yasgcjncnlvdpqsu2durizsxhdmhsbrqekypf6aa", + "cid": "bafybeifwa5vgfvnrdwzqmojsxilwbg2k37axh2fs57zfmddz3l5yivn4la", "height": int64(3), }, { - "cid": "bafybeifq2bd3nkqa6q5tjb5lrmeoskimtchhodvcxdqeilck2x4k3z7ijq", + "cid": "bafybeifn2f5lgzall3dzva47khbtib77lt7ve5qyclou3ihi2hy2uqj4nm", "height": int64(4), }, { - "cid": "bafybeiakoro6m2bvfmtmczykyffvixx6ci7tbgczebhdwttx5ymh5c7wyy", + "cid": "bafybeieijpm36ntafrncl4kgx6dkxgpbftcl4f7obbbmagurcgdoj6sl5y", "height": int64(4), }, }, diff --git a/tests/integration/query/commits/with_doc_id_test.go b/tests/integration/query/commits/with_doc_id_test.go index b57219df46..1524409663 100644 --- a/tests/integration/query/commits/with_doc_id_test.go +++ b/tests/integration/query/commits/with_doc_id_test.go @@ -62,13 +62,13 @@ func TestQueryCommitsWithDocID(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", }, }, }, @@ -102,22 +102,22 @@ func TestQueryCommitsWithDocIDAndLinks(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "links": []map[string]any{}, }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "links": []map[string]any{}, }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "links": []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "name": "age", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "name": "name", }, }, @@ -158,23 +158,23 @@ func TestQueryCommitsWithDocIDAndUpdate(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", "height": int64(2), }, { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "height": int64(1), }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "height": int64(1), }, { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "height": int64(2), }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "height": int64(1), }, }, @@ -219,44 +219,44 @@ func TestQueryCommitsWithDocIDAndUpdateAndLinks(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", "links": []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "name": "_head", }, }, }, { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "links": []map[string]any{}, }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "links": []map[string]any{}, }, { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", "links": []map[string]any{ { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "name": "_head", }, { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", "name": "age", }, }, }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "links": []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "name": "age", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "name": "name", }, }, diff --git a/tests/integration/query/commits/with_doc_id_typename_test.go b/tests/integration/query/commits/with_doc_id_typename_test.go index 17a1422d7b..51bc88a946 100644 --- a/tests/integration/query/commits/with_doc_id_typename_test.go +++ b/tests/integration/query/commits/with_doc_id_typename_test.go @@ -37,15 +37,15 @@ func TestQueryCommitsWithDocIDWithTypeName(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "__typename": "Commit", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "__typename": "Commit", }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "__typename": "Commit", }, }, diff --git a/tests/integration/query/commits/with_field_test.go b/tests/integration/query/commits/with_field_test.go index bebd35b828..1ea35a8d96 100644 --- a/tests/integration/query/commits/with_field_test.go +++ b/tests/integration/query/commits/with_field_test.go @@ -66,7 +66,7 @@ func TestQueryCommitsWithFieldId(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", }, }, }, @@ -98,7 +98,7 @@ func TestQueryCommitsWithCompositeFieldId(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", }, }, }, @@ -131,8 +131,8 @@ func TestQueryCommitsWithCompositeFieldIdWithReturnedSchemaVersionId(t *testing. }`, Results: []map[string]any{ { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", - "schemaVersionId": "bafkreibpk53kumv6q3kkc3hz2y57tnbgizpodk3vleyc3h5muv6vm4pdoe", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", + "schemaVersionId": "bafkreicprhqxzlw3akyssz2v6pifwfueavp7jq2yj3dghapi3qcq6achs4", }, }, }, diff --git a/tests/integration/query/commits/with_group_test.go b/tests/integration/query/commits/with_group_test.go index 414df231c2..1971e6f6dd 100644 --- a/tests/integration/query/commits/with_group_test.go +++ b/tests/integration/query/commits/with_group_test.go @@ -89,10 +89,10 @@ func TestQueryCommitsWithGroupByHeightWithChild(t *testing.T) { "height": int64(2), "_group": []map[string]any{ { - "cid": "bafybeia7qkfbfm4jijlkqs6uxziie2v57nin5gaa3afnpkruw352mmrt4q", + "cid": "bafybeiaho26jaxdjfuvyxozws6ushksjwidllvgai6kgxmqxhzylwzkvte", }, { - "cid": "bafybeid4fh7ggr2wgema6b5hrqroimcso3vxyous3oyck5c66vm72br7z4", + "cid": "bafybeiep7c6ouykgidnwzjeasyim3ost5qjkro4qvs62t4u4u7rolbmugm", }, }, }, @@ -100,13 +100,13 @@ func TestQueryCommitsWithGroupByHeightWithChild(t *testing.T) { "height": int64(1), "_group": []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", }, }, }, @@ -142,7 +142,7 @@ func TestQueryCommitsWithGroupByCidWithChild(t *testing.T) { }`, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "_group": []map[string]any{ { "height": int64(1), @@ -150,7 +150,7 @@ func TestQueryCommitsWithGroupByCidWithChild(t *testing.T) { }, }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "_group": []map[string]any{ { "height": int64(1), @@ -158,7 +158,7 @@ func TestQueryCommitsWithGroupByCidWithChild(t *testing.T) { }, }, { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "_group": []map[string]any{ { "height": int64(1), diff --git a/tests/integration/query/latest_commits/with_doc_id_field_test.go b/tests/integration/query/latest_commits/with_doc_id_field_test.go index 4c7ed89f9c..0b886b966a 100644 --- a/tests/integration/query/latest_commits/with_doc_id_field_test.go +++ b/tests/integration/query/latest_commits/with_doc_id_field_test.go @@ -68,7 +68,7 @@ func TestQueryLatestCommitsWithDocIDAndFieldId(t *testing.T) { }, Results: []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "links": []map[string]any{}, }, }, @@ -101,14 +101,14 @@ func TestQueryLatestCommitsWithDocIDAndCompositeFieldId(t *testing.T) { }, Results: []map[string]any{ { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "links": []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "name": "age", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "name": "name", }, }, diff --git a/tests/integration/query/latest_commits/with_doc_id_test.go b/tests/integration/query/latest_commits/with_doc_id_test.go index 0ef237c300..089f6f5086 100644 --- a/tests/integration/query/latest_commits/with_doc_id_test.go +++ b/tests/integration/query/latest_commits/with_doc_id_test.go @@ -38,14 +38,14 @@ func TestQueryLatestCommitsWithDocID(t *testing.T) { }, Results: []map[string]any{ { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", "links": []map[string]any{ { - "cid": "bafybeieoeoset5itv7alud2yzjmq6dqizymdwdmlvyxam2uxe4lfexooaq", + "cid": "bafybeietdefm4jtgcbpof5elqdptwnuevvzujb3j22n6dytx67vpmb3xn4", "name": "age", }, { - "cid": "bafybeih4plbb3rinhqvn663ssfwhnujdbnbjistymzowsry5nvmxchmqny", + "cid": "bafybeihc26puzzgnctvgvgowihytif52tmdj3y2ksx6tvge2wtjkjvtszi", "name": "name", }, }, @@ -75,8 +75,8 @@ func TestQueryLatestCommitsWithDocIDWithSchemaVersionIdField(t *testing.T) { }, Results: []map[string]any{ { - "cid": "bafybeic2zvs2beirqmgd45myszkqwj32w3oyduolugkxv4gxxph4c4mzva", - "schemaVersionId": "bafkreibpk53kumv6q3kkc3hz2y57tnbgizpodk3vleyc3h5muv6vm4pdoe", + "cid": "bafybeiafufeqwjo5eeeaobwiu6ibf73dnvlefr47mrx45z42337mfnezkq", + "schemaVersionId": "bafkreicprhqxzlw3akyssz2v6pifwfueavp7jq2yj3dghapi3qcq6achs4", }, }, } diff --git a/tests/integration/query/one_to_many/with_cid_doc_id_test.go b/tests/integration/query/one_to_many/with_cid_doc_id_test.go index 843bf12638..f3f5ff580c 100644 --- a/tests/integration/query/one_to_many/with_cid_doc_id_test.go +++ b/tests/integration/query/one_to_many/with_cid_doc_id_test.go @@ -104,7 +104,7 @@ func TestQueryOneToManyWithCidAndDocID(t *testing.T) { testUtils.Request{ Request: `query { Book ( - cid: "bafybeidixr5nt7vb5go4nx675exjubb6g7sn2upltkfvf4piepgcd5ntjm" + cid: "bafybeia3qbhebdwssoe5udinpbdj4pntb5wjr77ql7ptzq32howbaxz2cu" docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" ) { name @@ -179,7 +179,7 @@ func TestQueryOneToManyWithChildUpdateAndFirstCidAndDocID(t *testing.T) { testUtils.Request{ Request: `query { Book ( - cid: "bafybeidixr5nt7vb5go4nx675exjubb6g7sn2upltkfvf4piepgcd5ntjm", + cid: "bafybeia3qbhebdwssoe5udinpbdj4pntb5wjr77ql7ptzq32howbaxz2cu", docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" ) { name @@ -252,7 +252,7 @@ func TestQueryOneToManyWithParentUpdateAndFirstCidAndDocID(t *testing.T) { testUtils.Request{ Request: `query { Book ( - cid: "bafybeidixr5nt7vb5go4nx675exjubb6g7sn2upltkfvf4piepgcd5ntjm", + cid: "bafybeia3qbhebdwssoe5udinpbdj4pntb5wjr77ql7ptzq32howbaxz2cu", docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" ) { rating @@ -324,7 +324,7 @@ func TestQueryOneToManyWithParentUpdateAndLastCidAndDocID(t *testing.T) { testUtils.Request{ Request: `query { Book ( - cid: "bafybeicuhxlsrkonczjlrpj77xbg6fxgkncictecifxe7rdw4egxs72kse", + cid: "bafybeibqkdnc63xh5k4frs3x3k7z7p6sw4usjrhxd4iusbjj2uhxfjfjcq", docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" ) { rating diff --git a/tests/integration/query/simple/with_cid_doc_id_test.go b/tests/integration/query/simple/with_cid_doc_id_test.go index 7c265a409c..6fe41d1aae 100644 --- a/tests/integration/query/simple/with_cid_doc_id_test.go +++ b/tests/integration/query/simple/with_cid_doc_id_test.go @@ -93,7 +93,7 @@ func TestQuerySimpleWithCidAndDocID(t *testing.T) { testUtils.Request{ Request: `query { Users ( - cid: "bafybeidlsifvletowavkcihp2d4k62ayuznumttxsseqynatufwnahiste", + cid: "bafybeif757a4mdwimqwl24ujjnao6xlajiajz2hwuleopnptusuttri6zu", docID: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" ) { name @@ -135,7 +135,7 @@ func TestQuerySimpleWithUpdateAndFirstCidAndDocID(t *testing.T) { testUtils.Request{ Request: `query { Users ( - cid: "bafybeidlsifvletowavkcihp2d4k62ayuznumttxsseqynatufwnahiste", + cid: "bafybeif757a4mdwimqwl24ujjnao6xlajiajz2hwuleopnptusuttri6zu", docID: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" ) { name @@ -177,7 +177,7 @@ func TestQuerySimpleWithUpdateAndLastCidAndDocID(t *testing.T) { testUtils.Request{ Request: `query { Users ( - cid: "bafybeicowz6vraybays3br77rm4yzkiykr6jlp3mmsbyqbkcvk2cdukdru", + cid: "bafybeibwxvtvppws6sjfoajazevrdh27g4qwn5wguslpabyl3kzxd2a6fm", docID: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" ) { name @@ -224,7 +224,7 @@ func TestQuerySimpleWithUpdateAndMiddleCidAndDocID(t *testing.T) { testUtils.Request{ Request: `query { Users ( - cid: "bafybeicowz6vraybays3br77rm4yzkiykr6jlp3mmsbyqbkcvk2cdukdru", + cid: "bafybeibwxvtvppws6sjfoajazevrdh27g4qwn5wguslpabyl3kzxd2a6fm", docID: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" ) { name @@ -266,7 +266,7 @@ func TestQuerySimpleWithUpdateAndFirstCidAndDocIDAndSchemaVersion(t *testing.T) testUtils.Request{ Request: `query { Users ( - cid: "bafybeidlsifvletowavkcihp2d4k62ayuznumttxsseqynatufwnahiste", + cid: "bafybeif757a4mdwimqwl24ujjnao6xlajiajz2hwuleopnptusuttri6zu", docID: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" ) { name @@ -280,7 +280,7 @@ func TestQuerySimpleWithUpdateAndFirstCidAndDocIDAndSchemaVersion(t *testing.T) "name": "John", "_version": []map[string]any{ { - "schemaVersionId": "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", + "schemaVersionId": "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", }, }, }, @@ -324,7 +324,7 @@ func TestCidAndDocIDQuery_ContainsPNCounterWithIntKind_NoError(t *testing.T) { testUtils.Request{ Request: `query { Users ( - cid: "bafybeihd4uju62lpqft3fheevde2cmcehty3zqkbpyp2zu2ehfwietcu5i", + cid: "bafybeicruxxfhxhyvefbxid7gukdbnfzkyad45phu4mnwzzqde24p32xnu", docID: "bae-a688789e-d8a6-57a7-be09-22e005ab79e0" ) { name @@ -376,7 +376,7 @@ func TestCidAndDocIDQuery_ContainsPNCounterWithFloatKind_NoError(t *testing.T) { testUtils.Request{ Request: `query { Users ( - cid: "bafybeiecgpblwcvgs3lw66v2p7frvwwak4gg4754dax742lomfxfrrvb4i", + cid: "bafybeibeo7pmvzpkkanwd72q4qu3m4yxex3coufq7uogvcnjwgqzrlpco4", docID: "bae-fa6a97e9-e0e9-5826-8a8c-57775d35e07c" ) { name @@ -423,7 +423,7 @@ func TestCidAndDocIDQuery_ContainsPCounterWithIntKind_NoError(t *testing.T) { testUtils.Request{ Request: `query { Users ( - cid: "bafybeibinkgqwegghg7kqwk66etboc5jv42i4akasxrih35wrvykdwcima", + cid: "bafybeidtjhrssohan2f5nt7ml3nh4bovpaqhqjvijlpacfednyx77iw5y4", docID: "bae-a688789e-d8a6-57a7-be09-22e005ab79e0" ) { name @@ -470,7 +470,7 @@ func TestCidAndDocIDQuery_ContainsPCounterWithFloatKind_NoError(t *testing.T) { testUtils.Request{ Request: `query { Users ( - cid: "bafybeifsok5oy42zs2p7habfjr3ee3j7mxeag5nfdo7u4d2bfvm6hdhnpq", + cid: "bafybeieimeijjl4hdvqkt5gkn62j54nlnaetm4te7w4z2mdljlyphfsyji", docID: "bae-fa6a97e9-e0e9-5826-8a8c-57775d35e07c" ) { name diff --git a/tests/integration/query/simple/with_version_test.go b/tests/integration/query/simple/with_version_test.go index 08032dd694..615e75a293 100644 --- a/tests/integration/query/simple/with_version_test.go +++ b/tests/integration/query/simple/with_version_test.go @@ -46,14 +46,14 @@ func TestQuerySimpleWithEmbeddedLatestCommit(t *testing.T) { "Age": int64(21), "_version": []map[string]any{ { - "cid": "bafybeiaar7e2rama55djgnt5z2myspcmse4cfcwujo5z726qxpkp5af5z4", + "cid": "bafybeigxe467aute545c52e27ll3yun7rpkledh5tbjhxxs2i76dzkfdom", "links": []map[string]any{ { - "cid": "bafybeibdnm4rrtu5upewruipxb5zcvytgjfhvhnvobifkyrsddyacdboxy", + "cid": "bafybeigdvbqfwrm6dxfnfv4srbue5agzpyzoifl77ix6df7k5pjhat3fwu", "name": "Age", }, { - "cid": "bafybeiekpxtt3nuqygah2dta3ztauifvx6dbw3sjrl6hi76tkxrjfzcste", + "cid": "bafybeicurnibuf3b6krgqm3sh2ohmvxiodvawagx2evod573z67xf54zxu", "name": "Name", }, }, @@ -90,7 +90,7 @@ func TestQuerySimpleWithEmbeddedLatestCommitWithSchemaVersionId(t *testing.T) { "Name": "John", "_version": []map[string]any{ { - "schemaVersionId": "bafkreics522ai3tdep2trfeesb6csl5wqul4dexhhueha6b2xarmcctyoa", + "schemaVersionId": "bafkreigqmcqzkbg3elpe24vfza4rjle2r6cxu7ihzvg56aov57crhaebry", }, }, }, @@ -171,14 +171,14 @@ func TestQuerySimpleWithMultipleAliasedEmbeddedLatestCommit(t *testing.T) { "Age": int64(21), "_version": []map[string]any{ { - "cid": "bafybeiaar7e2rama55djgnt5z2myspcmse4cfcwujo5z726qxpkp5af5z4", + "cid": "bafybeigxe467aute545c52e27ll3yun7rpkledh5tbjhxxs2i76dzkfdom", "L1": []map[string]any{ { - "cid": "bafybeibdnm4rrtu5upewruipxb5zcvytgjfhvhnvobifkyrsddyacdboxy", + "cid": "bafybeigdvbqfwrm6dxfnfv4srbue5agzpyzoifl77ix6df7k5pjhat3fwu", "name": "Age", }, { - "cid": "bafybeiekpxtt3nuqygah2dta3ztauifvx6dbw3sjrl6hi76tkxrjfzcste", + "cid": "bafybeicurnibuf3b6krgqm3sh2ohmvxiodvawagx2evod573z67xf54zxu", "name": "Name", }, }, @@ -242,7 +242,7 @@ func TestQuery_WithAllCommitFields_NoError(t *testing.T) { "_docID": docID, "_version": []map[string]any{ { - "cid": "bafybeiaar7e2rama55djgnt5z2myspcmse4cfcwujo5z726qxpkp5af5z4", + "cid": "bafybeigxe467aute545c52e27ll3yun7rpkledh5tbjhxxs2i76dzkfdom", "collectionID": int64(1), "delta": nil, "docID": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", @@ -251,15 +251,15 @@ func TestQuery_WithAllCommitFields_NoError(t *testing.T) { "height": int64(1), "links": []map[string]any{ { - "cid": "bafybeibdnm4rrtu5upewruipxb5zcvytgjfhvhnvobifkyrsddyacdboxy", + "cid": "bafybeigdvbqfwrm6dxfnfv4srbue5agzpyzoifl77ix6df7k5pjhat3fwu", "name": "Age", }, { - "cid": "bafybeiekpxtt3nuqygah2dta3ztauifvx6dbw3sjrl6hi76tkxrjfzcste", + "cid": "bafybeicurnibuf3b6krgqm3sh2ohmvxiodvawagx2evod573z67xf54zxu", "name": "Name", }, }, - "schemaVersionId": "bafkreics522ai3tdep2trfeesb6csl5wqul4dexhhueha6b2xarmcctyoa", + "schemaVersionId": "bafkreigqmcqzkbg3elpe24vfza4rjle2r6cxu7ihzvg56aov57crhaebry", }, }, }, @@ -321,7 +321,7 @@ func TestQuery_WithAllCommitFieldsWithUpdate_NoError(t *testing.T) { "_docID": docID, "_version": []map[string]any{ { - "cid": "bafybeieywntwsejjuxxrwhlcudadsyc6xhy3pt6rcdhom3zvdewqhmncve", + "cid": "bafybeibpezk2dgdlyavsh3k7vbmgh3iwanqhkzo4byafgytjdv5c7xy73u", "collectionID": int64(1), "delta": nil, "docID": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", @@ -330,18 +330,18 @@ func TestQuery_WithAllCommitFieldsWithUpdate_NoError(t *testing.T) { "height": int64(2), "links": []map[string]any{ { - "cid": "bafybeibb6sup35cb4tjrgetjqkqshg3r56vk5up7ruz3rddqklttnk7yfi", + "cid": "bafybeihidcg4gkm6bnlyyghr5cq5dkn6x5a4l347amy7odsy5rkd7eu4qu", "name": "Age", }, { - "cid": "bafybeiaar7e2rama55djgnt5z2myspcmse4cfcwujo5z726qxpkp5af5z4", + "cid": "bafybeigxe467aute545c52e27ll3yun7rpkledh5tbjhxxs2i76dzkfdom", "name": "_head", }, }, - "schemaVersionId": "bafkreics522ai3tdep2trfeesb6csl5wqul4dexhhueha6b2xarmcctyoa", + "schemaVersionId": "bafkreigqmcqzkbg3elpe24vfza4rjle2r6cxu7ihzvg56aov57crhaebry", }, { - "cid": "bafybeiaar7e2rama55djgnt5z2myspcmse4cfcwujo5z726qxpkp5af5z4", + "cid": "bafybeigxe467aute545c52e27ll3yun7rpkledh5tbjhxxs2i76dzkfdom", "collectionID": int64(1), "delta": nil, "docID": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", @@ -350,15 +350,15 @@ func TestQuery_WithAllCommitFieldsWithUpdate_NoError(t *testing.T) { "height": int64(1), "links": []map[string]any{ { - "cid": "bafybeibdnm4rrtu5upewruipxb5zcvytgjfhvhnvobifkyrsddyacdboxy", + "cid": "bafybeigdvbqfwrm6dxfnfv4srbue5agzpyzoifl77ix6df7k5pjhat3fwu", "name": "Age", }, { - "cid": "bafybeiekpxtt3nuqygah2dta3ztauifvx6dbw3sjrl6hi76tkxrjfzcste", + "cid": "bafybeicurnibuf3b6krgqm3sh2ohmvxiodvawagx2evod573z67xf54zxu", "name": "Name", }, }, - "schemaVersionId": "bafkreics522ai3tdep2trfeesb6csl5wqul4dexhhueha6b2xarmcctyoa", + "schemaVersionId": "bafkreigqmcqzkbg3elpe24vfza4rjle2r6cxu7ihzvg56aov57crhaebry", }, }, }, diff --git a/tests/integration/schema/crdt_type_test.go b/tests/integration/schema/crdt_type_test.go index fdc278e52c..2a321ef751 100644 --- a/tests/integration/schema/crdt_type_test.go +++ b/tests/integration/schema/crdt_type_test.go @@ -20,7 +20,7 @@ import ( ) func TestSchemaCreate_ContainsPNCounterTypeWithIntKind_NoError(t *testing.T) { - schemaVersionID := "bafkreihg7aweuwitzdtturuipps2rxw774o5iu36ovxqawdncxa4yibpsq" + schemaVersionID := "bafkreigsnu67poxm3663e7vl5cncl6pxdzndcc7jf66cnnvxzw5uko5iuu" test := testUtils.TestCase{ Actions: []any{ @@ -59,7 +59,7 @@ func TestSchemaCreate_ContainsPNCounterTypeWithIntKind_NoError(t *testing.T) { } func TestSchemaCreate_ContainsPNCounterTypeWithFloatKind_NoError(t *testing.T) { - schemaVersionID := "bafkreig7olui76coe4nmm6s7f6lza7d7i35rurktxhcbmrs4po7plcrnvu" + schemaVersionID := "bafkreieflo3tkhsywsqcyzoj6nqgxc6ovv5m5lc7bfbum6yqls5rxlwkye" test := testUtils.TestCase{ Actions: []any{ @@ -132,7 +132,7 @@ func TestSchemaCreate_ContainsPNCounterWithInvalidType_Error(t *testing.T) { } func TestSchemaCreate_ContainsPCounterTypeWithIntKind_NoError(t *testing.T) { - schemaVersionID := "bafkreidjvjnvtwwdkcdqwcmwxqzu3bxrbxs3rkn6h6h7kkxmibpli3mp7y" + schemaVersionID := "bafkreigbmy67fjsys3li5rbs64k3vezvdtbfryc67pxiju4nis7lrbanea" test := testUtils.TestCase{ Actions: []any{ @@ -171,7 +171,7 @@ func TestSchemaCreate_ContainsPCounterTypeWithIntKind_NoError(t *testing.T) { } func TestSchemaCreate_ContainsPCounterTypeWithFloatKind_NoError(t *testing.T) { - schemaVersionID := "bafkreiasm64v2oimv6uk3hlfap6awptumwkm4fxuoc3ck3ehfe2tmry66i" + schemaVersionID := "bafkreifcyba45ov5zqi6dbhlu72rmf4wp3crjynjvvpq6iuauns2ofbvzi" test := testUtils.TestCase{ Actions: []any{ diff --git a/tests/integration/schema/get_schema_test.go b/tests/integration/schema/get_schema_test.go index 9f7d3bea3c..a89f4a2eb9 100644 --- a/tests/integration/schema/get_schema_test.go +++ b/tests/integration/schema/get_schema_test.go @@ -71,9 +71,9 @@ func TestGetSchema_GivenNoSchemaGivenUnknownName(t *testing.T) { } func TestGetSchema_ReturnsAllSchema(t *testing.T) { - usersSchemaVersion1ID := "bafkreiaopue5oiqzbszdk265wl6lqkqc44glt2tgjncbwek447slainu7m" - usersSchemaVersion2ID := "bafkreibuxh4vi3xsob5vx22bn3i5osbkxtimdl2nrs74cqxuf2w3ys2f3y" - booksSchemaVersion1ID := "bafkreicwmtpmea4gis6lkt46l5evd2xhais36qd5egb2b7mjrqnojbtzja" + usersSchemaVersion1ID := "bafkreia2jn5ecrhtvy4fravk6pm3wqiny46m7mqymvjkgat7xiqupgqoai" + usersSchemaVersion2ID := "bafkreibbsqjeladin2keszmja5kektzgi4eowb6m3oimxssiqge7mmvhva" + booksSchemaVersion1ID := "bafkreibiu34zrehpq346pwp5z24qkderm7ibhnpcqalhkivhnf5e2afqoy" test := testUtils.TestCase{ Actions: []any{ @@ -145,8 +145,8 @@ func TestGetSchema_ReturnsAllSchema(t *testing.T) { } func TestGetSchema_ReturnsSchemaForGivenRoot(t *testing.T) { - usersSchemaVersion1ID := "bafkreiaopue5oiqzbszdk265wl6lqkqc44glt2tgjncbwek447slainu7m" - usersSchemaVersion2ID := "bafkreibuxh4vi3xsob5vx22bn3i5osbkxtimdl2nrs74cqxuf2w3ys2f3y" + usersSchemaVersion1ID := "bafkreia2jn5ecrhtvy4fravk6pm3wqiny46m7mqymvjkgat7xiqupgqoai" + usersSchemaVersion2ID := "bafkreibbsqjeladin2keszmja5kektzgi4eowb6m3oimxssiqge7mmvhva" test := testUtils.TestCase{ Actions: []any{ @@ -208,8 +208,8 @@ func TestGetSchema_ReturnsSchemaForGivenRoot(t *testing.T) { } func TestGetSchema_ReturnsSchemaForGivenName(t *testing.T) { - usersSchemaVersion1ID := "bafkreiaopue5oiqzbszdk265wl6lqkqc44glt2tgjncbwek447slainu7m" - usersSchemaVersion2ID := "bafkreibuxh4vi3xsob5vx22bn3i5osbkxtimdl2nrs74cqxuf2w3ys2f3y" + usersSchemaVersion1ID := "bafkreia2jn5ecrhtvy4fravk6pm3wqiny46m7mqymvjkgat7xiqupgqoai" + usersSchemaVersion2ID := "bafkreibbsqjeladin2keszmja5kektzgi4eowb6m3oimxssiqge7mmvhva" test := testUtils.TestCase{ Actions: []any{ diff --git a/tests/integration/schema/migrations/query/simple_test.go b/tests/integration/schema/migrations/query/simple_test.go index 150e70a0a4..a588e70e87 100644 --- a/tests/integration/schema/migrations/query/simple_test.go +++ b/tests/integration/schema/migrations/query/simple_test.go @@ -45,8 +45,8 @@ func TestSchemaMigrationQuery(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -115,8 +115,8 @@ func TestSchemaMigrationQueryMultipleDocs(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -178,8 +178,8 @@ func TestSchemaMigrationQueryWithMigrationRegisteredBeforeSchemaPatch(t *testing }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -254,8 +254,8 @@ func TestSchemaMigrationQueryMigratesToIntermediaryVersion(t *testing.T) { // Register a migration from schema version 1 to schema version 2 **only** - // there should be no migration from version 2 to version 3. LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -325,8 +325,8 @@ func TestSchemaMigrationQueryMigratesFromIntermediaryVersion(t *testing.T) { // Register a migration from schema version 2 to schema version 3 **only** - // there should be no migration from version 1 to version 2. LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", - DestinationSchemaVersionID: "bafkreiahtlb4wv2zrnezvlwyxwtk7a2gexhrcjbnzd3hf4ejsdgatjybey", + SourceSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", + DestinationSchemaVersionID: "bafkreib65lld2tdyvlilbumlcccftqwvflpgutugghf5afrnlhdg7dgyv4", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -394,8 +394,8 @@ func TestSchemaMigrationQueryMigratesAcrossMultipleVersions(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -411,8 +411,8 @@ func TestSchemaMigrationQueryMigratesAcrossMultipleVersions(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", - DestinationSchemaVersionID: "bafkreiahtlb4wv2zrnezvlwyxwtk7a2gexhrcjbnzd3hf4ejsdgatjybey", + SourceSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", + DestinationSchemaVersionID: "bafkreib65lld2tdyvlilbumlcccftqwvflpgutugghf5afrnlhdg7dgyv4", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -466,8 +466,8 @@ func TestSchemaMigrationQueryMigratesAcrossMultipleVersionsBeforePatches(t *test }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -483,8 +483,8 @@ func TestSchemaMigrationQueryMigratesAcrossMultipleVersionsBeforePatches(t *test }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", - DestinationSchemaVersionID: "bafkreiahtlb4wv2zrnezvlwyxwtk7a2gexhrcjbnzd3hf4ejsdgatjybey", + SourceSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", + DestinationSchemaVersionID: "bafkreib65lld2tdyvlilbumlcccftqwvflpgutugghf5afrnlhdg7dgyv4", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -553,8 +553,8 @@ func TestSchemaMigrationQueryMigratesAcrossMultipleVersionsBeforePatchesWrongOrd testUtils.ConfigureMigration{ // Declare the migration from v2=>v3 before declaring the migration from v1=>v2 LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", - DestinationSchemaVersionID: "bafkreiahtlb4wv2zrnezvlwyxwtk7a2gexhrcjbnzd3hf4ejsdgatjybey", + SourceSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", + DestinationSchemaVersionID: "bafkreib65lld2tdyvlilbumlcccftqwvflpgutugghf5afrnlhdg7dgyv4", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -570,8 +570,8 @@ func TestSchemaMigrationQueryMigratesAcrossMultipleVersionsBeforePatchesWrongOrd }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -712,8 +712,8 @@ func TestSchemaMigrationQueryMigrationMutatesExistingScalarField(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -773,8 +773,8 @@ func TestSchemaMigrationQueryMigrationMutatesExistingInlineArrayField(t *testing }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreicm3axeowuuorrvlpvzatvnsaa6224qt7erlzjjhevwkndn532pxe", - DestinationSchemaVersionID: "bafkreih4urgndwhrvjoruj55yv5n3luvvky4daq67ivahiici7yn35mkfu", + SourceSchemaVersionID: "bafkreicn6ltdovb6y7g3ecoptqkvx2y5y5yntrb5uydmg3jiakskqva2ta", + DestinationSchemaVersionID: "bafkreifv4vhz3dw7upc5u3omsqi6klz3h3e54ogfskp72gtut62fuxqrcu", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -836,8 +836,8 @@ func TestSchemaMigrationQueryMigrationRemovesExistingField(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreibthhctfd3rykinfa6ivvkhegp7sbhk5yvujdkhase7ilj5dz5gqi", - DestinationSchemaVersionID: "bafkreig5ovmx3vbhskpazxzjvlezy4brrndxu7bhdn5z2iqnozvw5iliwu", + SourceSchemaVersionID: "bafkreihhd6bqrjhl5zidwztgxzeseveplv3cj3fwtn3unjkdx7j2vr2vrq", + DestinationSchemaVersionID: "bafkreiegvk3fkcjxoqqpp7npxqjdjwijiwthvynzmsvtzajpjevgu2krku", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -897,8 +897,8 @@ func TestSchemaMigrationQueryMigrationPreservesExistingFieldWhenFieldNotRequeste }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreibthhctfd3rykinfa6ivvkhegp7sbhk5yvujdkhase7ilj5dz5gqi", - DestinationSchemaVersionID: "bafkreig5ovmx3vbhskpazxzjvlezy4brrndxu7bhdn5z2iqnozvw5iliwu", + SourceSchemaVersionID: "bafkreihhd6bqrjhl5zidwztgxzeseveplv3cj3fwtn3unjkdx7j2vr2vrq", + DestinationSchemaVersionID: "bafkreiegvk3fkcjxoqqpp7npxqjdjwijiwthvynzmsvtzajpjevgu2krku", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -971,8 +971,8 @@ func TestSchemaMigrationQueryMigrationCopiesExistingFieldWhenSrcFieldNotRequeste }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreibthhctfd3rykinfa6ivvkhegp7sbhk5yvujdkhase7ilj5dz5gqi", - DestinationSchemaVersionID: "bafkreihmw2xtrfccga6dy2nsh2sqwnzmbsygm5xkoltf4v3u4vdrinliki", + SourceSchemaVersionID: "bafkreihhd6bqrjhl5zidwztgxzeseveplv3cj3fwtn3unjkdx7j2vr2vrq", + DestinationSchemaVersionID: "bafkreidgnuvanzqur3pkp4mmrd77ojwvov2rlczraaks4435e6wsgxpwoq", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -1033,8 +1033,8 @@ func TestSchemaMigrationQueryMigrationCopiesExistingFieldWhenSrcAndDstFieldNotRe }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreibthhctfd3rykinfa6ivvkhegp7sbhk5yvujdkhase7ilj5dz5gqi", - DestinationSchemaVersionID: "bafkreihmw2xtrfccga6dy2nsh2sqwnzmbsygm5xkoltf4v3u4vdrinliki", + SourceSchemaVersionID: "bafkreihhd6bqrjhl5zidwztgxzeseveplv3cj3fwtn3unjkdx7j2vr2vrq", + DestinationSchemaVersionID: "bafkreidgnuvanzqur3pkp4mmrd77ojwvov2rlczraaks4435e6wsgxpwoq", Lens: model.Lens{ Lenses: []model.LensModule{ { diff --git a/tests/integration/schema/migrations/query/with_doc_id_test.go b/tests/integration/schema/migrations/query/with_doc_id_test.go index 70bf0040e3..ee175515dc 100644 --- a/tests/integration/schema/migrations/query/with_doc_id_test.go +++ b/tests/integration/schema/migrations/query/with_doc_id_test.go @@ -52,8 +52,8 @@ func TestSchemaMigrationQueryByDocID(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -158,8 +158,8 @@ func TestSchemaMigrationQueryMultipleQueriesByDocID(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { diff --git a/tests/integration/schema/migrations/query/with_inverse_test.go b/tests/integration/schema/migrations/query/with_inverse_test.go index 2375fbb373..f436c332c0 100644 --- a/tests/integration/schema/migrations/query/with_inverse_test.go +++ b/tests/integration/schema/migrations/query/with_inverse_test.go @@ -49,8 +49,8 @@ func TestSchemaMigrationQueryInversesAcrossMultipleVersions(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreieabpdpv5ua4f6lc5lprud4vvbefmfinzqaewhx5gzuf7anwgrqmy", - DestinationSchemaVersionID: "bafkreid2g456hvlkedusgfp6argh76a74ymrlii2ag4yqqsn2sgt4pkslu", + SourceSchemaVersionID: "bafkreicdkt3m6mgwuoix7qyijvwxwtj3dlre4a4c6mdnqbucbndwuxjsvi", + DestinationSchemaVersionID: "bafkreibpaw4dxy6bvmuoyegm7bwxyi24nubozmukemwiour4v62kz5ffuu", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -66,8 +66,8 @@ func TestSchemaMigrationQueryInversesAcrossMultipleVersions(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreid2g456hvlkedusgfp6argh76a74ymrlii2ag4yqqsn2sgt4pkslu", - DestinationSchemaVersionID: "bafkreibwswh2pxloduldc2l5h5jzm7b6fqt3s4vijq3nssmn3rr5gws2ki", + SourceSchemaVersionID: "bafkreibpaw4dxy6bvmuoyegm7bwxyi24nubozmukemwiour4v62kz5ffuu", + DestinationSchemaVersionID: "bafkreickm4zodm2muw5qcctmssht63g57u7kxujqyoax4zb5c42zs4pdh4", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -89,7 +89,7 @@ func TestSchemaMigrationQueryInversesAcrossMultipleVersions(t *testing.T) { }`, }, testUtils.SetActiveSchemaVersion{ - SchemaVersionID: "bafkreieabpdpv5ua4f6lc5lprud4vvbefmfinzqaewhx5gzuf7anwgrqmy", + SchemaVersionID: "bafkreicdkt3m6mgwuoix7qyijvwxwtj3dlre4a4c6mdnqbucbndwuxjsvi", }, testUtils.Request{ Request: `query { diff --git a/tests/integration/schema/migrations/query/with_p2p_schema_branch_test.go b/tests/integration/schema/migrations/query/with_p2p_schema_branch_test.go index 9aba1698e1..ca8de37f95 100644 --- a/tests/integration/schema/migrations/query/with_p2p_schema_branch_test.go +++ b/tests/integration/schema/migrations/query/with_p2p_schema_branch_test.go @@ -46,8 +46,8 @@ func TestSchemaMigrationQueryWithP2PReplicatedDocOnOtherSchemaBranch(t *testing. testUtils.ConfigureMigration{ // Register the migration on both nodes. LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreihax57fohcdupqr2l4heoqxdsiggjfeaubr44tgrz4xqdgvnid4xy", - DestinationSchemaVersionID: "bafkreifer354qmdrwdtae5n3k7sbl2oauis3mz24fk46p3otub7ojznobq", + SourceSchemaVersionID: "bafkreibpai5hfnalhtn5mgamzkgml4gwftow7pklmjcn6i4sqey6a5u5ce", + DestinationSchemaVersionID: "bafkreidrbhf54zckhmchzw2ngbobfqtkt7sm6ihbliu2wtxesehz5g4xwm", Lens: model.Lens{ Lenses: []model.LensModule{ { diff --git a/tests/integration/schema/migrations/query/with_p2p_test.go b/tests/integration/schema/migrations/query/with_p2p_test.go index 4e9bee6828..f8b0197d5d 100644 --- a/tests/integration/schema/migrations/query/with_p2p_test.go +++ b/tests/integration/schema/migrations/query/with_p2p_test.go @@ -46,8 +46,8 @@ func TestSchemaMigrationQueryWithP2PReplicatedDocAtOlderSchemaVersion(t *testing testUtils.ConfigureMigration{ // Register the migration on both nodes. LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreihax57fohcdupqr2l4heoqxdsiggjfeaubr44tgrz4xqdgvnid4xy", - DestinationSchemaVersionID: "bafkreifer354qmdrwdtae5n3k7sbl2oauis3mz24fk46p3otub7ojznobq", + SourceSchemaVersionID: "bafkreibpai5hfnalhtn5mgamzkgml4gwftow7pklmjcn6i4sqey6a5u5ce", + DestinationSchemaVersionID: "bafkreidrbhf54zckhmchzw2ngbobfqtkt7sm6ihbliu2wtxesehz5g4xwm", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -145,8 +145,8 @@ func TestSchemaMigrationQueryWithP2PReplicatedDocAtMuchOlderSchemaVersion(t *tes testUtils.ConfigureMigration{ // Register the migration on both nodes. LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreihax57fohcdupqr2l4heoqxdsiggjfeaubr44tgrz4xqdgvnid4xy", - DestinationSchemaVersionID: "bafkreifer354qmdrwdtae5n3k7sbl2oauis3mz24fk46p3otub7ojznobq", + SourceSchemaVersionID: "bafkreibpai5hfnalhtn5mgamzkgml4gwftow7pklmjcn6i4sqey6a5u5ce", + DestinationSchemaVersionID: "bafkreidrbhf54zckhmchzw2ngbobfqtkt7sm6ihbliu2wtxesehz5g4xwm", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -163,8 +163,8 @@ func TestSchemaMigrationQueryWithP2PReplicatedDocAtMuchOlderSchemaVersion(t *tes testUtils.ConfigureMigration{ // Register the migration on both nodes. LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreifer354qmdrwdtae5n3k7sbl2oauis3mz24fk46p3otub7ojznobq", - DestinationSchemaVersionID: "bafkreihxxnewvatrejbay6uwon5pcxxh2427txtq3ozwc5qybc2hwyn4s4", + SourceSchemaVersionID: "bafkreidrbhf54zckhmchzw2ngbobfqtkt7sm6ihbliu2wtxesehz5g4xwm", + DestinationSchemaVersionID: "bafkreidiohu3klvu4f2fdqcywtpqild4v7spsn7ivsjtg6sea6ome2oc4i", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -253,8 +253,8 @@ func TestSchemaMigrationQueryWithP2PReplicatedDocAtNewerSchemaVersion(t *testing testUtils.ConfigureMigration{ // Register the migration on both nodes. LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreihax57fohcdupqr2l4heoqxdsiggjfeaubr44tgrz4xqdgvnid4xy", - DestinationSchemaVersionID: "bafkreifer354qmdrwdtae5n3k7sbl2oauis3mz24fk46p3otub7ojznobq", + SourceSchemaVersionID: "bafkreibpai5hfnalhtn5mgamzkgml4gwftow7pklmjcn6i4sqey6a5u5ce", + DestinationSchemaVersionID: "bafkreidrbhf54zckhmchzw2ngbobfqtkt7sm6ihbliu2wtxesehz5g4xwm", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -355,8 +355,8 @@ func TestSchemaMigrationQueryWithP2PReplicatedDocAtMuchNewerSchemaVersionWithSch // Register a migration from version 2 to version 3 on both nodes. // There is no migration from version 1 to 2, thus node 1 has no knowledge of schema version 2. LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", - DestinationSchemaVersionID: "bafkreiahtlb4wv2zrnezvlwyxwtk7a2gexhrcjbnzd3hf4ejsdgatjybey", + SourceSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", + DestinationSchemaVersionID: "bafkreib65lld2tdyvlilbumlcccftqwvflpgutugghf5afrnlhdg7dgyv4", Lens: model.Lens{ Lenses: []model.LensModule{ { diff --git a/tests/integration/schema/migrations/query/with_restart_test.go b/tests/integration/schema/migrations/query/with_restart_test.go index 7d7525b910..f44264312c 100644 --- a/tests/integration/schema/migrations/query/with_restart_test.go +++ b/tests/integration/schema/migrations/query/with_restart_test.go @@ -45,8 +45,8 @@ func TestSchemaMigrationQueryWithRestart(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -99,8 +99,8 @@ func TestSchemaMigrationQueryWithRestartAndMigrationBeforeSchemaPatch(t *testing }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { diff --git a/tests/integration/schema/migrations/query/with_schema_branch_test.go b/tests/integration/schema/migrations/query/with_schema_branch_test.go index fe882944ee..0ed9e68aca 100644 --- a/tests/integration/schema/migrations/query/with_schema_branch_test.go +++ b/tests/integration/schema/migrations/query/with_schema_branch_test.go @@ -21,7 +21,7 @@ import ( ) func TestSchemaMigrationQuery_WithBranchingSchema(t *testing.T) { - schemaVersion1ID := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" + schemaVersion1ID := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" test := testUtils.TestCase{ Description: "Test schema update, with branching schema migrations", diff --git a/tests/integration/schema/migrations/query/with_set_default_test.go b/tests/integration/schema/migrations/query/with_set_default_test.go index 8501d68a8e..17c147338c 100644 --- a/tests/integration/schema/migrations/query/with_set_default_test.go +++ b/tests/integration/schema/migrations/query/with_set_default_test.go @@ -22,7 +22,7 @@ import ( ) func TestSchemaMigrationQuery_WithSetDefaultToLatest_AppliesForwardMigration(t *testing.T) { - schemaVersionID2 := "bafkreifer354qmdrwdtae5n3k7sbl2oauis3mz24fk46p3otub7ojznobq" + schemaVersionID2 := "bafkreidrbhf54zckhmchzw2ngbobfqtkt7sm6ihbliu2wtxesehz5g4xwm" test := testUtils.TestCase{ Description: "Test schema migration", @@ -83,8 +83,8 @@ func TestSchemaMigrationQuery_WithSetDefaultToLatest_AppliesForwardMigration(t * } func TestSchemaMigrationQuery_WithSetDefaultToOriginal_AppliesInverseMigration(t *testing.T) { - schemaVersionID1 := "bafkreihax57fohcdupqr2l4heoqxdsiggjfeaubr44tgrz4xqdgvnid4xy" - schemaVersionID2 := "bafkreifer354qmdrwdtae5n3k7sbl2oauis3mz24fk46p3otub7ojznobq" + schemaVersionID1 := "bafkreibpai5hfnalhtn5mgamzkgml4gwftow7pklmjcn6i4sqey6a5u5ce" + schemaVersionID2 := "bafkreidrbhf54zckhmchzw2ngbobfqtkt7sm6ihbliu2wtxesehz5g4xwm" test := testUtils.TestCase{ Description: "Test schema migration", @@ -158,8 +158,8 @@ func TestSchemaMigrationQuery_WithSetDefaultToOriginal_AppliesInverseMigration(t } func TestSchemaMigrationQuery_WithSetDefaultToOriginalVersionThatDocWasCreatedAt_ClearsMigrations(t *testing.T) { - schemaVersionID1 := "bafkreihax57fohcdupqr2l4heoqxdsiggjfeaubr44tgrz4xqdgvnid4xy" - schemaVersionID2 := "bafkreifer354qmdrwdtae5n3k7sbl2oauis3mz24fk46p3otub7ojznobq" + schemaVersionID1 := "bafkreibpai5hfnalhtn5mgamzkgml4gwftow7pklmjcn6i4sqey6a5u5ce" + schemaVersionID2 := "bafkreidrbhf54zckhmchzw2ngbobfqtkt7sm6ihbliu2wtxesehz5g4xwm" test := testUtils.TestCase{ Description: "Test schema migration", diff --git a/tests/integration/schema/migrations/query/with_txn_test.go b/tests/integration/schema/migrations/query/with_txn_test.go index f22d4bcbc4..880f9e01ed 100644 --- a/tests/integration/schema/migrations/query/with_txn_test.go +++ b/tests/integration/schema/migrations/query/with_txn_test.go @@ -47,8 +47,8 @@ func TestSchemaMigrationQueryWithTxn(t *testing.T) { testUtils.ConfigureMigration{ TransactionID: immutable.Some(0), LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -109,8 +109,8 @@ func TestSchemaMigrationQueryWithTxnAndCommit(t *testing.T) { testUtils.ConfigureMigration{ TransactionID: immutable.Some(0), LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { diff --git a/tests/integration/schema/migrations/query/with_update_test.go b/tests/integration/schema/migrations/query/with_update_test.go index b3ddd94e77..93a2586e25 100644 --- a/tests/integration/schema/migrations/query/with_update_test.go +++ b/tests/integration/schema/migrations/query/with_update_test.go @@ -45,8 +45,8 @@ func TestSchemaMigrationQueryWithUpdateRequest(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -129,8 +129,8 @@ func TestSchemaMigrationQueryWithMigrationRegisteredAfterUpdate(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { diff --git a/tests/integration/schema/migrations/simple_test.go b/tests/integration/schema/migrations/simple_test.go index 6b7767943a..a7826f5366 100644 --- a/tests/integration/schema/migrations/simple_test.go +++ b/tests/integration/schema/migrations/simple_test.go @@ -106,8 +106,8 @@ func TestSchemaMigrationGetMigrationsReturnsMultiple(t *testing.T) { }, testUtils.ConfigureMigration{ LensConfig: client.LensConfig{ - SourceSchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", - DestinationSchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SourceSchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", + DestinationSchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Lens: model.Lens{ Lenses: []model.LensModule{ { @@ -154,11 +154,11 @@ func TestSchemaMigrationGetMigrationsReturnsMultiple(t *testing.T) { }, { ID: 3, - SchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", + SchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", }, { ID: 4, - SchemaVersionID: "bafkreifpgr7zjwxmrjpo3rtybd2kqye6mmf5copqwzv27a5fgpvbq4aqm4", + SchemaVersionID: "bafkreib5jaawobqqiu6frzacerlj55pxxxuql3igqj4ldmg2pgilke4bty", Sources: []any{ &client.CollectionSource{ SourceCollectionID: 3, diff --git a/tests/integration/schema/simple_test.go b/tests/integration/schema/simple_test.go index c0f615e6eb..9e169e6178 100644 --- a/tests/integration/schema/simple_test.go +++ b/tests/integration/schema/simple_test.go @@ -20,7 +20,7 @@ import ( ) func TestSchemaSimpleCreatesSchemaGivenEmptyType(t *testing.T) { - schemaVersionID := "bafkreiaopue5oiqzbszdk265wl6lqkqc44glt2tgjncbwek447slainu7m" + schemaVersionID := "bafkreia2jn5ecrhtvy4fravk6pm3wqiny46m7mqymvjkgat7xiqupgqoai" test := testUtils.TestCase{ Actions: []any{ diff --git a/tests/integration/schema/updates/add/field/create_update_test.go b/tests/integration/schema/updates/add/field/create_update_test.go index 6ce10243c0..d299b70e7f 100644 --- a/tests/integration/schema/updates/add/field/create_update_test.go +++ b/tests/integration/schema/updates/add/field/create_update_test.go @@ -17,8 +17,8 @@ import ( ) func TestSchemaUpdatesAddFieldWithCreateWithUpdateAfterSchemaUpdateAndVersionJoin(t *testing.T) { - initialSchemaVersionId := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" - updatedSchemaVersionId := "bafkreigdplzukezgpmjs45lw6kwzhtwge4xjzfgm6iodcd32d7kdageply" + initialSchemaVersionId := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" + updatedSchemaVersionId := "bafkreibz4g6rkxanzn6ro74ezmbwoe5hvcguwvi34judrk2kfuqqtk5ak4" test := testUtils.TestCase{ Description: "Test schema update, add field with update after schema update, version join", @@ -105,8 +105,8 @@ func TestSchemaUpdatesAddFieldWithCreateWithUpdateAfterSchemaUpdateAndVersionJoi } func TestSchemaUpdatesAddFieldWithCreateWithUpdateAfterSchemaUpdateAndCommitQuery(t *testing.T) { - initialSchemaVersionId := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" - updatedSchemaVersionId := "bafkreigdplzukezgpmjs45lw6kwzhtwge4xjzfgm6iodcd32d7kdageply" + initialSchemaVersionId := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" + updatedSchemaVersionId := "bafkreibz4g6rkxanzn6ro74ezmbwoe5hvcguwvi34judrk2kfuqqtk5ak4" test := testUtils.TestCase{ Description: "Test schema update, add field with update after schema update, commits query", diff --git a/tests/integration/schema/updates/add/field/simple_test.go b/tests/integration/schema/updates/add/field/simple_test.go index 45a9b6afd5..80aaec32d6 100644 --- a/tests/integration/schema/updates/add/field/simple_test.go +++ b/tests/integration/schema/updates/add/field/simple_test.go @@ -20,8 +20,8 @@ import ( ) func TestSchemaUpdatesAddFieldSimple(t *testing.T) { - schemaVersion1ID := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" - schemaVersion2ID := "bafkreigdplzukezgpmjs45lw6kwzhtwge4xjzfgm6iodcd32d7kdageply" + schemaVersion1ID := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" + schemaVersion2ID := "bafkreibz4g6rkxanzn6ro74ezmbwoe5hvcguwvi34judrk2kfuqqtk5ak4" test := testUtils.TestCase{ Description: "Test schema update, add field", @@ -115,8 +115,8 @@ func TestSchemaUpdates_AddFieldSimpleDoNotSetDefault_Errors(t *testing.T) { } func TestSchemaUpdates_AddFieldSimpleDoNotSetDefault_VersionIsQueryable(t *testing.T) { - schemaVersion1ID := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" - schemaVersion2ID := "bafkreigdplzukezgpmjs45lw6kwzhtwge4xjzfgm6iodcd32d7kdageply" + schemaVersion1ID := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" + schemaVersion2ID := "bafkreibz4g6rkxanzn6ro74ezmbwoe5hvcguwvi34judrk2kfuqqtk5ak4" test := testUtils.TestCase{ Description: "Test schema update, add field", diff --git a/tests/integration/schema/updates/move/simple_test.go b/tests/integration/schema/updates/move/simple_test.go index 2e33c709d6..9898430e0f 100644 --- a/tests/integration/schema/updates/move/simple_test.go +++ b/tests/integration/schema/updates/move/simple_test.go @@ -17,7 +17,7 @@ import ( ) func TestSchemaUpdatesMoveCollectionDoesNothing(t *testing.T) { - schemaVersionID := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" + schemaVersionID := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" test := testUtils.TestCase{ Description: "Test schema update, move collection", diff --git a/tests/integration/schema/updates/with_schema_branch_test.go b/tests/integration/schema/updates/with_schema_branch_test.go index a47a5f4bb4..d8f7d1afc2 100644 --- a/tests/integration/schema/updates/with_schema_branch_test.go +++ b/tests/integration/schema/updates/with_schema_branch_test.go @@ -20,9 +20,9 @@ import ( ) func TestSchemaUpdates_WithBranchingSchema(t *testing.T) { - schemaVersion1ID := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" - schemaVersion2ID := "bafkreigdplzukezgpmjs45lw6kwzhtwge4xjzfgm6iodcd32d7kdageply" - schemaVersion3ID := "bafkreiawvcmcwounww6dbzb2vlvvstqf7venmktd4tsgxkw4o4undmtipe" + schemaVersion1ID := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" + schemaVersion2ID := "bafkreibz4g6rkxanzn6ro74ezmbwoe5hvcguwvi34judrk2kfuqqtk5ak4" + schemaVersion3ID := "bafkreifswbi23wxvq2zpqnoldolsxk2fhtj5t6rs3pidil3j6tybc62q3m" test := testUtils.TestCase{ Description: "Test schema update, with branching schema", @@ -169,10 +169,10 @@ func TestSchemaUpdates_WithBranchingSchema(t *testing.T) { } func TestSchemaUpdates_WithPatchOnBranchedSchema(t *testing.T) { - schemaVersion1ID := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" - schemaVersion2ID := "bafkreigdplzukezgpmjs45lw6kwzhtwge4xjzfgm6iodcd32d7kdageply" - schemaVersion3ID := "bafkreiawvcmcwounww6dbzb2vlvvstqf7venmktd4tsgxkw4o4undmtipe" - schemaVersion4ID := "bafkreidqp7ha7mfhwqpahevcpsn5etmi3soawyq76oytdxlyozvs6cgyui" + schemaVersion1ID := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" + schemaVersion2ID := "bafkreibz4g6rkxanzn6ro74ezmbwoe5hvcguwvi34judrk2kfuqqtk5ak4" + schemaVersion3ID := "bafkreifswbi23wxvq2zpqnoldolsxk2fhtj5t6rs3pidil3j6tybc62q3m" + schemaVersion4ID := "bafkreid4ulxeclzgpzhznge7zdin6docxvklugvr6gt4jxfyanz5i2r2hu" test := testUtils.TestCase{ Description: "Test schema update, with patch on branching schema", @@ -307,9 +307,9 @@ func TestSchemaUpdates_WithPatchOnBranchedSchema(t *testing.T) { } func TestSchemaUpdates_WithBranchingSchemaAndSetActiveSchemaToOtherBranch(t *testing.T) { - schemaVersion1ID := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" - schemaVersion2ID := "bafkreigdplzukezgpmjs45lw6kwzhtwge4xjzfgm6iodcd32d7kdageply" - schemaVersion3ID := "bafkreiawvcmcwounww6dbzb2vlvvstqf7venmktd4tsgxkw4o4undmtipe" + schemaVersion1ID := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" + schemaVersion2ID := "bafkreibz4g6rkxanzn6ro74ezmbwoe5hvcguwvi34judrk2kfuqqtk5ak4" + schemaVersion3ID := "bafkreifswbi23wxvq2zpqnoldolsxk2fhtj5t6rs3pidil3j6tybc62q3m" test := testUtils.TestCase{ Description: "Test schema update, with branching schema toggling between branches", @@ -403,10 +403,10 @@ func TestSchemaUpdates_WithBranchingSchemaAndSetActiveSchemaToOtherBranch(t *tes } func TestSchemaUpdates_WithBranchingSchemaAndSetActiveSchemaToOtherBranchThenPatch(t *testing.T) { - schemaVersion1ID := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" - schemaVersion2ID := "bafkreigdplzukezgpmjs45lw6kwzhtwge4xjzfgm6iodcd32d7kdageply" - schemaVersion3ID := "bafkreiawvcmcwounww6dbzb2vlvvstqf7venmktd4tsgxkw4o4undmtipe" - schemaVersion4ID := "bafkreih5trmbzpjdgterha2amx2n6opgwlpvdyxfeyfi2uq7ncbodpl2cu" + schemaVersion1ID := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" + schemaVersion2ID := "bafkreibz4g6rkxanzn6ro74ezmbwoe5hvcguwvi34judrk2kfuqqtk5ak4" + schemaVersion3ID := "bafkreifswbi23wxvq2zpqnoldolsxk2fhtj5t6rs3pidil3j6tybc62q3m" + schemaVersion4ID := "bafkreidjuyxhakc5yx7fucunoxijnfjvgqohf4sjoryzf27mqxidh37kne" test := testUtils.TestCase{ Description: "Test schema update, with branching schema toggling between branches then patch", @@ -545,7 +545,7 @@ func TestSchemaUpdates_WithBranchingSchemaAndSetActiveSchemaToOtherBranchThenPat } func TestSchemaUpdates_WithBranchingSchemaAndGetCollectionAtVersion(t *testing.T) { - schemaVersion1ID := "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a" + schemaVersion1ID := "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe" test := testUtils.TestCase{ Description: `Test schema update, with branching schema toggling between branches and gets the diff --git a/tests/integration/schema/with_update_set_default_test.go b/tests/integration/schema/with_update_set_default_test.go index 9203a61655..f46e0540e3 100644 --- a/tests/integration/schema/with_update_set_default_test.go +++ b/tests/integration/schema/with_update_set_default_test.go @@ -92,7 +92,7 @@ func TestSchema_WithUpdateAndSetDefaultVersionToOriginal_NewFieldIsNotQueriable( SetAsDefaultVersion: immutable.Some(false), }, testUtils.SetActiveSchemaVersion{ - SchemaVersionID: "bafkreiht46o4lakri2py2zw57ed3pdeib6ud6ojlsomgjlrgwh53wl3q4a", + SchemaVersionID: "bafkreia3o3cetvcnnxyu5spucimoos77ifungfmacxdkva4zah2is3aooe", }, testUtils.Request{ Request: `query { @@ -129,7 +129,7 @@ func TestSchema_WithUpdateAndSetDefaultVersionToNew_AllowsQueryingOfNewField(t * SetAsDefaultVersion: immutable.Some(false), }, testUtils.SetActiveSchemaVersion{ - SchemaVersionID: "bafkreigdplzukezgpmjs45lw6kwzhtwge4xjzfgm6iodcd32d7kdageply", + SchemaVersionID: "bafkreibz4g6rkxanzn6ro74ezmbwoe5hvcguwvi34judrk2kfuqqtk5ak4", }, testUtils.Request{ Request: `query { From 042c19a01796df96bd2476490c3edc5f3ea80c81 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Mon, 15 Apr 2024 19:57:20 -0400 Subject: [PATCH 08/11] Document breaking change --- docs/data_format_changes/i2451-rel-field-props-local.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/data_format_changes/i2451-rel-field-props-local.md diff --git a/docs/data_format_changes/i2451-rel-field-props-local.md b/docs/data_format_changes/i2451-rel-field-props-local.md new file mode 100644 index 0000000000..ad34cc8965 --- /dev/null +++ b/docs/data_format_changes/i2451-rel-field-props-local.md @@ -0,0 +1,3 @@ +# Move relation field properties onto collection + +Field RelationName and secondary relation fields has been made local, and moved off of the schema and onto collection. Field IsPrimary has been removed completely (from the schema). As a result schema root and schema version id are no longer dependent on them. From d3a3371164440efa2a2545fd6e09f1aca48210d9 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Tue, 16 Apr 2024 11:13:32 -0400 Subject: [PATCH 09/11] PR FIXUP - Use field definitions generating gql inputs Secondary fields do not exist in the schema, and thus schema.fields is incorrect here. --- request/graphql/schema/generate.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/request/graphql/schema/generate.go b/request/graphql/schema/generate.go index 4b0b2bdec2..6b7483be4f 100644 --- a/request/graphql/schema/generate.go +++ b/request/graphql/schema/generate.go @@ -540,7 +540,6 @@ func (g *Generator) buildMutationInputTypes(collections []client.CollectionDefin // will be reassigned before the thunk is run // TODO remove when Go 1.22 collection := c - fieldDescriptions := collection.Schema.Fields mutationInputName := collection.Description.Name.Value() + "MutationInputArg" // check if mutation input type exists @@ -558,7 +557,7 @@ func (g *Generator) buildMutationInputTypes(collections []client.CollectionDefin mutationObjConf.Fields = (gql.InputObjectConfigFieldMapThunk)(func() (gql.InputObjectConfigFieldMap, error) { fields := make(gql.InputObjectConfigFieldMap) - for _, field := range fieldDescriptions { + for _, field := range collection.GetFields() { if strings.HasPrefix(field.Name, "_") { // ignore system defined args as the // user cannot override their values From 9c4fe729b5b66717df4b1e3804fec65d77806527 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Fri, 19 Apr 2024 12:38:12 -0400 Subject: [PATCH 10/11] PR FIXUP - Expand documentation on local vs global fields --- client/collection_description.go | 6 +++++- client/schema_description.go | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client/collection_description.go b/client/collection_description.go index 200ec82a7e..aa22bf7121 100644 --- a/client/collection_description.go +++ b/client/collection_description.go @@ -60,7 +60,11 @@ type CollectionDescription struct { // - [CollectionSource] Sources []any - // Fields contains the fields within this Collection. + // Fields contains the fields local to the node within this Collection. + // + // Most fields defined here will also be present on the [SchemaDescription]. A notable + // exception to this are the fields of the (optional) secondary side of a relation + // which are local only, and will not be present on the [SchemaDescription]. Fields []CollectionFieldDescription // Indexes contains the secondary indexes that this Collection has. diff --git a/client/schema_description.go b/client/schema_description.go index 302fadf5e7..2d34b131b8 100644 --- a/client/schema_description.go +++ b/client/schema_description.go @@ -31,7 +31,14 @@ type SchemaDescription struct { // It is immutable. Name string - // Fields contains the fields within this Schema. + // Fields contains the fields globally defined across the node network within this Schema. + // + // Any [CollectionDescription]s that reference this [SchemaDescription] will have a field + // set that contains all of these fields, plus any local only fields (such as the secondary side + // of a relation). + // + // Embedded objects (including within Views) are schema-only, and as such fields of embedded + // objects will not have a corresponding [CollectionFieldDescription]. // // Currently new fields may be added after initial declaration, but they cannot be removed. Fields []SchemaFieldDescription From 137e943ee6cc9ad59ab7e0e55ca09fbd329a8ea4 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Fri, 19 Apr 2024 15:20:14 -0400 Subject: [PATCH 11/11] PR FIXUP - Fix typo in code comment --- request/graphql/schema/collection.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request/graphql/schema/collection.go b/request/graphql/schema/collection.go index a15c32a061..937a6e2973 100644 --- a/request/graphql/schema/collection.go +++ b/request/graphql/schema/collection.go @@ -712,7 +712,7 @@ func finalizeRelations( // An _id field is added for every 1-1 or 1-N relationship from this object if the relation // does not point to an embedded object. // - // It is inserted immediately after the object field for make things nicer for the user. + // It is inserted immediately after the object field to make things nicer for the user. definition.Schema.Fields[schemaFieldIndex+1] = client.SchemaFieldDescription{ Name: idFieldName, Kind: client.FieldKind_DocID,