fix migration error

test plan:
* run migration, it should pass
* run migration spec, it should pass

Change-Id: I024c7b07671212eb42943273d5c361cce516e015
Reviewed-on: https://gerrit.instructure.com/8961
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Pendleton <zachp@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
Reviewed-by: Zach Wily <zach@instructure.com>
This commit is contained in:
Jon Jensen 2012-02-23 13:12:31 -07:00
parent d253888f19
commit 57d3a8238f
2 changed files with 48 additions and 10 deletions

View File

@ -1,9 +1,6 @@
class FixUserMergeConversations < ActiveRecord::Migration
def self.up
if supports_ddl_transactions?
commit_db_transaction
decrement_open_transactions while open_transactions > 0
end
self.transactional = false
# remove any duplicate CP's, possibly fixing private conversation hashes
# (which may merge it with another conversation)
@ -22,7 +19,7 @@ class FixUserMergeConversations < ActiveRecord::Migration
SQL
each do |cp|
cp.destroy
cp.conversation.renegerate_private_hash! if cp.private?
cp.conversation.regenerate_private_hash! if cp.private?
end
# there may be a bunch more private conversations with the wrong private
@ -38,11 +35,6 @@ class FixUserMergeConversations < ActiveRecord::Migration
:strand => "regenerate_conversation_private_hashes"
}, ids)
end
if supports_ddl_transactions?
increment_open_transactions
begin_db_transaction
end
end
def self.down

View File

@ -0,0 +1,46 @@
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
require 'db/migrate/20120216163427_fix_user_merge_conversations.rb'
describe FixUserMergeConversations do
describe "up" do
it "should work" do
u1 = user
u2 = user
u3 = user
c1 = Conversation.initiate([u1.id, u2.id], true)
c1.participants << u1
c1.update_attribute(:private_hash, 'no longer valid')
c1.conversation_participants.size.should eql 3
c2 = Conversation.initiate([u1.id, u3.id], true)
c2.update_attribute(:private_hash, 'well this is clearly wrong')
c3 = Conversation.initiate([u1.id, u3.id], true)
FixUserMergeConversations.up
c1.reload.conversation_participants.size.should eql 2
c1.private_hash.should_not eql 'no longer valid'
lambda { c2.reload }.should raise_error
end
end
end