I have a database set up for my Rails installation and some migrations set up. I would like to be able to reset my database back down to having no tables/constraints/etc., b
In addition to jdl's (correct) solution above, another hack-y way to acheive this is to do rake db:rollback STEP=1000000
, where 1000000
is a large number, larger than the number of migrations you'll ever have. It will rollback as far as it can up to 1000000
times, or however many times you put as the STEP
.
rake db:migrate VERSION=0
It works even if you're using the newer timestamped migration files.
Update: I just tested this on Rails 3.2.1, and it still works. It runs the "down" part of all the migrations known to schema_migrations
. I have no idea if it worked on 3.1 or not, but the comment below indicates that this feature was broken during that time.
It's moderately hackish, but you could do a query to find the first VERSION in schema_migrations and then call rake db:migrate:down to get that VERSION (I'm assuming you want to package up a "reset" script for your app).
That will, of course, require that the down methods on all your migrations work properly.