Modifying schema using Studio
Schema creation is an important part of creating a graph database.
It may 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.
One important distinction about schema is the difference between create()
and add()
.
The create()
command is used to create a property key, vertex label or edge label if it does not already exist.
When creating vertex labels and edge labels, create()
is used along with identification of associated property keys.
If a vertex label or edge label is created without property key identification, then the add()
command is used to identify associated property keys.
-
Examine the current schema
-
Before making modifications to the schema, examine the current settings.
schema.describe()
modifySchema1a
The schema displayed can be copied and used to reproduce the schema for a graph.
-
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
.schema.propertyKey('nationality').Text().create() schema.vertexLabel('author').properties('nationality').add()
modifySchema1
-
Verify that the property key is built for the vertex label
author
. Look for the property key namednationality
.schema.vertexLabel('author').describe()
modifySchema2
The properties
name
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.
g.V().has('author','name','Julia Child').property('nationality','American')
modifySchema3
-
Add property keys to an edge 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 edge label
created
.schema.edgeLabel('created').properties('timestamp').add()
modifySchema5 -
Verify that the property key is built for the edge label
created
. Look for the property key namedtimestamp
.schema.edgeLabel('created').describe()
modifySchema6
The properties
year
existed prior to the addition oftimestamp
. Any indexes on the vertex label are also displayed. -
Creating an edge between two vertices (connection)
-
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.
schema.vertexLabel('FridgeItem').properties('name','expiration_date','amount').add() schema.edgeLabel('isA').connection('ingredient','FridgeItem').create()
modifySchema4