Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: how to run all migrations up to a certain timestamp

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?

like image 340
dB' Avatar asked Feb 08 '13 12:02

dB'


People also ask

How do I run a specific migration in rails?

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.

How do you do the run down method of migration?

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.

What is up and down in rails migration?

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.

What does rake db Reset do?

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.


1 Answers

rake db:migrate VERSION=timestamp
like image 112
Babur Ussenakunov Avatar answered Oct 26 '22 01:10

Babur Ussenakunov