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 <cody@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
Reviewed-by: James Williams  <jamesw@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Product-Review: Brian Palmer <brianp@instructure.com>
QA-Review: Brian Palmer <brianp@instructure.com>
This commit is contained in:
Brian Palmer 2013-04-19 15:42:12 -06:00
parent ff85faf46a
commit 59841e884c
3 changed files with 17 additions and 15 deletions

View File

@ -1,5 +1,5 @@
class AddManageRubricsPermission < ActiveRecord::Migration class AddManageRubricsPermission < ActiveRecord::Migration
tag :predeploy tag :postdeploy
def self.up def self.up
DataFixup::CopyRoleOverrides.send_later_if_production_enqueue_args(:run, DataFixup::CopyRoleOverrides.send_later_if_production_enqueue_args(:run,

View File

@ -14,7 +14,7 @@ class CreateMigrationIssues < ActiveRecord::Migration
t.timestamps t.timestamps
end end
add_index :migration_issues, :content_migration_id, :concurrently => true add_index :migration_issues, :content_migration_id
end end
def self.down def self.down

View File

@ -1,22 +1,24 @@
module DataFixup::CopyRoleOverrides module DataFixup::CopyRoleOverrides
def self.run(old_permission, new_permission) def self.run(old_permission, new_permission)
RoleOverride.where(:permission => old_permission.to_s).find_in_batches do |old_role_overrides| RoleOverride.where(:permission => old_permission.to_s).find_in_batches do |old_role_overrides|
possible_new_role_overrides = RoleOverride.find(:all, :conditions => RoleOverride.send(:with_exclusive_scope) do
{:permission => new_permission.to_s, :context_id => old_role_overrides.map(&:context_id)} ) 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| old_role_overrides.each do |old_role_override|
unless old_role_override.invalid? || possible_new_role_overrides.detect{|ro| unless old_role_override.invalid? || possible_new_role_overrides.detect{|ro|
ro.context_id == old_role_override.context_id && ro.context_id == old_role_override.context_id &&
ro.context_type == old_role_override.context_type && ro.context_type == old_role_override.context_type &&
ro.enrollment_type == old_role_override.enrollment_type ro.enrollment_type == old_role_override.enrollment_type
} }
dup = RoleOverride.new 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| 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.send("#{key}=", val)
end
dup.permission = new_permission.to_s
dup.save!
end end
dup.permission = new_permission.to_s
dup.save!
end end
end end
end end