Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rake just one migration

I'm trying to run just one migration out of a whole bunch in my rails app. How can I do this? I don't want to run any of the migrations before or after it. Thanks.

like image 338
Anon Avatar asked Aug 25 '09 22:08

Anon


People also ask

How do I rollback a specific migration?

You can rollback your migration by using rake db:rollback with different options. The syntax will be different according to your requirements.

How do I run a particular migration in Rails?

To run a specific migration up or down, use db:migrate:up or db:migrate:down . The version number in the above commands is the numeric prefix in the migration's filename. For example, to migrate to the migration 20160515085959_add_name_to_users. rb , you would use 20160515085959 as the version number.

How does rake db migrate work?

A migration means that you move from the current version to a newer version (as is said in the first answer). Using rake db:migrate you can apply any new changes to your schema. But if you want to rollback to a previous migration you can use rake db:rollback to nullify your new changes if they are incorrectly defined.


2 Answers

rake db:migrate:redo VERSION=xxxxxxx, but that will run the down and then the up step. You could do this in conjunction with commenting out the down step temporarily.

like image 64
Ryan Bigg Avatar answered Oct 06 '22 07:10

Ryan Bigg


rake db:migrate:up VERSION=1234567890 

similarly rake db:migrate:down to take a specific migration down. You can get a list of available rake tasks with rake -T.

like image 32
Shadwell Avatar answered Oct 06 '22 07:10

Shadwell