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:
parent
ff85faf46a
commit
59841e884c
|
@ -1,5 +1,5 @@
|
|||
class AddManageRubricsPermission < ActiveRecord::Migration
|
||||
tag :predeploy
|
||||
tag :postdeploy
|
||||
|
||||
def self.up
|
||||
DataFixup::CopyRoleOverrides.send_later_if_production_enqueue_args(:run,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue