Neo4J (GraphDB)#

Neo4J is an open source and enterprise graph database. We repurposed the dokku postgres plugin for neo4j here, the README has additional documentation. It can be used to launch & manage databases and link them to apps.

Creating a database for your app#

# create the database
dokku neo4j:create <db-name>

# connect to the database
dokku neo4j:connect <db-name>

Provisioning the database from an existing database#

# dump data from local database
#  (NOTE: neo4j likely requires additional parameters like the hostname, username & password to local db)
neo4j-admin dump --to=- > db.dump

# send dump to dokku database
dokku neo4j:import <db-name> < db.dump

Dumping from a dockerized neo4j database#

Neo4j dump command only works when the database is not running, so you must first stop the container then use the dump command. For a docker-compose setup it looks like:

docker-compose stop neo4j
docker-compose run neo4j neo4j-admin dump --to=- > db.dump
docker-compose start neo4j

Linking the database to your app#

# assuming the db and app are created
dokku neo4j:link <db-name> <app-name>

This will set an environment variable: NEO4J_URL which contains a connection URI of the form bolt://<username>:<auto-generated-password>@<service-name>:7687/<db-name>.

Importantly, your app should receive this variable and use it to configure the database. For example, in python:

import os
from py2neo import Graph

NEO4J_URL = os.environ.get('NEO4J_URL')
assert NEO4J_URL is not None, 'Missing NEO4J_URL environment variable to connect to the database'

# connect to db
graph = Graph(NEO4J_URL)

# ... use graph in your app to build queries ...

Exporting from dokku neo4j#

# data in a dokku database can also be exported similarly to neo4j-admin dump
dokku neo4j:export <db-name> > db.dump