Guest User

Untitled

a guest
Jun 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class ConvertBackgroundImage < ActiveRecord::Migration
  2.  
  3. include PaperclipMigrations
  4.  
  5. def self.up
  6. # Paperclip
  7. add_column :background_images, :photo_file_name, :string
  8. add_column :background_images, :photo_content_type, :string
  9. add_column :background_images, :photo_file_size, :integer
  10. add_column :background_images, :photo_updated_at, :datetime
  11.  
  12. # Update table information
  13. BackgroundImage.reset_column_information
  14.  
  15. # Delete all attachement_fu image sizes
  16. BackgroundImage.delete_all("parent_id IS NOT NULL")
  17. remove_column :background_images, :parent_id
  18.  
  19. # Migrate data
  20. BackgroundImage.all.each do |image|
  21. populate_paperclip_from_attachment_fu(image, image, 'photo', 'public/system/background_images') if image
  22. image.reprocess! if image
  23. end
  24.  
  25. # After data migration and paperclip reprocessing remove attachement_fu columns
  26. remove_column :background_images, :filename
  27. remove_column :background_images, :content_type
  28. remove_column :background_images, :size
  29. end
  30.  
  31. def self.down
  32. raise ActiveRecord::IrreversibleMigration, "Can't recover the deleted data (Image)."
  33. end
  34.  
  35.  
  36. end
Add Comment
Please, Sign In to add comment