Commit 4a0e0a9d

mo khan <mo@mokhan.ca>
2014-09-22 03:01:58
change migration to a script.
1 parent c4d58e1
db/migrate/20140921024709_migrate_avatars_to_photos.rb
@@ -1,19 +0,0 @@
-class MigrateAvatarsToPhotos < ActiveRecord::Migration
-  def change
-    BlobStorage.new.tap do |blob_storage|
-      Avatar.includes(:user).where('avatar IS NOT NULL').find_each do |avatar|
-        begin
-          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
-        rescue StandardError => error
-          say error.message
-        end
-      end
-    end
-  end
-end
db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20140921024709) do
+ActiveRecord::Schema.define(version: 20140920033516) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
script/deploy-production.sh
@@ -1,2 +1,2 @@
 #!/bin/bash -x
-bundle exec cap production deploy:migrations
+bundle exec cap production deploy
script/deploy-staging.sh
@@ -1,2 +0,0 @@
-#!/bin/bash -x
-bundle exec cap staging deploy:migrations
script/migrate-avatars.rb
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
+
+BlobStorage.new.tap do |blob_storage|
+  Avatar.includes(:user).where('avatar IS NOT NULL').find_each do |avatar|
+    begin
+      key = avatar.avatar.path
+      blob_storage.download(key) do |file|
+        puts file.path
+        UploadAvatar.new.run(avatar.user, { photo: { image: file.path } })
+      end
+    rescue StandardError => error
+      puts error.message
+    end
+  end
+end