debshots/lib/tasks/paperclip_to_shrine.rake
2020-11-01 23:25:34 +01:00

25 lines
607 B
Ruby

namespace :debshots do
desc "Convert images from Paperclip (deprecated) to Shrine"
task paperclip_to_shrine: :environment do
Screenshot.find_each do |screenshot|
puts "Screenshot… #{screenshot.id}"
path = screenshot.image.path
puts "Image path… #{path}"
# Skip run if there is a Shrine attachment already (idempotency)
next if screenshot.simage
# Upload file as Shrine
screenshot.simage = File.open(path)
puts "Creating derivatives…"
screenshot.simage_derivatives!
screenshot.save!
puts "------------"
end
end
end