views:

416

answers:

3

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?

+1  A: 

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.

Sohan
+1  A: 

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

bobbywilson0
what about later migrations that add data to this model? does script/destroy search the migrations or does it just delete the initial one that created the table?
brad
Later migrations will need their own `script/destory migration migration_name`. A good way to think about it, it is the undo of the genarate command. So, no it also won't search for other migrations that alter the same model.
bobbywilson0
right, so then the final answer to all of this is that I can use script/destroy, but I also need to manually edit any migrations that might contain refs to these deleted models. Thanks so much
brad
+1  A: 

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.

nowk