Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running migrations against the Rails test environment

Tags:

I know that I can run specific migrations:

rake db:migrate:up VERSION=20080906120000 

But can I run a specific migration against my test database? Will the following work?

RAILS_ENV=test rake db:migrate:up VERSION=20080906120000 

In theory, running the migrations in default mode (which should affect the development database) and then running rake db:test:prepare should get the job done, but I found something strange with my test database after doing that, and I need to run a specific migration on the test database to aid my troubleshooting.

I'd just try out the above rake command, except I'm in the middle of a long data seeding run on my development database, and I can't risk the migration interfering with that, so I figured I'd see if anyone knows the answer before I can determine it myself. :)

like image 890
Josh Glover Avatar asked Mar 17 '11 14:03

Josh Glover


People also ask

How can I check my Rails migration status?

rake db:migrate:status (Rails 3 to 5) or rails db:migrate:status (Rails 5) will accomplish this. See this commit. up means the migration has been run. down means the migration has not been run.

Are Rails migrations run in a transaction?

On databases that support transactions with statements that change the schema, migrations are wrapped in a transaction. If the database does not support this then when a migration fails the parts of it that succeeded will not be rolled back. You will have to rollback the changes that were made by hand.

How does migration work in Rails?

A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.


1 Answers

In different order:

rake db:migrate:up VERSION=20080906120000 RAILS_ENV=test 
like image 173
Adrian Serafin Avatar answered Oct 29 '22 16:10

Adrian Serafin