private static Set getNodeSchemaStatements()

in v2/googlecloud-to-neo4j/src/main/java/com/google/cloud/teleport/v2/neo4j/database/CypherGenerator.java [139:268]


  private static Set<String> getNodeSchemaStatements(
      NodeTarget target, Neo4jCapabilities capabilities) {
    NodeSchema schema = target.getSchema();
    Set<String> statements = new LinkedHashSet<>();

    if (capabilities.hasNodeTypeConstraints()) {
      Map<String, PropertyType> types = indexPropertyTypes(target.getProperties());
      for (var constraint : schema.getTypeConstraints()) {
        String property = constraint.getProperty();
        statements.add(
            "CREATE CONSTRAINT "
                + sanitize(constraint.getName())
                + " IF NOT EXISTS FOR (n:"
                + sanitize(constraint.getLabel())
                + ") REQUIRE n."
                + sanitize(property)
                + " IS :: "
                + CypherPatterns.propertyType(types.get(property)));
      }
    }
    if (capabilities.hasNodeKeyConstraints()) {
      for (var constraint : schema.getKeyConstraints()) {
        var properties =
            CypherPatterns.qualifyAll("n", CypherPatterns.sanitizeAll(constraint.getProperties()));
        var options = CypherPatterns.schemaOptions(constraint.getOptions());
        statements.add(
            "CREATE CONSTRAINT "
                + sanitize(constraint.getName())
                + " IF NOT EXISTS FOR (n:"
                + sanitize(constraint.getLabel())
                + ") REQUIRE ("
                + String.join(", ", properties)
                + ") IS NODE KEY"
                + (options.isEmpty() ? "" : " " + options));
      }
    }
    if (capabilities.hasNodeUniqueConstraints()) {
      for (var constraint : schema.getUniqueConstraints()) {
        var properties =
            CypherPatterns.qualifyAll("n", CypherPatterns.sanitizeAll(constraint.getProperties()));
        var options = CypherPatterns.schemaOptions(constraint.getOptions());
        statements.add(
            "CREATE CONSTRAINT "
                + sanitize(constraint.getName())
                + " IF NOT EXISTS FOR (n:"
                + sanitize(constraint.getLabel())
                + ") REQUIRE ("
                + String.join(", ", properties)
                + ") IS UNIQUE"
                + (options.isEmpty() ? "" : " " + options));
      }
    }
    if (capabilities.hasNodeExistenceConstraints()) {
      for (var constraint : schema.getExistenceConstraints()) {
        statements.add(
            "CREATE CONSTRAINT "
                + sanitize(constraint.getName())
                + " IF NOT EXISTS FOR (n:"
                + sanitize(constraint.getLabel())
                + ") REQUIRE n."
                + sanitize(constraint.getProperty())
                + " IS NOT NULL");
      }
    }
    for (var index : schema.getRangeIndexes()) {
      var properties =
          CypherPatterns.qualifyAll("n", CypherPatterns.sanitizeAll(index.getProperties()));
      statements.add(
          "CREATE INDEX "
              + sanitize(index.getName())
              + " IF NOT EXISTS FOR (n:"
              + sanitize(index.getLabel())
              + ") ON ("
              + String.join(", ", properties)
              + ")");
    }
    for (var index : schema.getTextIndexes()) {
      String options = CypherPatterns.schemaOptions(index.getOptions());
      statements.add(
          "CREATE TEXT INDEX "
              + sanitize(index.getName())
              + " IF NOT EXISTS FOR (n:"
              + sanitize(index.getLabel())
              + ") ON (n."
              + sanitize(index.getProperty())
              + ")"
              + (options.isEmpty() ? "" : " " + options));
    }
    for (var index : schema.getPointIndexes()) {
      String options = CypherPatterns.schemaOptions(index.getOptions());
      statements.add(
          "CREATE POINT INDEX "
              + sanitize(index.getName())
              + " IF NOT EXISTS FOR (n:"
              + sanitize(index.getLabel())
              + ") ON (n."
              + sanitize(index.getProperty())
              + ")"
              + (options.isEmpty() ? "" : " " + options));
    }
    for (var index : schema.getFullTextIndexes()) {
      var properties =
          CypherPatterns.qualifyAll("n", CypherPatterns.sanitizeAll(index.getProperties()));
      var options = CypherPatterns.schemaOptions(index.getOptions());
      statements.add(
          "CREATE FULLTEXT INDEX "
              + sanitize(index.getName())
              + " IF NOT EXISTS FOR (n"
              + CypherPatterns.labels(index.getLabels(), "|")
              + ") ON EACH ["
              + String.join(", ", properties)
              + "]"
              + (options.isEmpty() ? "" : " " + options));
    }
    if (capabilities.hasVectorIndexes()) {
      for (var index : schema.getVectorIndexes()) {
        var options = CypherPatterns.schemaOptions(index.getOptions());
        statements.add(
            "CREATE VECTOR INDEX "
                + sanitize(index.getName())
                + " IF NOT EXISTS FOR (n:"
                + sanitize(index.getLabel())
                + ") ON (n."
                + sanitize(index.getProperty())
                + ")"
                + (options.isEmpty() ? "" : " " + options));
      }
    }
    return statements;
  }