Cypher init script

Apoc optionally allows you to run cypher commands after database initialization is finished. This can e.g. be used to ensure indexes/constraints are created up front.

The initializers are defined by Configuration Options using the following naming convention:

apoc.initializer.<database_name>.<identifier> = <some cypher string>

For each database all initializer strings are ordered by <identifier> and each of them is executed in a separate transaction. If you only have one single initializer for a given database you can omit <identifier>.

As an example we want to

  • create another db user in system db

  • create a index for :Person in default db neo4j

  • add two person nodes in default db neo4j

This is achieved by

apoc.initializer.system=create user dummy set password 'abc'
apoc.initializer.neo4j.0=create index person_index for (p:Person) on (p.name)
apoc.initializer.neo4j.1=create (:Person{name:'foo'})
apoc.initializer.neo4j.2=create (:Person{name:'bar'})