Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ConvertBackgroundImage < ActiveRecord::Migration
- include PaperclipMigrations
- def self.up
- # Paperclip
- add_column :background_images, :photo_file_name, :string
- add_column :background_images, :photo_content_type, :string
- add_column :background_images, :photo_file_size, :integer
- add_column :background_images, :photo_updated_at, :datetime
- # Update table information
- BackgroundImage.reset_column_information
- # Delete all attachement_fu image sizes
- BackgroundImage.delete_all("parent_id IS NOT NULL")
- remove_column :background_images, :parent_id
- # Migrate data
- BackgroundImage.all.each do |image|
- populate_paperclip_from_attachment_fu(image, image, 'photo', 'public/system/background_images') if image
- image.reprocess! if image
- end
- # After data migration and paperclip reprocessing remove attachement_fu columns
- remove_column :background_images, :filename
- remove_column :background_images, :content_type
- remove_column :background_images, :size
- end
- def self.down
- raise ActiveRecord::IrreversibleMigration, "Can't recover the deleted data (Image)."
- end
- end
Add Comment
Please, Sign In to add comment