FIX: Destroy optimized images in `upload:migrate_to_s3` rake task.

FIX: Destroy optimized images in upload:migrate_to_s3 rake task.

OptimizedImage are currently not renegerated when the image changes store.

diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake
index f5f1455..12d16ff 100644
--- a/lib/tasks/uploads.rake
+++ b/lib/tasks/uploads.rake
@@ -378,6 +378,11 @@ def migrate_to_s3
     else
       DbHelper.remap(from, to)
     end
+
+    OptimizedImage
+      .joins("LEFT JOIN uploads u ON optimized_images.upload_id = u.id")
+      .where("u.id IS NOT NULL AND u.url LIKE '//%' AND optimized_images.url NOT LIKE '//%'")
+      .destroy_all
   end
 
   puts "Done!"

GitHub sha: 4e594f2b

2 Likes