This PR aims at handling dgraph schema spec uniformity by generating dgraph-compliant schema and indices.
This work is requried since:
Dgraph schema types are constantly updated with new version bumps. Manual maintenance could create potential issues with backups and backward portability
Generating schema from python classes would require only addition of new predicates in class definitions thus preventing maintenance of multiple definitions
Easier while scaling up
Simpler to version the schema file
Can be quickly updated/downgraded as per new Dgraph schema rules
Updated Changes:
Schema Generator forms type definitions for all nodes with right predicate associations
Add indexing info to the schema to complete the Schema spec
Pending Changes:
~Add indexing info to the schema to complete the Schema spec~
Design thoughts
Index rules need to be defined alongwith class definitions so that there is no ambiguity or misrepresentation of predicates
There can be some predicates/relations that are reused across various nodes. For e.g Keyphrase node has a predicate called type which indicates the type of keyphrase. Similarly, Mind node also has type with different input but of same type (string).
Hence, it is important that while defining index rules we do not end up defining different index types for the same predicates.
Separate TypeDef generation and Index generation since not always both need to be updated. Also, TypeDefs are more prone to changes from Dgraph team than schema. Keeping them separate is easier to maintain code.
Implementation detail
Based on these design thoughts, a new dataclass called IndexRules is added. This class will be a single place where all the indices will be defined or modified, keeping node definitions separate and agnostic from this.
Dataclasses are defined by Field object which contains information about the class attributes. It provides an additional attribute called metadata which can be used for third-party apps to add/define more configurations.
Using metadata field, dgconfig method is introduced where all metadata related to dgraph specific additions can be mentioned. The schema generators will read this metadata to make decisions over schema file.
This PR aims at handling dgraph schema spec uniformity by generating dgraph-compliant schema and indices. This work is requried since:
Updated Changes:
Pending Changes:
Design thoughts
Keyphrase
node has a predicate calledtype
which indicates the type of keyphrase. Similarly,Mind
node also hastype
with different input but of same type (string
). Hence, it is important that while defining index rules we do not end up defining different index types for the same predicates.Implementation detail
IndexRules
is added. This class will be a single place where all the indices will be defined or modified, keeping node definitions separate and agnostic from this.Field
object which contains information about the class attributes. It provides an additional attribute calledmetadata
which can be used for third-party apps to add/define more configurations.metadata
field,dgconfig
method is introduced where all metadata related to dgraph specific additions can be mentioned. The schema generators will read this metadata to make decisions over schema file.dgconfig (DgMeta struct)
Example dgconfig representation
Output from TypeDef and Index Generator
Defining
DgMeta
in dataclasses