In this tutorial, we're going to deploy an application with a PlanetScale database to Heroku. If you already have an application running locally, you can use it for this tutorial.
pscale auth login
Let's use the
pscale CLI on Heroku to establish a secure connection to your database.
pscale service-token create
Take note of the service token name and value it returns to you.
pscale service-token add-access your-token-name connect_production_branch --database your-db-name
heroku config:set PLANETSCALE_ORG=your-org-nameheroku config:set PLANETSCALE_SERVICE_TOKEN_NAME=your-token-nameheroku config:set PLANETSCALE_SERVICE_TOKEN=your-token-value
heroku buildpacks:add https://github.com/planetscale/heroku-buildpack-planetscale
This command will install the latest
pscale CLI into your Heroku application. You can specify a CLI version by setting
Procfilethat initiates your application using pscale:
web: pscale connect your-db-name main --execute 'node app.js'
As you can see, we chose to use the sample Node.js and Express.js application we built in our previous Connect Node.js App tutorial.
Congratulations! You successfully deployed an application to Heroku.
In this tutorial, we deployed an application that was connected to a PlanetScale database to Heroku. We chose to use the sample Node.js and Express.js application we built in our previous Connect Node.js App tutorial. That said, you could use any local application you've made and use it to connect to a PlanetScale database.
Now that you've successfully deployed an application to Heroku, it's time to make more schema changes to your tables! Learn more about how PlanetScale allows you to make non-blocking schema changes to your database tables without locking or causing downtime for production databases.