Make sure migration up and down deal with all indicies
This commit is contained in:
parent
68399be639
commit
1f04094956
1 changed files with 9 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue