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

    schema.vertexLabel('author').describe()
    modifySchema2
    modifySchema2

    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')
    modifySchema3
    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
    modifySchema5
  • Verify that the property key is built for the edge label created. Look for the property key named timestamp.

    schema.edgeLabel('created').describe()
    modifySchema6
    modifySchema6

    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()
    modifySchema4
    modifySchema4

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, info@datastax.com