From 59841e884cffc6d78a16426e7b1a15600f21ca4d Mon Sep 17 00:00:00 2001 From: Brian Palmer Date: Fri, 19 Apr 2013 15:42:12 -0600 Subject: [PATCH] migration fixups make this data fix postdeploy, and avoid find_in_batches issues also remove :concurrently from a index created transactionally (on a new table) Change-Id: If9744e13b2387eb1a310f19629fff6327000add5 Reviewed-on: https://gerrit.instructure.com/19834 Reviewed-by: Cody Cutrer Reviewed-by: Bracken Mosbacker Reviewed-by: James Williams Tested-by: Jenkins Product-Review: Brian Palmer QA-Review: Brian Palmer --- ...215164701_add_manage_rubrics_permission.rb | 2 +- .../20130313141722_create_migration_issues.rb | 2 +- lib/data_fixup/copy_role_overrides.rb | 28 ++++++++++--------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/db/migrate/20130215164701_add_manage_rubrics_permission.rb b/db/migrate/20130215164701_add_manage_rubrics_permission.rb index 751b41f5e47..ae9c844a66a 100644 --- a/db/migrate/20130215164701_add_manage_rubrics_permission.rb +++ b/db/migrate/20130215164701_add_manage_rubrics_permission.rb @@ -1,5 +1,5 @@ class AddManageRubricsPermission < ActiveRecord::Migration - tag :predeploy + tag :postdeploy def self.up DataFixup::CopyRoleOverrides.send_later_if_production_enqueue_args(:run, diff --git a/db/migrate/20130313141722_create_migration_issues.rb b/db/migrate/20130313141722_create_migration_issues.rb index c86e8d2a744..4b7db162b55 100644 --- a/db/migrate/20130313141722_create_migration_issues.rb +++ b/db/migrate/20130313141722_create_migration_issues.rb @@ -14,7 +14,7 @@ class CreateMigrationIssues < ActiveRecord::Migration t.timestamps end - add_index :migration_issues, :content_migration_id, :concurrently => true + add_index :migration_issues, :content_migration_id end def self.down diff --git a/lib/data_fixup/copy_role_overrides.rb b/lib/data_fixup/copy_role_overrides.rb index b325511c764..f38a58d046e 100644 --- a/lib/data_fixup/copy_role_overrides.rb +++ b/lib/data_fixup/copy_role_overrides.rb @@ -1,22 +1,24 @@ module DataFixup::CopyRoleOverrides def self.run(old_permission, new_permission) RoleOverride.where(:permission => old_permission.to_s).find_in_batches do |old_role_overrides| - possible_new_role_overrides = RoleOverride.find(:all, :conditions => - {:permission => new_permission.to_s, :context_id => old_role_overrides.map(&:context_id)} ) + RoleOverride.send(:with_exclusive_scope) do + possible_new_role_overrides = RoleOverride.find(:all, :conditions => + {:permission => new_permission.to_s, :context_id => old_role_overrides.map(&:context_id)} ) - old_role_overrides.each do |old_role_override| - unless old_role_override.invalid? || possible_new_role_overrides.detect{|ro| - ro.context_id == old_role_override.context_id && - ro.context_type == old_role_override.context_type && - ro.enrollment_type == old_role_override.enrollment_type - } + old_role_overrides.each do |old_role_override| + unless old_role_override.invalid? || possible_new_role_overrides.detect{|ro| + ro.context_id == old_role_override.context_id && + ro.context_type == old_role_override.context_type && + ro.enrollment_type == old_role_override.enrollment_type + } - dup = RoleOverride.new - old_role_override.attributes.delete_if{|k,v| [:id, :permission, :created_at, :updated_at].include?(k.to_sym)}.each do |key, val| - dup.send("#{key}=", val) + dup = RoleOverride.new + old_role_override.attributes.delete_if{|k,v| [:id, :permission, :created_at, :updated_at].include?(k.to_sym)}.each do |key, val| + dup.send("#{key}=", val) + end + dup.permission = new_permission.to_s + dup.save! end - dup.permission = new_permission.to_s - dup.save! end end end