I'm trying to revert my database to a previous state. For some reason db:rollback
isn't working properly (I might have flubbed one of my down
methods), so instead of rolling back, I was wondering if I could get there by dropping the database and then re-running certain migrations. Essentially, I'd like to run db:migrate
, but I'd like it to stop at a particular timestamp.
Is there a rake command that will run all migrations up to and including a given timestamp?
How do I run a specific 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.
To use the Down method you must explicitly specify the target migration for your upgrade. If the target migration is the old one, the migration API will automatically use the Down method and downgrade your database.
The up and down methods are a more granular way of defining the change method in a Rails migration. The up method is a set of instructions of what to do when you migrate, and the down method is a set of directions of what to do when you rollback.
db:reset: Resets your database using your migrations for the current environment. It does this by running the db:drop , db:create , db:migrate tasks. db:rollback: Rolls the schema back to the previous version, undoing the migration that you just ran. If you want to undo previous n migrations, pass STEP=n to this task.
rake db:migrate 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