Deploying EdgeDB to Heroku

In this guide we show how to deploy EdgeDB to Heroku using a Heroku PostgreSQL add-on as the backend.

Because of Heroku’s architecture EdgeDB must be deployed with a web app on Heroku. For this guide we will use a todo app written in node.

Prerequisites

Setup

First copy the code, initialize a new git repo, and create a new heroku app.

  1. $
  1. npx degit 'edgedb/simpletodo#main' simpletodo-heroku
  1. $
  1. cd simpletodo-heroku
  1. $
  1. git init --initial-branch main
  1. $
  1. heroku apps:create --buildpack heroku/nodejs
  1. $
  1. edgedb project init --non-interactive

If you are using the JS query builder for EdgeDB then you will need to check the dbschema/edgeql-js directory in to your git repo after running yarn edgeql-js. The edgeql-js command can not be run during the build step on Heroku because it needs access to a running EdgeDB instance which is not available at build time on Heroku.

  1. $
  1. yarn install && npx edgeql-js

The dbschema/edgeql-js directory was added to the .gitignore in the upstream project so we’ll remove it here.

  1. $
  1. sed -i '/^dbschema\/edgeql-js$/d' .gitignore

Create a PostgreSQL Add-on

Heroku’s smallest PostgreSQL plan, Hobby Dev, limits the number of rows to 10,000, but EdgeDB’s standard library uses more than 20,000 rows so we need to use a different plan. We’ll use the Standard 0 plan for this guide.

  1. $
  1. heroku addons:create heroku-postgresql:standard-0

Add the EdgeDB Buildpack

To run EdgeDB on Heroku we’ll add the EdgeDB buildpack.

  1. $
  1. heroku buildpacks:add \
  2. --index 1 \
  3. https://github.com/edgedb/heroku-buildpack-edgedb.git

To make EdgeDB available to a process prepend the command with start-edgedb which is provided by the EdgeDB buildpack. For the sample application in this guide, the web process is started with the command npm start. If you have other processes in your application besides/instead of web that need to access EdgeDB those process commands should be prepended with start-edgedb too.

  1. $
  1. echo "web: start-edgedb npm start" > Procfile

Deploy the App

Commit the changes and push to Heroku to deploy the app.

  1. $
  1. git add .
  1. $
  1. git commit -m "first commit"
  1. $
  1. git push heroku main