Search code examples
ruby-on-railsrubyrails-migrations

rails How to properly rollback certain migrations


In my blog project, I used paperclip to manage the pictures. Now I'd like to switch to carrierwave, and want to make my project as if paperclip was never there.

First of, this is what the project looks like: Every blogpost has many pictures, and every picture has one image. So I generated a model for the gallery

rails g model pictures

this creates the migration create_pictures.rb and the picture model. Then I added the image attribute to the picture model

rails g paperclip picture image

this created the migration AddAttachementImageToPictures.rb Then I created the migration AddPostIdToPictures

Now I want to make a migration that gets rid of all this stuff. 2 of the 3 migrations are about adding attributes to the pictures table. So I wonder if I could just remove the pictures table and the picture model?

rails g migration RemovePictures
rails d model Picture

Or do I need to remove the attributes first, and then the whole table?


Solution

  • Yes you are doing right thing. You should remove pictures table and then Picture model.

    You don't need to remove each single column separately if you don't need that table. Or if you are planing to use same model for carrierwave as well then you can just remove attribute for paperclip and create new one for carrierwave.

    This link will help you in migration changes.