Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Rails migration conditional on current RAILS_ENV?

How do you make a Rails migration conditional on the current RAILS_ENV?

Specifically, I want to:

  1. Check a migration into head-of-master
  2. Execute the migration only on our Staging instance

Doing this will allow us to perform database updates - via migrations - which we only want in our Staging environment. An example would be activating a feature for a specific account or class of accounts for testing purposes.

like image 943
Jordan Dea-Mattson Avatar asked Mar 01 '11 20:03

Jordan Dea-Mattson


1 Answers

Just use Rails.env.production? / Rails.env.<custom-env>? in your up / down class methods in the Migration.

like image 95
rmk Avatar answered Oct 04 '22 07:10

rmk