apoc.schema.assert

This procedure is not considered safe to run from multiple threads. It is therefore not supported by the parallel runtime (introduced in Neo4j 5.13). For more information, see the Cypher Manual → Parallel runtime.

Details

Syntax

apoc.schema.assert(indexes, constraints [, dropExisting ]) :: (label, key, keys, unique, action)

Description

Drops all other existing indexes and constraints when dropExisting is true (default is true). Asserts at the end of the operation that the given indexes and unique constraints are there.

Input arguments

Name

Type

Description

indexes

MAP

A map that pairs labels with lists of properties to create indexes from.

constraints

MAP

A map that pairs labels with lists of properties to create constraints from.

dropExisting

BOOLEAN

Whether or not to drop all other existing indexes and constraints. The default is: true.

Return arguments

Name

Type

Description

label

ANY

The label associated with the constraint or index.

key

STRING

The property key associated with the constraint or index.

keys

LIST<STRING>

The property keys associated with the constraint or index.

unique

BOOLEAN

Whether or not this is a uniqueness constraint.

action

STRING

The action applied to this constraint or index; can be ["KEPT", "CREATED", "DROPPED"]

Usage Examples

CALL apoc.schema.assert({
  Person: ["id"]
}, {
  Person: ["name"]
});

We can create a uniqueness constraint on :Person(name) and an index on :Person(id) by running the following query:

Results
label key keys unique action

"Person"

"id"

["id"]

FALSE

"CREATED"

"Person"

"name"

["name"]

TRUE

"CREATED"

We can drop all constraints and indexes, by running the following query. Note that the cancellation mechanism doesn’t consider indexes of type LOOKUP and multi-token indexes, that is indexes applicable to multiple rel-types or multiple labels, for example CREATE FULLTEXT INDEX titlesAndDescriptions FOR (n:Movie|Book) ON EACH [n.title, n.description] or CREATE FULLTEXT INDEX fullIdxRel FOR ()-[r:TYPE_1|TYPE_2]-() ON EACH [r.alpha, r.beta]. This because they cannot be re-created by the apoc.schema.assert procedure:

CALL apoc.schema.assert({}, {});
Results
label key keys unique action

"Person"

"id"

["id"]

FALSE

"DROPPED"

"Person"

"name"

["name"]

TRUE

"DROPPED"