Commit 56274741

mo khan <mo@mokhan.ca>
2014-09-21 04:11:41
start to build migration to migrate avatars to photos.
1 parent 0e26bca
db/migrate/20140921024709_migrate_avatars_to_photos.rb
@@ -0,0 +1,14 @@
+class MigrateAvatarsToPhotos < ActiveRecord::Migration
+  def change
+    blob_storage = BlogStorage.new
+    Avatar.includes(:user).find_each do |avatar|
+      user = avatar.user
+      key = avatar.avatar.path
+      blob_storage.download(key) do |file|
+        user.avatar = Photo.create!
+        user.avatar.upload(file.path, blob_storage)
+        user.avatar.save!
+      end
+    end
+  end
+end