Modifying schema

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.

  • 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()
  • Verify that the property key is built for the vertex label author. Look for the property key named nationality.

    gremlin> schema.vertexLabel('author').describe()
    ===>schema.vertexLabel("author").properties("nationality", "name", "gender").create()

    The properties name and gender 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.

    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()
          "FridgeItem").connection("FridgeItem", "ingredient").add()

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000,