From f5488bd032dc2aa47fea6a97c45a01871347411d Mon Sep 17 00:00:00 2001 From: MrZYX Date: Fri, 27 May 2011 19:26:47 +0200 Subject: [PATCH] made migration more failure tolerant --- ...35552_photo_status_message_association_on_guid.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 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 d6c16c3ee..d5b442588 100644 --- a/db/migrate/20110527135552_photo_status_message_association_on_guid.rb +++ b/db/migrate/20110527135552_photo_status_message_association_on_guid.rb @@ -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.each do |photo| - status_message = Post.find(photo.status_message_id) - photo.update_attributes(:status_message_guid => status_message.guid) + if Post.where(:id => photo.status_message_id).exists? + status_message = Post.find(photo.status_message_id) + photo.update_attributes(:status_message_guid => status_message.guid) + end end 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.each do |photo| - status_message = Post.where(:guid => photo.status_message_guid).first - photo.update_attributes(:status_message_id => status_message.id) + if Post.where(:guid => photo.status_message_guid).exists? + status_message = Post.where(:guid => photo.status_message_guid).first + photo.update_attributes(:status_message_id => status_message.id) + end end remove_index :posts, [:status_message_guid, :pending]