migrations: remove accidental extra excessive update triggers

Change-Id: If1bba729e0ccd8939f99a0ad416daf5e80b8b5a6
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/342856
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Jacob Burroughs <jburroughs@instructure.com>
Migration-Review: Jacob Burroughs <jburroughs@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2024-03-13 09:39:16 -06:00
parent bf78738798
commit 48cfe93459
2 changed files with 38 additions and 1 deletions

View File

@ -280,7 +280,7 @@ module PostgreSQLAdapterExtensions
def add_guard_excessive_updates(table_name)
# Don't try to install this on rails-internal tables; they need to be created for
# internal_metadata to exist and this guard isn't really useful there either
return if ["schema_migrations", "internal_metadata"].include?(table_name)
return if [ActiveRecord::Base.internal_metadata_table_name, ActiveRecord::Base.schema_migrations_table_name].include?(table_name)
# If the function doesn't exist yet it will be backfilled
return unless ((Rails.version < "7.1") ? ::ActiveRecord::InternalMetadata : ::ActiveRecord::InternalMetadata.new(self))[:guard_dangerous_changes_installed]

View File

@ -0,0 +1,37 @@
# frozen_string_literal: true
#
# Copyright (C) 2024 - 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 RemoveGuardTriggersFromInternalMetadataTables < ActiveRecord::Migration[7.0]
tag :postdeploy
def up
# these triggers may have been accidentally added due to using constant
# table names instead of `ActiveRecord::Base.internal_metadata_table_name`
operations = ["UPDATE", "DELETE"]
[ActiveRecord::Base.internal_metadata_table_name,
ActiveRecord::Base.schema_migrations_table_name].each do |t|
operations.each do |operation|
trigger_name = "guard_excessive_#{operation.downcase}s"
execute("DROP TRIGGER IF EXISTS #{trigger_name} ON #{connection.quote_table_name(t)}")
end
end
end
end