Cypher initializer

APOC allows you to optionally run Cypher commands after database initialization is finished. This can be used to ensure indexes and constraints are created on startup.

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 a single initializer for a given database you can omit <identifier>.

For example, if you want to:

  • Create another database user in the System db.

  • Create an index for :Person in the default database neo4j.

  • Add two :Person nodes in to the default database 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'})