use Rails.version check instead of CANVAS_RAILS variable

refs DE-523

Change-Id: I7baff2f4a6dee7beb518c6d1151a3027a7572f57
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/287809
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Jacob Burroughs <jburroughs@instructure.com>
QA-Review: Aaron Ogata <aogata@instructure.com>
Product-Review: Aaron Ogata <aogata@instructure.com>
This commit is contained in:
Aaron Ogata 2022-03-23 09:37:42 -07:00
parent 641d0523f1
commit 9098145ff5
17 changed files with 36 additions and 37 deletions

View File

@ -46,7 +46,7 @@ module Auditors::ActiveRecord
log "*" * 80
end
unless Rails.env.test?
if CANVAS_RAILS6_0
if Rails.version < "6.1"
ActiveRecord::Base.connection_pool.current_pool.disconnect!
else
ActiveRecord::Base.connection_pool.disconnect!

View File

@ -23,7 +23,7 @@ module Messages
log "Done. Bye!"
log "*" * 80
unless Rails.env.test?
if CANVAS_RAILS6_0
if Rails.version < "6.1"
ActiveRecord::Base.connection_pool.current_pool.disconnect!
else
ActiveRecord::Base.connection_pool.disconnect!

View File

@ -39,7 +39,7 @@ class Quizzes::QuizSubmissionEventPartitioner
log "Done. Bye!"
log "*" * 80
unless in_migration || Rails.env.test?
if CANVAS_RAILS6_0
if Rails.version < "6.1"
ActiveRecord::Base.connection_pool.current_pool.disconnect!
else
ActiveRecord::Base.connection_pool.disconnect!

View File

@ -37,7 +37,7 @@ class SimplyVersioned::Partitioner
log "Done. Bye!"
log "*" * 80
unless Rails.env.test?
if CANVAS_RAILS6_0
if Rails.version < "6.1"
ActiveRecord::Base.connection_pool.current_pool.disconnect!
else
ActiveRecord::Base.connection_pool.disconnect!

View File

@ -400,7 +400,7 @@ class StreamItem < ActiveRecord::Base
StreamItem.vacuum
StreamItemInstance.vacuum
unless Rails.env.test?
if CANVAS_RAILS6_0
if Rails.version < "6.1"
ActiveRecord::Base.connection_pool.current_pool.disconnect!
else
ActiveRecord::Base.connection_pool.disconnect!

View File

@ -23,5 +23,5 @@ 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 CANVAS_RAILS6_0
self.shard_category = :unsharded if Rails.version < "6.1"
end

View File

@ -130,7 +130,7 @@ module CanvasRails
Canvas::Plugins::DefaultPlugins.apply_all
ActiveSupport::JSON::Encoding.escape_html_entities_in_json = true
if CANVAS_RAILS6_0
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

View File

