Modifying schema
How to modify schema after initial creation.
Schema creation is an important part of creating a graph database. It can be
necessary to add or modify the schema after initial creation. In
Development
mode, the schema can be modified
after data creation. In Production
mode, schema creation and data loading
cannot be mixed. Property keys can be added. Adjacencies can be identified.
Procedure
Add property keys to a vertex label
-
Add a property key after schema creation. The property key must already exist. In the
example, the first command builds the property key for the graph, and the second command
adds the property key to the vertex label
author
.gremlin> schema.propertyKey('nationality').Text().create() gremlin> schema.vertexLabel('author').properties('nationality').add()
==>null
-
Verify that the property key is built for the vertex label
author
. Look for the property key namednationality
.gremlin> schema.vertexLabel('author').describe()
===>schema.vertexLabel("author").properties("nationality", "name", "gender").create() schema.vertexLabel("author").index("byName").secondary().by("name").add()
The properties
name
andgender
existed prior to the addition ofnationality
. Any indexes on the vertex label are also displayed. -
Add a value for the newly added property key to a vertex.
gremlin> g.V().has('author','name','Julia Child').property('nationality','American')
gremlin> g.V().hasLabel('author').valueMap() ==>[gender:[F], name:[Alice Waters]] ==>[gender:[F], name:[Louisette Bertholie]] ==>[gender:[M], name:[Fritz Streiff]] ==>[gender:[F], nationality:[American], name:[Julia Child]]
Identify the adjacency for two vertices
-
Create a vertex label with properties. All the properties must exist prior to creating
the vertex label. Add an edge label that identifies the connection outgoing vertex and incoming vertex.
gremlin> schema.vertexLabel('FridgeItem').properties('name','expiration_date','amount').add() gremlin> schema.edgeLabel('isA').connection('ingredient','FridgeItem').create() schema.edgeLabel('isA').describe()
schema.edgeLabel("isA").multiple().create() schema.edgeLabel("isA").connection("ingredient", "FridgeItem").connection("FridgeItem", "ingredient").add()