apoc.schema.assert

Procedure APOC Core

apoc.schema.assert({indexLabel:, …​}, {constraintLabel:[constraintKeys], …​}, dropExisting : true) yield label, key, keys, unique, action - drops all other existing indexes and constraints when dropExisting is true (default is true), and asserts that at the end of the operation the given indexes and unique constraints are there, each label:key pair is considered one constraint/label. Non-constraint indexes can define compound indexes with label:[key1,key2…​] pairings.

Signature

apoc.schema.assert(indexes :: MAP?, constraints :: MAP?, dropExisting = true :: BOOLEAN?) :: (label :: ANY?, key :: STRING?, keys :: LIST? OF STRING?, unique :: BOOLEAN?, action :: STRING?)

Input parameters

Name Type Default

indexes

MAP?

null

constraints

MAP?

null

dropExisting

BOOLEAN?

true

Output parameters

Name Type

label

ANY?

key

STRING?

keys

LIST? OF STRING?

unique

BOOLEAN?

action

STRING?

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:

Table 1. 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({}, {});
Table 2. Results
label key keys unique action

"Person"

"id"

["id"]

FALSE

"DROPPED"

"Person"

"name"

["name"]

TRUE

"DROPPED"