ruby-on-railsrubyherokumigrationrails-migrations

How to have Rails migrations run automatically on Heroku


I have more than 10 different Ruby on Rails apps where I have to deploy the same code. I have connected the git repo to my Heroku apps, so whenever I push new changes it deploys on all of them.

The issue is with the database migration step. I want to run migrations automatically after each deployment. None of custom build pack is working. Can someone please help me? I am using rails 4 and spree.

So far, I have tried:

  1. https://github.com/heroku/heroku-buildpack-ruby.git
  2. https://github.com/gunpowderlabs/buildpack-ruby-db-migrate.git

This solution is not working.

Is there any other solution to run Rails migrations on Heroku automatically?


Solution

  • No need to use gems or write scripts. Heroku has a 'release' phase features (https://devcenter.heroku.com/articles/release-phase).

    Thank to this, you just have to add to your Procfile some code to automatically run rails db:migrate to all your push:

    # cat Procfile
    release: bundle exec rails db:migrate