- Create groovy file Eg:
schema.groovy
, then create function eg:
def defineSchema(graph) {
graph.tx().rollback()
mgmt = graph.openManagement()
// Vertex Schema
if (!mgmt.containsPropertyKey("name")) mgmt.makePropertyKey("name").dataType(String.class).cardinality(org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality.single).make()
// Edge Schema
if (!mgmt.containsPropertyKey("role")) mgmt.makePropertyKey("role").dataType(String.class).cardinality(org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality.single).make()
name = mgmt.getPropertyKey("name")
// Vertex Indices
mgmt.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex()
// Edge Indices
hasRole = mgmt.getEdgeLabel('has_role')
mgmt.buildEdgeIndex(hasRole, 'hasRoleByEndTime', Direction.BOTH, endTime)
//Commit
mgmt.commit()
}
- Login in to gremlin console
./gremlin.sh
- Connect to database with session
:remote connect tinkerpop.server conf/remote.yaml session
:remote console
- Load & Define Schema
Before load, make sure the file is upload to janus user accessible location. Eg /home/janus/schema.groovy
Load:
:load /home/janus/schema.groovy
Define:
defineSchema(graph)
mgmt=graph.openManagement()
mgmt.printSchema()
mgmt.commit()