Set up replica identity index for context external tools
closes INTEROP-6237 flag=none Test plan - Verify that the replica identity index has been created - Verify the replica identity for context_external_tools has been set to index (SELECT relname, relreplident FROM pg_class WHERE relname = 'context_external_tools';) Change-Id: Ic9540381a82a1f10b8f930f40bf90b1fdf370aa9 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/252622 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Wagner Goncalves <wagner.goncalves@instructure.com> QA-Review: Wagner Goncalves <wagner.goncalves@instructure.com> Product-Review: Mysti Lilla <mysti@instructure.com>
This commit is contained in:
parent
982f3cb21d
commit
3812d21600
|
@ -1537,7 +1537,7 @@ ActiveRecord::ConnectionAdapters::SchemaStatements.class_eval do
|
|||
fk_name_to_delete = foreign_key_for(from_table, **options)&.name
|
||||
return if fk_name_to_delete.nil?
|
||||
else
|
||||
fk_name_to_delete = foreign_key_for!(from_table, **options).name
|
||||
fk_name_to_delete = foreign_key_for!(from_table, **options).name
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1546,6 +1546,22 @@ ActiveRecord::ConnectionAdapters::SchemaStatements.class_eval do
|
|||
|
||||
execute schema_creation.accept(at)
|
||||
end
|
||||
|
||||
def add_replica_identity(table_string, column_name, default_value)
|
||||
klass = table_string.constantize
|
||||
DataFixup::BackfillNulls.run(klass, column_name, default_value: default_value)
|
||||
change_column_null klass.table_name, column_name, false
|
||||
primary_column = klass.primary_key
|
||||
index_name = "index_#{klass.table_name}_replica_identity"
|
||||
add_index klass.table_name, [column_name, primary_column], name: index_name, algorithm: :concurrently, unique: true, if_not_exists: true
|
||||
execute(%[ALTER TABLE #{klass.quoted_table_name} REPLICA IDENTITY USING INDEX #{index_name}])
|
||||
end
|
||||
|
||||
def remove_replica_identity(table_string)
|
||||
klass = table_string.constantize
|
||||
execute(%[ALTER TABLE #{klass.quoted_table_name} REPLICA IDENTITY DEFAULT])
|
||||
remove_index klass.table_name, name: "index_#{klass.table_name}_replica_identity", if_exists: true
|
||||
end
|
||||
end
|
||||
|
||||
ActiveRecord::Associations::CollectionAssociation.class_eval do
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2020 - 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 AddReplicaIdentityForContextExternalTools < ActiveRecord::Migration[5.2]
|
||||
tag :postdeploy
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
add_replica_identity 'ContextExternalTool', :root_account_id, 0
|
||||
remove_index :context_external_tools, name: 'index_context_external_tools_on_root_account_id', if_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
add_index :context_external_tools, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
remove_replica_identity 'ContextExternalTool'
|
||||
change_column_null :context_external_tools, :root_account_id, true
|
||||
end
|
||||
end
|
|
@ -384,20 +384,6 @@ describe DataFixup::PopulateRootAccountIdOnModels do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with ContextExternalTool' do
|
||||
it_behaves_like 'a datafixup that populates root_account_id' do
|
||||
let(:record) { external_tool_model(context: @course) }
|
||||
let(:reference_record) { @course }
|
||||
end
|
||||
|
||||
context 'when the tool context is a root account' do
|
||||
it_behaves_like 'a datafixup that populates root_account_id' do
|
||||
let(:record) { external_tool_model(context: @course.root_account) }
|
||||
let(:reference_record) { @course }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with ContentMigration' do
|
||||
it 'should populate the root_account_id' do
|
||||
cm = @course.content_migrations.create!(user: @user)
|
||||
|
|
Loading…
Reference in New Issue