views:

23

answers:

1

I am trying to run some custom SQL during the setup of my Rails integration tests to prepare a legacy database (e.g., to create its tables, create any required views, etc.), which is not part of my schema.rb (nor do any migrations for it exist).

Are there any best practices for doing so? Googling has not been very enlightening so far ;-)

The reason why there are not any migrations is that in the development and production RAILS_ENV the database already exists for legacy reasons. If there is a way to run these migrations only for RAILS_ENV=='test', that would maybe also help.

A: 

You can pass the Rails environment to Rake on the command line. For example, to only run migrations for the test environment, do:

rake RAILS_ENV=test db:migrate
John Topley
Ok, I am aware of that, but maybe I am missing something terribly obvious: How do I declare a migration, which only runs in the test environment?The same applies to schema.rb.I could certainly put in some ugly `RAILS_ENV=='test'` conditionals, but hope there is a more elegant (and declarative) way to do this.
tg