12

I want to rollback my database to a certain version on Rails using the STEP parameter, but I don't know how many steps should i rollback so I want to check the migration log. Can I do that on Rails (v3.2.13)?

1
  • Do you know the specific migration upto which you want to rollback
    – Grey
    Commented Apr 27, 2013 at 5:14

2 Answers 2

24

Try the following:

rake db:migrate:status

It will give you the following output, up meaning migration has been run, down hasn't been run yet:

Status   Migration ID    Migration Name
--------------------------------------------------
   up     20120328154345  Devise create users
   up     20120331182021  Create websites
0
2

You can try to get migration versions by

 >  ActiveRecord::Migrator.current_version
   (38.7ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" 
 => 20130403113845 
1.9.3-p392 :002 > ActiveRecord::Migrator.get_all_versions
   (0.8ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" 
 => [20130327085819, 20130327085820, 20130327085821, 20130327085822, 20130327085823, 20130327085824, 20130327085825, 20130327085826, 20130327085827, 20130327085828, 20130327085829, 20130327085830,........

or you can use the time stamp of the specific migration upto which you want to rollback and use

rake db:migrate:down VERSION= timestamp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.