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)?
To check for status, run rails db:migrate:status . Then you'll have a good view of the migrations you want to remove. Then, run rails db:rollback to revert the changes one by one.
Migrations are a convenient way to alter your database schema over time in a consistent way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent. You can think of each migration as being a new 'version' of the database.
rails db:rollback:primary , where primary is the name of the database in your config/databases. yml file, to rollback the last migration. You can make usage of the STEPS attribute here, as usual. rails db:rollback:primary VERSION=your_migration_timestamp , to rollback only the provided migration version.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With