Modifying schema using Studio 

How to modify schema after initial creation.

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.

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.
    schema.propertyKey('nationality').Text().create()
    schema.vertexLabel('author').properties('nationality').add()
  • Verify that the property key is built for the vertex label author. Look for the property key named nationality.
    schema.vertexLabel('author').describe()

    The properties name existed prior to the addition of nationality. 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')

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()
  • 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.
    schema.vertexLabel('FridgeItem').properties('name','expiration_date','amount').add()
    schema.edgeLabel('isA').connection('ingredient','FridgeItem').create()