@ -610,7 +610,7 @@ class ActiveRecord::Base
end
def self.current_xlog_location
Shard.current(send(CANVAS_RAILS6_0 ? :shard_category : :connection_classes)).database_server.unguard do
Shard.current(send(Rails.version < "6.1" ? :shard_category : :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"
@ -709,7 +709,7 @@ class ActiveRecord::Base
changes_applied
end
unless CANVAS_RAILS6_0
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)
@ -732,7 +732,7 @@ module UsefulFindInBatches
else
enum_for(:find_each, start: start, finish: finish, order: order, **kwargs) do
relation = self
if CANVAS_RAILS6_0
if Rails.version < "6.1"
apply_limits(relation, start, finish).size
else
apply_limits(relation, start, finish, order).size
@ -746,7 +746,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 CANVAS_RAILS6_0
total = if Rails.version < "6.1"
apply_limits(relation, start, finish).size
else
apply_limits(relation, start, finish, order).size
@ -776,7 +776,7 @@ module UsefulFindInBatches
if strategy == :id
raise ArgumentError, "GROUP BY is incompatible with :id batches strategy" unless group_values.empty?
if CANVAS_RAILS6_0
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) }
@ -825,7 +825,7 @@ module UsefulFindInBatches
def in_batches_with_cursor(of: 1000, start: nil, finish: nil, order: :asc, load: false)
klass.transaction do
relation = if CANVAS_RAILS6_0
relation = if Rails.version < "6.1"
apply_limits(clone, start, finish)
else
apply_limits(clone, start, finish, order)
@ -869,7 +869,7 @@ module UsefulFindInBatches
limited_query = limit(0).to_sql
relation = self
relation_for_copy = if CANVAS_RAILS6_0
relation_for_copy = if Rails.version < "6.1"
apply_limits(relation, start, finish)
else
apply_limits(relation, start, finish, order)
@ -967,7 +967,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 CANVAS_RAILS6_0
relation = if Rails.version < "6.1"
apply_limits(self, start, finish)
else
apply_limits(self, start, finish, order)
@ -999,7 +999,7 @@ module UsefulFindInBatches
group, or order)."
end
relation = if CANVAS_RAILS6_0
relation = if Rails.version < "6.1"
apply_limits(self, start, finish)
else
apply_limits(self, start, finish, order)
@ -1144,7 +1144,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) || (!CANVAS_RAILS6_0 && pred.is_a?(Arel::Nodes::HomogeneousIn))
next unless pred.is_a?(Arel::Nodes::Binary) || (Rails.version >= "6.1" && pred.is_a?(Arel::Nodes::HomogeneousIn))
next unless pred.left == attr
found_match = true
@ -1170,7 +1170,7 @@ module UsefulBatchEnumerator
pred.right.exclude?(update)
elsif pred.instance_of?(Arel::Nodes::NotIn) && pred.right.is_a?(Array)
pred.right.include?(update)
elsif !CANVAS_RAILS6_0 && pred.instance_of?(Arel::Nodes::HomogeneousIn)
elsif Rails.version >= "6.1" && pred.instance_of?(Arel::Nodes::HomogeneousIn)
case pred.type
when :in
pred.right.map(&:value).exclude?(update.value.value)
@ -1368,7 +1368,7 @@ module UpdateAndDeleteWithJoins
end
def update_all(updates, *args)
db = Shard.current(klass.send(CANVAS_RAILS6_0 ? :shard_category : :connection_classes)).database_server
db = Shard.current(klass.send(Rails.version < "6.1" ? :shard_category : :connection_classes)).database_server
if joins_values.empty?
if ::GuardRail.environment == db.guard_rail_environment
return super
@ -1618,7 +1618,7 @@ module Migrator
super.select(&:runnable?)
end
if CANVAS_RAILS6_0
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)
@ -1785,7 +1785,7 @@ ActiveRecord::Associations::CollectionAssociation.class_eval do
end
end
if CANVAS_RAILS6_0
if Rails.version < "6.1"
module UnscopeCallbacks
def run_callbacks(kind)
return super if __callbacks[kind].empty?
@ -2002,7 +2002,7 @@ ActiveRecord::Relation.prepend(DontExplicitlyNameColumnsBecauseOfIgnores)
module PreserveShardAfterTransaction
def after_transaction_commit(&block)
shards = Shard.send(:active_shards)
shards[CANVAS_RAILS6_0 ? :delayed_jobs : Delayed::Backend::ActiveRecord::AbstractJob] = Shard.current.delayed_jobs_shard if ::ActiveRecord::Migration.open_migrations.positive?
shards[Rails.version < "6.1" ? :delayed_jobs : Delayed::Backend::ActiveRecord::AbstractJob] = Shard.current.delayed_jobs_shard if ::ActiveRecord::Migration.open_migrations.positive?
super { Shard.activate(shards, &block) }
end
end
@ -2051,7 +2051,7 @@ ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(RestoreConnectionConnec
module MaxRuntimeConnectionPool
def max_runtime
# TODO: Rails 6.1 uses a PoolConfig object instead
if CANVAS_RAILS6_0
if Rails.version < "6.1"
@spec.config[:max_runtime]
else
db_config.configuration_hash[:max_runtime]
@ -2172,7 +2172,7 @@ module UserContentSerialization
end
ActiveRecord::Base.include(UserContentSerialization)
unless CANVAS_RAILS6_0
if Rails.version >= "6.1"
# Hopefully this can be removed with https://github.com/rails/rails/commit/6beee45c3f071c6a17149be0fabb1697609edbe8
# having made a released version of rails; if not bump the rails version in this comment and leave the comment to be revisited
# on the next rails bump

View File

@ -69,7 +69,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(CANVAS_RAILS6_0 ? :delayed_jobs : Delayed::Backend::ActiveRecord::AbstractJob).id}~" }
Delayed::Settings.worker_procname_prefix = -> { "#{Shard.current(Rails.version < "6.1" ? :delayed_jobs : 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

View File

@ -21,7 +21,7 @@ if ENV["RAILS_DATABASE_ENVIRONMENT"]
GuardRail.activate!(ENV["RAILS_DATABASE_ENVIRONMENT"].to_sym)
end
if ENV["RAILS_DATABASE_USER"]
if CANVAS_RAILS6_0
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)

