Rails remove old models with migrations

Viewed 17093

I have a bunch of rails models that I'm re-writing into a single model to simplify my code and reduce unnecessary tables.

I'm wondering what the best way to delete a model class and its table is. I want past migrations to still succeed, but I don't want to leave the empty models lying around.

Do I have to manually delete the old migrations that reference these models, then manually delete the class files?

Does anyone have any tips for the best way to do this?

7 Answers

What about doing ruby script/destroy model? That should take care of the model and the migration.

Depending on how far into development or production you are, you may want to migrate the models out safely using a migration to remove/backup data or what not. Then as bobbywilson0 suggested, using

script/destroy model

or if you rspec anything

script/destroy rspec_model

This will remove any spec tests as well.

Or you can always just drag them to the trash folder.

You can take a look at this one at rails guide. But I suggest, if it is possible, you should delete the models and all references to the models. This will probably save time later as you don't need to maintain the dead code in the codebase.

Related