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
Developmentmode, 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.
Procedure
Examine the current schema
Before making modifications to the schema, examine the current settings.
schema.describe()
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.
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.
Verify that the property key is built for the edge label
created. Look for the property key named
timestamp.
schema.edgeLabel('created').describe()
The properties year existed prior to the addition of
timestamp. 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.