Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove past migration in rails

I created quite a lot of migrations since the beginning of my rails app. Some of them where just for test purposes. I now have a lot of migrations that are totally useless (eg: create a table in a migration and drop it in the next one).

As schema.rb get updated once db:migrate is ran, is it possible to delete all the migrations and to start from the actual content of schema.rb ?

like image 504
Luc Avatar asked Apr 12 '12 11:04

Luc


1 Answers

Yes, you can (and probably should) remove older migrations. There will come a point where your old migrations might no longer work since your model code will depend on later versions of your schema.

So by all means delete the migrations (you have them under source control, right?), and use

rake db:schema:load

to initialize a new database if you need to.

UPDATE: The Rails guide now has something similar to say about this: http://guides.rubyonrails.org/active_record_migrations.html#schema-dumping-and-you

like image 129
Thilo Avatar answered Oct 13 '22 20:10

Thilo