This tutorial describes how to migrate your web application running on Heroku to Qovery. In the article, you learn how to migrate a Node.js application connected to Heroku Postgres as a backing service on the Heroku platform. It covers all required steps you need to take to deploy your application on Qovery and transfer your data from Heroku Postgres to the database managed by Qovery.
The application is a simple Node.js Todo web app that uses PostgreSQL as a persistence layer.
- You are familiar with Heroku basics, have a Heroku account and access to Heroku CLI
- You have a Qovery account and access to Qovery CLI
- You have a Github account
If you have not installed the Qovery CLI yet, you can see steps to take here.
Deploying the sample application to Heroku
Log in to Heroku using the CLI:heroku login --interactive
Clone the application repository:git clone https://github.com/qovery/migrate-webapp-from-heroku-to-qovery.git
Move to the directory of the cloned repository:cd migrate-webapp-from-heroku-to-qovery
The repository is made of a few simple components:
index.js- Node.js script for setting up the web application.
package.json- File determining app's dependencies.
Procfile- File required to run the app on Heroku. It determines the command executed on the application startup.
views- Directory with the HTML served by the app.
Create a Heroku app:heroku create
Add Heroku PostgreSQL to your application:heroku addons:create heroku-postgresql:hobby-dev
Deploy the application:git push heroku master
Check your application URL:heroku info
In the browser, navigate to your application's URL - you'll see a simple view with a Todo app:
Create a few Todo tasks in the UI to make sure you have sample data in the database.
Migrating the application from Heroku to Qovery
Dockerize the application
As Qovery uses Docker for the runtime of applications, you need first to Dockerize the application. To do so,
create a file named
Dockerfile in the root of application repository with the following content:
FROM node:10-alpineWORKDIR /appCOPY package*.json ./RUN npm installCOPY . /appEXPOSE 8080CMD ["npm", "start"]
If you want to learn more about Docker, you can read our introductory article:
To set up the application for Qovery deployment with a PostgreSQL database, create a
.qovery.yml file in the root of the project with the following content:
application:name: node-todo-appproject: migrate-from-herokupublicly_accessible: truedatabases:- type: postgresqlversion: "11.5"name: my-postgresql-databaserouters:- name: mainroutes:- application_name: node-todo-apppaths:- /
The sample application uses
DATABASE_URL environment variable to connect to PostgreSQL. To provide your app
with correct database URL, create a
.env file in the root of application repository with this content:
Adding this file populates the
DATABASE_URL environment variable (that is consumed often on Heroku)
with database URL provided by Qovery.
Deploy the application to Qovery
All you need to do to deploy the application to Qovery is to commit and push a repository containing
.qovery.yml to Github.
Qovery needs access to this repository to build and deploy the application.
Remove current git configuration from the repository you cloned:
rm -rf .git
- Initialize a new repository and commit all files:
git initgit add .git commit -m "Deploying to Qovery"
- Push the local repository to the newly created Github repo (replace placeholders in the code below):
git remote add origin https://github.com/$YOUR_NAME/$YOUR_REPOSITORY_NAME.gitgit push -u origin master
Good job! It's all you need to do to deploy your application with a database to Qovery.
To confirm that your application is, in fact, deploying, run
The output of the above command could look like this:
BRANCH NAME | STATUS | ENDPOINTS | APPLICATIONS | DATABASESmaster | running | https:/your.app.url.qovery.io | node-todo-app | my-postgresql-databaseAPPLICATION NAME | STATUS | DATABASESnode-todo-app | running | my-postgresql-databaseDATABASE NAME | STATUS | TYPE | VERSION | ENDPOINT | PORT | USERNAME | PASSWORD | APPLICATIONSmy-postgresql-database | running | POSTGRESQL | 11.5 | <hidden> | <hidden> | <hidden> | <hidden> | node-todo-app
The application should be deployed in a few minutes. When it's status is
running, open the browser
using address specified in the
ENDPOINTS section of
qovery status output.
You should see the same application you previously deployed to Heroku, yet without the data from the database.
Migrate PostgreSQL data
There are multiple paths you could take to migrate your data from Heroku Postgres to Qovery. For production usage for the shortest downtime you would probably want to configure Qovery PostgreSQL as a replica to the database on Heroku, and making it the primary instance after migration. Heroku does not support this in its free tier, so for the purpose of the example, we take a simpler path and use different tools to migrate the data.
First, dump the data from your Heroku Postgres:
heroku pg:backups:download -a YOUR_APPLICATION_NAMEheroku pg:backups:capture -a YOUR_APPLICATION_NAME
It results in creating a new
latest.dump file, which you use to transfer data to Qovery.
To migrate the data to Qovery, run (replace all placeholders with values you get from running
qovery application env list -c):
pg_restore -v -h $DATABASE_HOST -U $DATABASE_USER -d postgres latest.dump --no-owner
In the browser, navigate to your application URL deployed on Qovery. Now you should see all the data you had in your database hosted on Heroku. Well done!