Commit fd55ae1b

mo k <mo@mokhan.ca>
2012-10-09 13:35:45
split the migration script
1 parent d0b8d78
db/migrate/20121007153154_recreate_photos.rb
@@ -0,0 +1,11 @@
+class MigrateImagesToPhotos < ActiveRecord::Migration
+  def up
+    Photo.all.each do |photo|
+      puts "recreating versions for #{photo.id}"
+      photo.image.recreate_versions!
+    end
+  end
+
+  def down
+  end
+end
db/migrate/20121007153155_migrate_images_to_photos.rb
@@ -1,12 +1,6 @@
 class MigrateImagesToPhotos < ActiveRecord::Migration
   def up
     add_column :photos, :is_primary, :boolean
-    add_index  :photos, :is_primary
-
-    Photo.all.each do |photo|
-      photo.image.recreate_versions!
-    end
-
     Creation.all.each_with_index do |creation, index|
       puts "#{index}. processing #{creation.name}"
       photo = creation.photos.build({:is_primary => true})
@@ -16,6 +10,7 @@ class MigrateImagesToPhotos < ActiveRecord::Migration
       photo.save!
       puts "#{index}. migrated #{creation.image.url} to #{photo.attributes}"
     end
+    #add_index  :photos, :is_primary
     #remove_column :creations, :image
   end
 
@@ -23,7 +18,7 @@ class MigrateImagesToPhotos < ActiveRecord::Migration
     Photo.where(:is_primary => true).each do |photo|
       photo.destroy
     end
-    remove_index  :photos, :is_primary
+    #remove_index  :photos, :is_primary
     remove_column :photos, :is_primary
   end
 end