Buildpacks are scripts that run after your app is deployed to Heroku. Heroku is smart enough to figure out what buildpacks to use depending on your app. For example, assets are automatically prepared when you deploy your Rails app.

Heroku Buildpacks

For added functionality, Heroku lets you add additional buildpacks. So, to automatically run any pending database migration after your Rails app deploys:

  1. Go to your app’s directory and run heroku buildpacks to see the list of current buildpacks.
  2. Add a rake tasks buildpack with: heroku buildpacks:add
  3. Configure this buildpack: heroku config:set DEPLOY_TASKS='db:migrate cache:clear'
  4. You are all done! Any pending migrations will automatically run the next time you deploy to Heroku.

More resources: