Set up replica identity index for RoleOverride

refs FOO-1171
flag=none

test plan:
 - migration works up and down
 - tests pass

Change-Id: I944d86adc191e5cb18a2129546e1661ae6197b78
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/260529
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
QA-Review: Michael Ziwisky <mziwisky@instructure.com>
Product-Review: Michael Ziwisky <mziwisky@instructure.com>
This commit is contained in:
Michael Ziwisky 2021-03-11 22:25:12 -08:00
parent 1fecc61f68
commit 824502bb03
3 changed files with 44 additions and 9 deletions

View File

@ -0,0 +1,33 @@
# frozen_string_literal: true
#
# Copyright (C) 2021 - present 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/>.
class AddReplicaIdentityForRoleOverrides < ActiveRecord::Migration[6.0]
tag :postdeploy
disable_ddl_transaction!
def up
add_replica_identity 'RoleOverride', :root_account_id, 0
remove_index :role_overrides, column: :root_account_id, if_exists: true
end
def down
add_index :role_overrides, :root_account_id, algorithm: :concurrently, if_not_exists: true
remove_replica_identity 'RoleOverride'
change_column_null :role_overrides, :root_account_id, true
end
end

View File

@ -28,6 +28,11 @@ module DataFixup
all_select_final_grade_overrides = RoleOverride.where(permission: 'select_final_grade')
all_ta_and_related_roles = Role.where(base_role_type: 'TaEnrollment')
site_admin = Account.site_admin
# this fixup gets run from a migration that takes place before the
# root_account_id column is added to the table. it also gets run from
# its own specs which execute after said column is added. so both
# versions of the table need to be accommodated.
add_root_account_id = RoleOverride.column_names.include?('root_account_id')
# The case where moderate_grades RoleOverrides exist for non-ta roles.
all_moderate_grades_overrides.where(enabled: false).find_in_batches do |moderate_overrides|
@ -47,7 +52,9 @@ module DataFixup
enabled: moderate_override.enabled,
locked: moderate_override.locked,
role_id: moderate_override.role_id
}
}.tap do |override|
override.merge!(root_account_id: moderate_override.root_account_id) if add_root_account_id
end
end
RoleOverride.bulk_insert(new_role_overrides)
@ -81,7 +88,9 @@ module DataFixup
enabled: false,
locked: false,
role_id: ta_role.id
}
}.tap do |override|
override.merge!(root_account_id: account.resolved_root_account_id) if add_root_account_id
end
end
end
RoleOverride.bulk_insert(new_role_overrides)

View File

@ -655,13 +655,6 @@ describe DataFixup::PopulateRootAccountIdOnModels do
end
end
context 'with RoleOverride' do
it_behaves_like 'a datafixup that populates root_account_id' do
let(:record) { RoleOverride.create!(account: reference_record, role: Role.first) }
let(:reference_record) { account_model }
end
end
context 'with Score' do
it_behaves_like 'a datafixup that populates root_account_id' do
let(:record) { reference_record.scores.create! }