スキーマの変更

最初の作成後にスキーマを変更する方法。

スキーマの作成は、グラフ・データベース作成の重要な一部です。最初に作成した後でスキーマを追加したり変更したりすることが必要になる場合があります。Developmentモードでは、データの作成後にスキーマを変更することができます。Productionモードでは、スキーマの作成とデータの読み込みを混合することはできません。プロパティ・キーは追加できます。隣接を特定することができます。

手順

頂点ラベルへのプロパティ・キーの追加

  • スキーマの作成後、プロパティ・キーを追加します。プロパティ・キーは既に存在している必要があります。次の例では、最初のコマンドによって、グラフのプロパティ・キーを構築し、2つ目のコマンドによって、頂点ラベルauthorにプロパティ・キーを追加します。
    gremlin> schema.propertyKey('nationality').Text().create()
    gremlin> schema.vertexLabel('author').properties('nationality').add()
    ==>null
  • 頂点ラベルauthorのプロパティ・キーが構築されることを確認します。nationalityというプロパティ・キーを探します。
    gremlin> schema.vertexLabel('author').describe()
    ===>schema.vertexLabel("author").properties("nationality", "name", "gender").create()
    schema.vertexLabel("author").index("byName").secondary().by("name").add()

    プロパティnamegenderは、nationalityを追加する前から存在していました。頂点ラベルのインデックスもすべて表示されます。

  • 新しく追加したプロパティ・キーの値を頂点に追加します。
    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]]

2つの頂点の隣接を特定します。

  • プロパティを使用して頂点ラベルを作成します。それらすべてのプロパティは、頂点ラベルを作成する前から存在している必要があります。connectionの外向き頂点と内向き頂点を指定する辺ラベルを追加します。
    gremlin> schema.vertexLabel('FridgeItem').properties('name','expiration_date','amount').add()
    gremlin> schema.edgeLabel('isA').connection('ingredient','FridgeItem').create()
    schema.edgeLabel('isA').describe()
    schema.edgeLabel("isA").multiple().create()
    schema.edgeLabel("isA").connection("ingredient",
    "FridgeItem").connection("FridgeItem", "ingredient").add()