How to create migrations in Ruby on Rails that only run in the development enviroment

February 13th, 2010 at 12:52 am No Comments

This is a reminder for myself for when I want to use a migration to create test data for the development environment only.

I thought it would be as easy as using the environment variable ENV['RAILS_ENV'] in the migration to see which environment you’re in, but this doesn’t work. After a little searching, it is as easy as I thought; you just have to use the constant RAILS_ENV. So, your migration would look something like this:


def self.up
  if RAILS_ENV == 'development'
    # set all of your test data for development...
  end
end

Leave a Comment