From 1f0409495641ed629239e2182ce7a8ebeadec099 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer <raphael@joindiaspora.com> Date: Wed, 1 Jun 2011 10:49:05 -0700 Subject: [PATCH] Make sure migration up and down deal with all indicies --- ...2_photo_status_message_association_on_guid.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/db/migrate/20110527135552_photo_status_message_association_on_guid.rb b/db/migrate/20110527135552_photo_status_message_association_on_guid.rb index 81ae491c8b..19f7105e32 100644 --- a/db/migrate/20110527135552_photo_status_message_association_on_guid.rb +++ b/db/migrate/20110527135552_photo_status_message_association_on_guid.rb @@ -3,10 +3,10 @@ class PhotoStatusMessageAssociationOnGuid < ActiveRecord::Migration attr_accessible :id, :guid, :status_message_id, :status_message_guid self.inheritance_column = :_type_disabled end - + def self.up add_column :posts, :status_message_guid, :string - + ActiveRecord::Base.record_timestamps = false photos = Post.where(Post.arel_table[:status_message_id].not_eq(nil).and(Post.arel_table[:type].eq('Photo'))) photos.each do |photo| @@ -15,17 +15,18 @@ class PhotoStatusMessageAssociationOnGuid < ActiveRecord::Migration photo.update_attributes(:status_message_guid => status_message.guid) end end - + + remove_index :posts, [:status_message_id] remove_index :posts, [:status_message_id, :pending] add_index :posts, :status_message_guid add_index :posts, [:status_message_guid, :pending] - + remove_column :posts, :status_message_id end def self.down add_column :posts, :status_message_id, :integer - + ActiveRecord::Base.record_timestamps = false photos = Post.where(Post.arel_table[:status_message_guid].not_eq(nil).and(Post.arel_table[:type].eq('Photo'))) photos.each do |photo| @@ -34,11 +35,12 @@ class PhotoStatusMessageAssociationOnGuid < ActiveRecord::Migration photo.update_attributes(:status_message_id => status_message.id) end end - + remove_index :posts, [:status_message_guid, :pending] + remove_index :posts, :status_message_guid add_index :posts, :status_message_id add_index :posts, [:status_message_id, :pending] - + remove_column :posts, :status_message_guid end end -- GitLab