2

Is there a way to only run migrations in the test environment?

I'd like to create tables and seed the data in only the test environment since the staging and production databases already exist.

dspencer
  • 918
  • 2
  • 8
  • 38

2 Answers2

5

I've found a solution based on the post here. This allows me to only apply the migration against the test environment.

class CreateLicenseDatabase < ActiveRecord::Migration
  def change
    if Rails.env.test?

      create_table.....

    end
  end
end
dspencer
  • 918
  • 2
  • 8
  • 38
  • 1
    This however will get you into a weird state where your migrations do not match your schema.rb. I would caution against doing this. – silvamerica Dec 03 '14 at 22:07
  • 2
    The reason why I wanted to just run the some migrations in the test environment is that I wanted to replicate a legacy database for the test environment only. – dspencer Dec 04 '14 at 13:31
0

Can't you just do this:

RAILS_ENV=test rake db:create
RAILS_ENV=test rake db:migrate

?

Chris Salzberg
  • 27,099
  • 4
  • 75
  • 82