View File

@ -177,7 +177,7 @@ module PostgreSQLAdapterExtensions
[index_name, index_type, index_columns, index_options, algorithm, using]
end
if CANVAS_RAILS6_0
if Rails.version < "6.1"
def remove_index(table_name, options = {})
table = ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(table_name.to_s)
@ -214,7 +214,7 @@ module PostgreSQLAdapterExtensions
end
end
if CANVAS_RAILS6_0
if Rails.version < "6.1"
def index_name_for_remove(table_name, options = {})
return options[:name] if can_remove_index_by_name?(options)
@ -416,7 +416,7 @@ module ReferenceDefinitionExtensions
end
if index
if CANVAS_RAILS6_0
if Rails.version < "6.1"
table.index(column_names, index_options)
else
table.index(column_names, **index_options(table.name))
@ -445,7 +445,7 @@ module SchemaStatementsExtensions
end
end
if CANVAS_RAILS6_0
if Rails.version < "6.1"
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::SchemaCreation.prepend(SchemaCreationExtensions)
else
ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaCreation.prepend(SchemaCreationExtensions)

View File

@ -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, (CANVAS_RAILS6_0 ? nil : ActiveRecord::ConnectionNotEstablished)].compact
rescue *[ActiveRecord::StatementInvalid, (Rails.version < "6.1" ? nil : ActiveRecord::ConnectionNotEstablished)].compact
# the db may not exist yet
end
else

View File

@ -762,7 +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 CANVAS_RAILS6_0
(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]

View File

@ -24,7 +24,7 @@ describe I18n do
# HINT: if this spec fails, run `rake i18n:generate_js`...
# it probably means you added a format or a new language
it "is up-to-date" do
skip("Rails 6.0 specific") unless CANVAS_RAILS6_0
skip("Rails 6.0 specific") if Rails.version >= "6.1"
file_contents = File.read("public/javascripts/translations/_core_en.js")
translations = I18n.backend.send(:translations)[:en].slice(*I18nTasks::Utils::CORE_KEYS)

View File

@ -884,7 +884,7 @@ 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 CANVAS_RAILS6_0
if Rails.version < "6.1"
let(:spec) do
ActiveRecord::ConnectionAdapters::ConnectionSpecification.new(
"spec",

View File

@ -43,7 +43,6 @@ describe "i18n js" do
context "locales" do
it "pulls in core translations for all locales" do
skip("Rails 6.0 specific") unless CANVAS_RAILS6_0
skip("USE_OPTIMIZED_JS=true") unless ENV["USE_OPTIMIZED_JS"]
skip("RAILS_LOAD_ALL_LOCALES=true") unless ENV["RAILS_LOAD_ALL_LOCALES"]
core_keys = I18nTasks::Utils::CORE_KEYS

View File

@ -73,9 +73,9 @@ module TestDatabaseUtils
private
def each_connection(&block)
::Shard.with_each_shard(CANVAS_RAILS6_0 ? ::Shard.categories : ::Shard.sharded_models) do
::Shard.with_each_shard(Rails.version < "6.1" ? ::Shard.categories : ::Shard.sharded_models) do
models = ::ActiveRecord::Base.descendants
models.reject! { |m| CANVAS_RAILS6_0 ? m.shard_category == :unsharded : m.connection_classes == [::Switchman::UnshardedRecord] } unless ::Shard.current.default?
models.reject! { |m| Rails.version < "6.1" ? m.shard_category == :unsharded : m.connection_classes == [::Switchman::UnshardedRecord] } unless ::Shard.current.default?
model_connections = models.map(&:connection).uniq
model_connections.each(&block)
end