Remove rails 6.0 support
Change-Id: I0df8f625c119b2622e358a5d663c158e2d7d7cb8 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/292904 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Alex Slaughter <aslaughter@instructure.com> QA-Review: Jacob Burroughs <jburroughs@instructure.com> Product-Review: Jacob Burroughs <jburroughs@instructure.com>
This commit is contained in:
parent
bb95a22093
commit
c7bf5fba48
|
@ -27,19 +27,11 @@ def gem_override(name, version)
|
|||
end
|
||||
end
|
||||
|
||||
if CANVAS_RAILS == "6.0"
|
||||
gem "rails", "6.0.4.7"
|
||||
gem "tzinfo", "1.2.7"
|
||||
gem_override "switchman", "2.2.3"
|
||||
gem "guardrail", "2.0.1"
|
||||
gem_override "switchman-inst-jobs", "3.2.10"
|
||||
else
|
||||
gem "rails", "6.1.4.6"
|
||||
gem "tzinfo", "2.0.4"
|
||||
gem_override "switchman", "3.0.24"
|
||||
gem "guardrail", "3.0.2"
|
||||
gem_override "switchman-inst-jobs", "4.0.6"
|
||||
end
|
||||
gem "rails", "6.1.4.6"
|
||||
gem "tzinfo", "2.0.4"
|
||||
gem_override "switchman", "3.0.24"
|
||||
gem "guardrail", "3.0.2"
|
||||
gem_override "switchman-inst-jobs", "4.0.6"
|
||||
gem "irb", "1.4.1"
|
||||
gem "open4", "1.3.4", require: false
|
||||
|
||||
|
|
|
@ -57,11 +57,7 @@ group :test do
|
|||
gem "pact-support", "1.16.8", require: false
|
||||
gem "pact-messages", "0.2.0"
|
||||
gem "pact_broker-client", "1.40.0"
|
||||
if CANVAS_RAILS == "6.0"
|
||||
gem "database_cleaner", "~> 1.5", ">= 1.5.3"
|
||||
else
|
||||
gem "database_cleaner", "~> 2.0"
|
||||
end
|
||||
gem "database_cleaner", "~> 2.0"
|
||||
gem "json-schema", "~> 2.8.1"
|
||||
|
||||
gem "parallel_tests"
|
||||
|
|
|
@ -46,11 +46,7 @@ module Auditors::ActiveRecord
|
|||
log "*" * 80
|
||||
end
|
||||
unless Rails.env.test?
|
||||
if Rails.version < "6.1"
|
||||
ActiveRecord::Base.connection_pool.current_pool.disconnect!
|
||||
else
|
||||
ActiveRecord::Base.connection_pool.disconnect!
|
||||
end
|
||||
ActiveRecord::Base.connection_pool.disconnect!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,11 +23,7 @@ module Messages
|
|||
log "Done. Bye!"
|
||||
log "*" * 80
|
||||
unless Rails.env.test?
|
||||
if Rails.version < "6.1"
|
||||
ActiveRecord::Base.connection_pool.current_pool.disconnect!
|
||||
else
|
||||
ActiveRecord::Base.connection_pool.disconnect!
|
||||
end
|
||||
ActiveRecord::Base.connection_pool.disconnect!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,11 +39,7 @@ class Quizzes::QuizSubmissionEventPartitioner
|
|||
log "Done. Bye!"
|
||||
log "*" * 80
|
||||
unless in_migration || Rails.env.test?
|
||||
if Rails.version < "6.1"
|
||||
ActiveRecord::Base.connection_pool.current_pool.disconnect!
|
||||
else
|
||||
ActiveRecord::Base.connection_pool.disconnect!
|
||||
end
|
||||
ActiveRecord::Base.connection_pool.current_pool.disconnect!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,11 +37,7 @@ class SimplyVersioned::Partitioner
|
|||
log "Done. Bye!"
|
||||
log "*" * 80
|
||||
unless Rails.env.test?
|
||||
if Rails.version < "6.1"
|
||||
ActiveRecord::Base.connection_pool.current_pool.disconnect!
|
||||
else
|
||||
ActiveRecord::Base.connection_pool.disconnect!
|
||||
end
|
||||
ActiveRecord::Base.connection_pool.disconnect!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -400,11 +400,7 @@ class StreamItem < ActiveRecord::Base
|
|||
StreamItem.vacuum
|
||||
StreamItemInstance.vacuum
|
||||
unless Rails.env.test?
|
||||
if Rails.version < "6.1"
|
||||
ActiveRecord::Base.connection_pool.current_pool.disconnect!
|
||||
else
|
||||
ActiveRecord::Base.connection_pool.disconnect!
|
||||
end
|
||||
ActiveRecord::Base.connection_pool.disconnect!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
# 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/>.
|
||||
#
|
||||
|
||||
# TODO: CANVAS_RAILS="6.0" remove this whole class since we will always get it from switchman
|
||||
class UnshardedRecord < ::ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
|
||||
# This line is conditional just so if it is eager-loaded nothing breaks
|
||||
self.shard_category = :unsharded if Rails.version < "6.1"
|
||||
end
|
|
@ -129,12 +129,6 @@ module CanvasRails
|
|||
require_dependency "canvas/plugins/default_plugins"
|
||||
Canvas::Plugins::DefaultPlugins.apply_all
|
||||
ActiveSupport::JSON::Encoding.escape_html_entities_in_json = true
|
||||
|
||||
if Rails.version < "6.1"
|
||||
# On rails 6.1, this comes from switchman; on rails 6.0 canvas provides it
|
||||
require_relative "#{__dir__}/../app/models/unsharded_record.rb"
|
||||
Switchman::UnshardedRecord = UnshardedRecord
|
||||
end
|
||||
end
|
||||
|
||||
module PostgreSQLEarlyExtensions
|
||||
|
@ -210,19 +204,25 @@ module CanvasRails
|
|||
|
||||
module RailsCacheShim
|
||||
def delete(key, options = nil)
|
||||
r1 = super(key, (options || {}).merge(use_new_rails: Rails.version >= "6.1")) # prefer rails new if on old rails and vice versa
|
||||
r2 = super(key, (options || {}).merge(use_new_rails: Rails.version < "6.1"))
|
||||
r1 || r2
|
||||
if options&.[](:unprefixed_key)
|
||||
super
|
||||
else
|
||||
SUPPORTED_VERSIONS.any? do |version|
|
||||
super(key, (options || {}).merge(explicit_version: version.delete(".")))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def normalize_key(key, options)
|
||||
result = super
|
||||
if options&.key?(:use_new_rails) ? options[:use_new_rails] : Rails.version >= "6.1"
|
||||
result = "rails61:#{result}"
|
||||
if options[:unprefixed_key]
|
||||
super
|
||||
elsif options[:explicit_version]
|
||||
"rails#{options[:explicit_version]}:#{super}"
|
||||
else
|
||||
"rails#{Rails::VERSION::MAJOR}#{Rails::VERSION::MINOR}:#{super}"
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
# 3. Create a Consul setting private/canvas/rails_version with <supported version> as the contents
|
||||
|
||||
DEFAULT_VERSION = "6.1"
|
||||
SUPPORTED_VERSIONS = %w[6.0 6.1].freeze
|
||||
SUPPORTED_VERSIONS = %w[6.1].freeze
|
||||
|
||||
unless defined?(CANVAS_RAILS)
|
||||
file_path = File.expand_path("RAILS_VERSION", __dir__)
|
||||
|
|
|
@ -17,15 +17,13 @@
|
|||
# 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/>.
|
||||
|
||||
if Rails.version >= "6.1"
|
||||
module NoLinksHeader
|
||||
# Max header size needs a default, since it's a noop it doesn't matter what
|
||||
def send_preload_links_header(preload_links, max_header_size: 0)
|
||||
# Intentional noop so we don't bload the headers to be too big
|
||||
end
|
||||
module NoLinksHeader
|
||||
# Max header size needs a default, since it's a noop it doesn't matter what
|
||||
def send_preload_links_header(preload_links, max_header_size: 0)
|
||||
# Intentional noop so we don't bload the headers to be too big
|
||||
end
|
||||
|
||||
# Directly put it in ActionView::Base in case that has already been loaded
|
||||
ActionView::Helpers::AssetTagHelper.prepend(NoLinksHeader)
|
||||
ActionView::Base.prepend(NoLinksHeader)
|
||||
end
|
||||
|
||||
# Directly put it in ActionView::Base in case that has already been loaded
|
||||
ActionView::Helpers::AssetTagHelper.prepend(NoLinksHeader)
|
||||
ActionView::Base.prepend(NoLinksHeader)
|
||||
|
|
|
@ -620,7 +620,7 @@ class ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.current_xlog_location
|
||||
Shard.current(send(Rails.version < "6.1" ? :shard_category : :connection_classes)).database_server.unguard do
|
||||
Shard.current(connection_classes).database_server.unguard do
|
||||
GuardRail.activate(:primary) do
|
||||
if Rails.env.test? ? in_transaction_in_test? : connection.open_transactions > 0
|
||||
raise "don't run current_xlog_location in a transaction"
|
||||
|
@ -754,16 +754,14 @@ class ActiveRecord::Base
|
|||
changes_applied
|
||||
end
|
||||
|
||||
if Rails.version >= "6.1"
|
||||
def self.override_db_configs(override)
|
||||
configurations.configs_for.each do |config|
|
||||
config.instance_variable_set(:@configuration_hash, config.configuration_hash.merge(override).freeze)
|
||||
end
|
||||
clear_all_connections!(nil)
|
||||
|
||||
# Just return something that isn't an ar connection object so consoles don't explode
|
||||
override
|
||||
def self.override_db_configs(override)
|
||||
configurations.configs_for.each do |config|
|
||||
config.instance_variable_set(:@configuration_hash, config.configuration_hash.merge(override).freeze)
|
||||
end
|
||||
clear_all_connections!(nil)
|
||||
|
||||
# Just return something that isn't an ar connection object so consoles don't explode
|
||||
override
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -777,11 +775,7 @@ module UsefulFindInBatches
|
|||
else
|
||||
enum_for(:find_each, start: start, finish: finish, order: order, **kwargs) do
|
||||
relation = self
|
||||
if Rails.version < "6.1"
|
||||
apply_limits(relation, start, finish).size
|
||||
else
|
||||
apply_limits(relation, start, finish, order).size
|
||||
end
|
||||
apply_limits(relation, start, finish, order).size
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -791,11 +785,7 @@ module UsefulFindInBatches
|
|||
relation = self
|
||||
unless block_given?
|
||||
return to_enum(:find_in_batches, start: start, finish: finish, order: order, batch_size: batch_size, **kwargs) do
|
||||
total = if Rails.version < "6.1"
|
||||
apply_limits(relation, start, finish).size
|
||||
else
|
||||
apply_limits(relation, start, finish, order).size
|
||||
end
|
||||
total = apply_limits(relation, start, finish, order).size
|
||||
(total - 1).div(batch_size) + 1
|
||||
end
|
||||
end
|
||||
|
@ -821,11 +811,7 @@ module UsefulFindInBatches
|
|||
if strategy == :id
|
||||
raise ArgumentError, "GROUP BY is incompatible with :id batches strategy" unless group_values.empty?
|
||||
|
||||
if Rails.version < "6.1"
|
||||
return activate { |r| r.call_super(:in_batches, UsefulFindInBatches, start: start, finish: finish, **kwargs, &block) }
|
||||
else
|
||||
return activate { |r| r.call_super(:in_batches, UsefulFindInBatches, start: start, finish: finish, order: order, **kwargs, &block) }
|
||||
end
|
||||
return activate { |r| r.call_super(:in_batches, UsefulFindInBatches, start: start, finish: finish, order: order, **kwargs, &block) }
|
||||
end
|
||||
|
||||
kwargs.delete(:error_on_ignore)
|
||||
|
@ -870,11 +856,7 @@ module UsefulFindInBatches
|
|||
|
||||
def in_batches_with_cursor(of: 1000, start: nil, finish: nil, order: :asc, load: false)
|
||||
klass.transaction do
|
||||
relation = if Rails.version < "6.1"
|
||||
apply_limits(clone, start, finish)
|
||||
else
|
||||
apply_limits(clone, start, finish, order)
|
||||
end
|
||||
relation = apply_limits(clone, start, finish, order)
|
||||
|
||||
relation.skip_query_cache!
|
||||
unless load
|
||||
|
@ -914,11 +896,7 @@ module UsefulFindInBatches
|
|||
limited_query = limit(0).to_sql
|
||||
|
||||
relation = self
|
||||
relation_for_copy = if Rails.version < "6.1"
|
||||
apply_limits(relation, start, finish)
|
||||
else
|
||||
apply_limits(relation, start, finish, order)
|
||||
end
|
||||
relation_for_copy = apply_limits(relation, start, finish, order)
|
||||
unless load
|
||||
relation_for_copy = relation_for_copy.except(:select).select(primary_key)
|
||||
end
|
||||
|
@ -1012,11 +990,7 @@ module UsefulFindInBatches
|
|||
# and yields the objects in batches in the same order as the scope specified
|
||||
# so the DB connection can be fully recycled during each block.
|
||||
def in_batches_with_pluck_ids(of: 1000, start: nil, finish: nil, order: :asc, load: false)
|
||||
relation = if Rails.version < "6.1"
|
||||
apply_limits(self, start, finish)
|
||||
else
|
||||
apply_limits(self, start, finish, order)
|
||||
end
|
||||
relation = apply_limits(self, start, finish, order)
|
||||
all_object_ids = relation.pluck(:id)
|
||||
current_order_values = order_values
|
||||
all_object_ids.in_groups_of(of) do |id_batch|
|
||||
|
@ -1044,11 +1018,7 @@ module UsefulFindInBatches
|
|||
group, or order)."
|
||||
end
|
||||
|
||||
relation = if Rails.version < "6.1"
|
||||
apply_limits(self, start, finish)
|
||||
else
|
||||
apply_limits(self, start, finish, order)
|
||||
end
|
||||
relation = apply_limits(self, start, finish, order)
|
||||
sql = relation.to_sql
|
||||
table = "#{table_name}_in_batches_temp_table_#{sql.hash.abs.to_s(36)}"
|
||||
table = table[-63..] if table.length > 63
|
||||
|
@ -1189,7 +1159,7 @@ module UsefulBatchEnumerator
|
|||
@relation.send(:_substitute_values, updates).any? do |(attr, update)|
|
||||
found_match = false
|
||||
predicates.any? do |pred|
|
||||
next unless pred.is_a?(Arel::Nodes::Binary) || (Rails.version >= "6.1" && pred.is_a?(Arel::Nodes::HomogeneousIn))
|
||||
next unless pred.is_a?(Arel::Nodes::Binary) || pred.is_a?(Arel::Nodes::HomogeneousIn)
|
||||
next unless pred.left == attr
|
||||
|
||||
found_match = true
|
||||
|
@ -1215,7 +1185,7 @@ module UsefulBatchEnumerator
|
|||
pred.right.exclude?(update)
|
||||
elsif pred.instance_of?(Arel::Nodes::NotIn) && pred.right.is_a?(Array)
|
||||
pred.right.include?(update)
|
||||
elsif Rails.version >= "6.1" && pred.instance_of?(Arel::Nodes::HomogeneousIn)
|
||||
elsif pred.instance_of?(Arel::Nodes::HomogeneousIn)
|
||||
case pred.type
|
||||
when :in
|
||||
pred.right.map(&:value).exclude?(update.value.value)
|
||||
|
@ -1413,13 +1383,8 @@ module UpdateAndDeleteWithJoins
|
|||
end
|
||||
|
||||
def update_all(updates, *args)
|
||||
db = Shard.current(klass.send(Rails.version < "6.1" ? :shard_category : :connection_classes)).database_server
|
||||
if joins_values.empty?
|
||||
if Rails.version < "6.1" && ::GuardRail.environment == db.guard_rail_environment
|
||||
return super
|
||||
else
|
||||
Shard.current.database_server.unguard { return super }
|
||||
end
|
||||
Shard.current.database_server.unguard { return super }
|
||||
end
|
||||
|
||||
stmt = Arel::UpdateManager.new
|
||||
|
@ -1455,11 +1420,7 @@ module UpdateAndDeleteWithJoins
|
|||
end
|
||||
where_sql = collector.value
|
||||
sql.concat("WHERE " + where_sql)
|
||||
if Rails.version < "6.1" && ::GuardRail.environment == db.guard_rail_environment
|
||||
connection.update(sql, "#{name} Update")
|
||||
else
|
||||
Shard.current.database_server.unguard { connection.update(sql, "#{name} Update") }
|
||||
end
|
||||
Shard.current.database_server.unguard { connection.update(sql, "#{name} Update") }
|
||||
end
|
||||
|
||||
def delete_all
|
||||
|
@ -1663,46 +1624,24 @@ module Migrator
|
|||
super.select(&:runnable?)
|
||||
end
|
||||
|
||||
if Rails.version < "6.1"
|
||||
def execute_migration_in_transaction(migration, direct)
|
||||
old_in_migration, ActiveRecord::Base.in_migration = ActiveRecord::Base.in_migration, true
|
||||
if defined?(Marginalia)
|
||||
old_migration_name, Marginalia::Comment.migration = Marginalia::Comment.migration, migration.name
|
||||
end
|
||||
if down? && !Rails.env.test? && !$confirmed_migrate_down
|
||||
require "highline"
|
||||
if HighLine.new.ask("Revert migration #{migration.name} (#{migration.version}) ? [y/N/a] > ") !~ /^([ya])/i
|
||||
raise("Revert not confirmed")
|
||||
end
|
||||
|
||||
$confirmed_migrate_down = true if $1.casecmp?("a")
|
||||
end
|
||||
|
||||
super
|
||||
ensure
|
||||
ActiveRecord::Base.in_migration = old_in_migration
|
||||
Marginalia::Comment.migration = old_migration_name if defined?(Marginalia)
|
||||
def execute_migration_in_transaction(migration)
|
||||
old_in_migration, ActiveRecord::Base.in_migration = ActiveRecord::Base.in_migration, true
|
||||
if defined?(Marginalia)
|
||||
old_migration_name, Marginalia::Comment.migration = Marginalia::Comment.migration, migration.name
|
||||
end
|
||||
else
|
||||
def execute_migration_in_transaction(migration)
|
||||
old_in_migration, ActiveRecord::Base.in_migration = ActiveRecord::Base.in_migration, true
|
||||
if defined?(Marginalia)
|
||||
old_migration_name, Marginalia::Comment.migration = Marginalia::Comment.migration, migration.name
|
||||
end
|
||||
if down? && !Rails.env.test? && !$confirmed_migrate_down
|
||||
require "highline"
|
||||
if HighLine.new.ask("Revert migration #{migration.name} (#{migration.version}) ? [y/N/a] > ") !~ /^([ya])/i
|
||||
raise("Revert not confirmed")
|
||||
end
|
||||
|
||||
$confirmed_migrate_down = true if $1.casecmp?("a")
|
||||
if down? && !Rails.env.test? && !$confirmed_migrate_down
|
||||
require "highline"
|
||||
if HighLine.new.ask("Revert migration #{migration.name} (#{migration.version}) ? [y/N/a] > ") !~ /^([ya])/i
|
||||
raise("Revert not confirmed")
|
||||
end
|
||||
|
||||
super
|
||||
ensure
|
||||
ActiveRecord::Base.in_migration = old_in_migration
|
||||
Marginalia::Comment.migration = old_migration_name if defined?(Marginalia)
|
||||
$confirmed_migrate_down = true if $1.casecmp?("a")
|
||||
end
|
||||
|
||||
super
|
||||
ensure
|
||||
ActiveRecord::Base.in_migration = old_in_migration
|
||||
Marginalia::Comment.migration = old_migration_name if defined?(Marginalia)
|
||||
end
|
||||
end
|
||||
ActiveRecord::Migrator.prepend(Migrator)
|
||||
|
@ -1830,20 +1769,6 @@ ActiveRecord::Associations::CollectionAssociation.class_eval do
|
|||
end
|
||||
end
|
||||
|
||||
if Rails.version < "6.1"
|
||||
module UnscopeCallbacks
|
||||
def run_callbacks(kind)
|
||||
return super if __callbacks[kind].empty?
|
||||
|
||||
# in rails 6.1, we can get rid of this entire monkeypatch
|
||||
scope = self.class.current_scope&.clone || self.class.default_scoped
|
||||
scope = scope.klass.unscoped
|
||||
scope.scoping { super }
|
||||
end
|
||||
end
|
||||
ActiveRecord::Base.include UnscopeCallbacks
|
||||
end
|
||||
|
||||
module MatchWithDiscard
|
||||
def match(model, name)
|
||||
result = super
|
||||
|
@ -2047,7 +1972,7 @@ ActiveRecord::Relation.prepend(DontExplicitlyNameColumnsBecauseOfIgnores)
|
|||
module PreserveShardAfterTransaction
|
||||
def after_transaction_commit(&block)
|
||||
shards = Shard.send(:active_shards)
|
||||
shards[Rails.version < "6.1" ? :delayed_jobs : Delayed::Backend::ActiveRecord::AbstractJob] = Shard.current.delayed_jobs_shard if ::ActiveRecord::Migration.open_migrations.positive?
|
||||
shards[Delayed::Backend::ActiveRecord::AbstractJob] = Shard.current.delayed_jobs_shard if ::ActiveRecord::Migration.open_migrations.positive?
|
||||
super { Shard.activate(shards, &block) }
|
||||
end
|
||||
end
|
||||
|
@ -2095,12 +2020,7 @@ ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(RestoreConnectionConnec
|
|||
|
||||
module MaxRuntimeConnectionPool
|
||||
def max_runtime
|
||||
# TODO: Rails 6.1 uses a PoolConfig object instead
|
||||
if Rails.version < "6.1"
|
||||
@spec.config[:max_runtime]
|
||||
else
|
||||
db_config.configuration_hash[:max_runtime]
|
||||
end
|
||||
db_config.configuration_hash[:max_runtime]
|
||||
end
|
||||
|
||||
def acquire_connection(*)
|
||||
|
|
|
@ -81,7 +81,7 @@ Delayed::Settings.queue = "canvas_queue"
|
|||
Delayed::Settings.select_random_from_batch = -> { Setting.get("jobs_select_random", "false") == "true" }
|
||||
Delayed::Settings.sleep_delay = -> { Setting.get("delayed_jobs_sleep_delay", "2.0").to_f }
|
||||
Delayed::Settings.sleep_delay_stagger = -> { Setting.get("delayed_jobs_sleep_delay_stagger", "2.0").to_f }
|
||||
Delayed::Settings.worker_procname_prefix = -> { "#{Shard.current(Rails.version < "6.1" ? :delayed_jobs : Delayed::Backend::ActiveRecord::AbstractJob).id}~" }
|
||||
Delayed::Settings.worker_procname_prefix = -> { "#{Shard.current(Delayed::Backend::ActiveRecord::AbstractJob).id}~" }
|
||||
Delayed::Settings.worker_health_check_type = Delayed::CLI.instance&.config&.dig("health_check", "type")&.to_sym || :none
|
||||
Delayed::Settings.worker_health_check_config = Delayed::CLI.instance&.config&.[]("health_check")
|
||||
# transitional
|
||||
|
|
|
@ -22,9 +22,7 @@ require "folio/core_ext/enumerable"
|
|||
module Folio::WillPaginate::ActiveRecord::Pagination
|
||||
def paginate(options = {})
|
||||
unless options.key?(:total_entries)
|
||||
scope = if ::Rails.version < "4"
|
||||
scoped
|
||||
elsif is_a?(::ActiveRecord::Relation)
|
||||
scope = if is_a?(::ActiveRecord::Relation)
|
||||
self
|
||||
elsif self < ::ActiveRecord::Base
|
||||
all
|
||||
|
@ -40,13 +38,9 @@ module Folio::WillPaginate::ActiveRecord::Pagination
|
|||
# total_entries left to an auto-count, but the relation being
|
||||
# paginated has a grouping. we need to do a special count, lest
|
||||
# self.count give us a hash instead of the integer we expect.
|
||||
having_clause_empty = Rails.version < "5" ? scope.having_values.empty? : scope.having_clause.empty?
|
||||
having_clause_empty = scope.having_clause.empty?
|
||||
options[:total_entries] = if having_clause_empty && group_values.length == 1 # multi-column distinct counts are broken right now (as of rails 4.2.5) :(
|
||||
if Rails.version < "5"
|
||||
except(:group, :select).select(group_values).uniq.count
|
||||
else
|
||||
except(:group, :select).select(group_values).distinct.count
|
||||
end
|
||||
except(:group, :select).select(group_values).distinct.count
|
||||
else
|
||||
unscoped.from("(#{to_sql}) a").count
|
||||
end
|
||||
|
|
|
@ -21,9 +21,5 @@ if ENV["RAILS_DATABASE_ENVIRONMENT"]
|
|||
GuardRail.activate!(ENV["RAILS_DATABASE_ENVIRONMENT"].to_sym)
|
||||
end
|
||||
if ENV["RAILS_DATABASE_USER"]
|
||||
if Rails.version < "6.1"
|
||||
GuardRail.apply_config!(username: ENV["RAILS_DATABASE_USER"], password: nil)
|
||||
else
|
||||
ActiveRecord::Base.override_db_configs(username: ENV["RAILS_DATABASE_USER"], password: nil)
|
||||
end
|
||||
ActiveRecord::Base.override_db_configs(username: ENV["RAILS_DATABASE_USER"], password: nil)
|
||||
end
|
||||
|
|
|
@ -51,13 +51,6 @@ class PeriodicJobs
|
|||
|
||||
def self.with_each_shard_by_database_in_region(klass, method, *args, jitter: nil, local_offset: false, connection_class: nil)
|
||||
callback = -> { Canvas::Errors.capture_exception(:periodic_job, $ERROR_INFO) }
|
||||
if Rails.version < "6.1"
|
||||
connection_class = if connection_class == Delayed::Backend::ActiveRecord::AbstractJob
|
||||
:delayed_jobs
|
||||
elsif connection_class == ActiveRecord::Base
|
||||
:primary
|
||||
end
|
||||
end
|
||||
Shard.with_each_shard(Shard.in_current_region, exception: callback) do
|
||||
current_shard = Shard.current(connection_class)
|
||||
strand = "#{klass}.#{method}:#{current_shard.database_server.id}"
|
||||
|
|
|
@ -177,79 +177,10 @@ module PostgreSQLAdapterExtensions
|
|||
[index_name, index_type, index_columns, index_options, algorithm, using]
|
||||
end
|
||||
|
||||
if Rails.version < "6.1"
|
||||
def remove_index(table_name, options = {})
|
||||
table = ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(table_name.to_s)
|
||||
def index_algorithm(algorithm)
|
||||
return nil if open_transactions > 0
|
||||
|
||||
if options.is_a?(Hash) && options.key?(:name)
|
||||
provided_index = ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(options[:name].to_s)
|
||||
|
||||
options[:name] = provided_index.identifier
|
||||
table = ActiveRecord::ConnectionAdapters::PostgreSQL::Name.new(provided_index.schema, table.identifier) unless table.schema.present?
|
||||
|
||||
if provided_index.schema.present? && table.schema != provided_index.schema
|
||||
raise ArgumentError, "Index schema '#{provided_index.schema}' does not match table schema '#{table.schema}'"
|
||||
end
|
||||
end
|
||||
|
||||
name = index_name_for_remove(table.to_s, options)
|
||||
return if name.nil? && options[:if_exists]
|
||||
|
||||
index_to_remove = ActiveRecord::ConnectionAdapters::PostgreSQL::Name.new(table.schema, name)
|
||||
algorithm =
|
||||
if options.is_a?(Hash) && options.key?(:algorithm)
|
||||
index_algorithms.fetch(options[:algorithm]) do
|
||||
raise ArgumentError, "Algorithm must be one of the following: #{index_algorithms.keys.map(&:inspect).join(", ")}"
|
||||
end
|
||||
end
|
||||
algorithm = nil if open_transactions > 0
|
||||
if_exists = " IF EXISTS" if options.is_a?(Hash) && options[:if_exists]
|
||||
execute "DROP INDEX #{algorithm} #{if_exists} #{quote_table_name(index_to_remove)}"
|
||||
end
|
||||
else
|
||||
def index_algorithm(algorithm)
|
||||
return nil if open_transactions > 0
|
||||
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
if Rails.version < "6.1"
|
||||
def index_name_for_remove(table_name, options = {})
|
||||
return options[:name] if can_remove_index_by_name?(options)
|
||||
|
||||
checks = []
|
||||
|
||||
if options.is_a?(Hash)
|
||||
checks << ->(i) { i.name == options[:name].to_s } if options.key?(:name)
|
||||
column_names = index_column_names(options[:column])
|
||||
else
|
||||
column_names = index_column_names(options)
|
||||
end
|
||||
|
||||
if column_names.present?
|
||||
checks << ->(i) { index_name(table_name, i.columns) == index_name(table_name, column_names) }
|
||||
end
|
||||
|
||||
raise ArgumentError, "No name or columns specified" if checks.none?
|
||||
|
||||
matching_indexes = indexes(table_name).select { |i| checks.all? { |check| check[i] } }
|
||||
|
||||
if matching_indexes.count > 1
|
||||
raise ArgumentError, "Multiple indexes found on #{table_name} columns #{column_names}. " \
|
||||
"Specify an index name from #{matching_indexes.map(&:name).join(", ")}"
|
||||
elsif matching_indexes.none?
|
||||
return if options.is_a?(Hash) && options[:if_exists]
|
||||
|
||||
raise ArgumentError, "No indexes found on #{table_name} with the options provided."
|
||||
else
|
||||
matching_indexes.first.name
|
||||
end
|
||||
end
|
||||
|
||||
def can_remove_index_by_name?(options)
|
||||
options.is_a?(Hash) && options.key?(:name) && options.except(:name, :algorithm, :if_exists).empty?
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
def add_column(table_name, column_name, type, if_not_exists: false, **options)
|
||||
|
@ -416,11 +347,7 @@ module ReferenceDefinitionExtensions
|
|||
end
|
||||
|
||||
if index
|
||||
if Rails.version < "6.1"
|
||||
table.index(column_names, index_options)
|
||||
else
|
||||
table.index(column_names, **index_options(table.name))
|
||||
end
|
||||
table.index(column_names, **index_options(table.name))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -445,11 +372,7 @@ module SchemaStatementsExtensions
|
|||
end
|
||||
end
|
||||
|
||||
if Rails.version < "6.1"
|
||||
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::SchemaCreation.prepend(SchemaCreationExtensions)
|
||||
else
|
||||
ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaCreation.prepend(SchemaCreationExtensions)
|
||||
end
|
||||
ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaCreation.prepend(SchemaCreationExtensions)
|
||||
ActiveRecord::ConnectionAdapters::ColumnDefinition.prepend(ColumnDefinitionExtensions)
|
||||
ActiveRecord::ConnectionAdapters::ReferenceDefinition.prepend(ReferenceDefinitionExtensions)
|
||||
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(SchemaStatementsExtensions)
|
||||
|
|
|
@ -310,7 +310,7 @@ module CanvasSecurity
|
|||
if db_hash.nil? || overwrite
|
||||
begin
|
||||
settings_store.set("encryption_key_hash", Digest::SHA1.hexdigest(encryption_key))
|
||||
rescue *[ActiveRecord::StatementInvalid, (Rails.version < "6.1" ? nil : ActiveRecord::ConnectionNotEstablished)].compact
|
||||
rescue ActiveRecord::StatementInvalid, ActiveRecord::ConnectionNotEstablished
|
||||
# the db may not exist yet
|
||||
end
|
||||
else
|
||||
|
|
|
@ -82,7 +82,7 @@ module ActiveRecord
|
|||
if multi_key_types.any?
|
||||
base_keys.each do |base_key|
|
||||
multi_key_types.each do |type|
|
||||
MultiCache.delete("#{base_key}/#{type}")
|
||||
MultiCache.delete("#{base_key}/#{type}", { unprefixed_key: true })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -762,11 +762,7 @@ describe ActiveRecord::Migration::CommandRecorder do
|
|||
[:add_index, [:accounts, :id, { if_not_exists: true }]],
|
||||
[:add_foreign_key, [:enrollments, :users, { if_not_exists: true }]],
|
||||
[:add_column, [:courses, :id, :integer, { limit: 8, if_not_exists: true }], nil],
|
||||
(if Rails.version < "6.1"
|
||||
[:remove_index, [:accounts, { algorithm: :concurrently, column: :course_template_id, if_exists: true }]]
|
||||
else
|
||||
[:remove_index, [:accounts, :course_template_id, { algorithm: :concurrently, if_exists: true }], nil]
|
||||
end),
|
||||
[:remove_index, [:accounts, :course_template_id, { algorithm: :concurrently, if_exists: true }], nil],
|
||||
[:remove_foreign_key, [:accounts, :courses, { column: :course_template_id, if_exists: true }], nil],
|
||||
[:remove_column, [:accounts, :course_template_id, :integer, { limit: 8, if_exists: true }], nil],
|
||||
])
|
||||
|
|
|
@ -419,7 +419,7 @@ describe Canvas::CacheRegister do
|
|||
key = Account.base_cache_register_key_for(Account.default) + "/feature_flags"
|
||||
allow(Canvas::CacheRegister).to receive(:can_use_multi_cache_redis?).and_return(true)
|
||||
expect(Canvas::CacheRegister).to_not receive(:redis)
|
||||
expect(MultiCache).to receive(:delete).with(key)
|
||||
expect(MultiCache).to receive(:delete).with(key, { unprefixed_key: true })
|
||||
Account.default.clear_cache_key(:feature_flags)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ describe ActiveSupport::Cache::HaStore do
|
|||
describe "#delete" do
|
||||
it "triggers a consul event when configured" do
|
||||
# will get called twice; once with rails52: prefix, once without
|
||||
expect(Diplomat::Event).to receive(:fire).with("invalidate", match(/mykey$/), nil, nil, nil, nil).twice
|
||||
expect(Diplomat::Event).to receive(:fire).with("invalidate", match(/mykey$/), nil, nil, nil, nil).exactly(SUPPORTED_VERSIONS.count).times
|
||||
store.delete("mykey")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -884,23 +884,13 @@ end
|
|||
describe ActiveRecord::ConnectionAdapters::ConnectionPool do
|
||||
# create a private pool, with the same config as the regular pool, but ensure
|
||||
# max_runtime is set
|
||||
if Rails.version < "6.1"
|
||||
let(:spec) do
|
||||
ActiveRecord::ConnectionAdapters::ConnectionSpecification.new(
|
||||
"spec",
|
||||
ActiveRecord::Base.connection_pool.spec.config.merge(max_runtime: 30),
|
||||
"postgresql_connection"
|
||||
)
|
||||
end
|
||||
else
|
||||
let(:spec) do
|
||||
config = ActiveRecord::DatabaseConfigurations::HashConfig.new(
|
||||
"test",
|
||||
"primary",
|
||||
ActiveRecord::Base.configurations.configs_for(env_name: "test", name: "primary").configuration_hash.merge(max_runtime: 30)
|
||||
)
|
||||
ActiveRecord::ConnectionAdapters::PoolConfig.new(ActiveRecord::Base, config)
|
||||
end
|
||||
let(:spec) do
|
||||
config = ActiveRecord::DatabaseConfigurations::HashConfig.new(
|
||||
"test",
|
||||
"primary",
|
||||
ActiveRecord::Base.configurations.configs_for(env_name: "test", name: "primary").configuration_hash.merge(max_runtime: 30)
|
||||
)
|
||||
ActiveRecord::ConnectionAdapters::PoolConfig.new(ActiveRecord::Base, config)
|
||||
end
|
||||
let(:pool) { ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec) }
|
||||
|
||||
|
|
|
@ -73,9 +73,9 @@ module TestDatabaseUtils
|
|||
private
|
||||
|
||||
def each_connection(&block)
|
||||
::Shard.with_each_shard(Rails.version < "6.1" ? ::Shard.categories : ::Shard.sharded_models) do
|
||||
::Shard.with_each_shard(::Shard.sharded_models) do
|
||||
models = ::ActiveRecord::Base.descendants
|
||||
models.reject! { |m| Rails.version < "6.1" ? m.shard_category == :unsharded : m.connection_classes == [::Switchman::UnshardedRecord] } unless ::Shard.current.default?
|
||||
models.reject! { |m| m.connection_classes == [::Switchman::UnshardedRecord] } unless ::Shard.current.default?
|
||||
model_connections = models.map(&:connection).uniq
|
||||
model_connections.each(&block)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue