made migration more failure tolerant

This commit is contained in:
MrZYX 2011-05-27 19:26:47 +02:00
parent e201340bb2
commit f5488bd032

View file

@ -9,8 +9,10 @@ class PhotoStatusMessageAssociationOnGuid < ActiveRecord::Migration
photos = Post.where(Post.arel_table[:status_message_id].not_eq(nil).and(Post.arel_table[:type].eq('Photo'))) photos = Post.where(Post.arel_table[:status_message_id].not_eq(nil).and(Post.arel_table[:type].eq('Photo')))
photos.each do |photo| photos.each do |photo|
status_message = Post.find(photo.status_message_id) if Post.where(:id => photo.status_message_id).exists?
photo.update_attributes(:status_message_guid => status_message.guid) status_message = Post.find(photo.status_message_id)
photo.update_attributes(:status_message_guid => status_message.guid)
end
end end
remove_index :posts, [:status_message_id, :pending] remove_index :posts, [:status_message_id, :pending]
@ -25,8 +27,10 @@ class PhotoStatusMessageAssociationOnGuid < ActiveRecord::Migration
photos = Post.where(Post.arel_table[:status_message_guid].not_eq(nil).and(Post.arel_table[:type].eq('Photo'))) photos = Post.where(Post.arel_table[:status_message_guid].not_eq(nil).and(Post.arel_table[:type].eq('Photo')))
photos.each do |photo| photos.each do |photo|
status_message = Post.where(:guid => photo.status_message_guid).first if Post.where(:guid => photo.status_message_guid).exists?
photo.update_attributes(:status_message_id => status_message.id) status_message = Post.where(:guid => photo.status_message_guid).first
photo.update_attributes(:status_message_id => status_message.id)
end
end end
remove_index :posts, [:status_message_guid, :pending] remove_index :posts, [:status_message_guid, :pending]