Shoaib
Shoaib

Reputation: 1185

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?

Upvotes: 5

Views: 1720

Answers (3)

Gregdebrick
Gregdebrick

Reputation: 581

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

Upvotes: 15

SomeSchmo
SomeSchmo

Reputation: 665

You can use Travis-ci. Pretty simple to setup and provides the desired functionality

Upvotes: 1

Muhammad Ali
Muhammad Ali

Reputation: 2183

Add gem 'iconv', '~> 1.0.3' to your gemfile and then try it will work as worked for me!

I take this as a duplicate of this answer

If you are looking for alternative then you can write a deploy script in .sh file and run it everytime like bash script.

Upvotes: -1

Related Questions