diff --git a/Gemfile.lock b/Gemfile.lock index eb038548463..55be426f551 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -336,15 +336,16 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.5.0) - loofah (~> 2.19, >= 2.19.1) - rails_failover (1.0.0) - activerecord (> 6.0, < 7.1) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + rails_failover (2.0.1) + activerecord (>= 6.1, <= 7.1) concurrent-ruby - railties (> 6.0, < 7.1) - rails_multisite (4.0.1) - activerecord (> 5.0, < 7.1) - railties (> 5.0, < 7.1) + railties (>= 6.1, <= 7.1) + rails_multisite (5.0.0) + activerecord (>= 6.0) + railties (>= 6.0) railties (7.0.4.3) actionpack (= 7.0.4.3) activesupport (= 7.0.4.3) diff --git a/config/application.rb b/config/application.rb index 9850f85bf70..0962bccb6ca 100644 --- a/config/application.rb +++ b/config/application.rb @@ -94,7 +94,6 @@ module Discourse config.active_record.cache_versioning = false # our custom cache class doesn’t support this config.action_controller.forgery_protection_origin_check = false config.active_record.belongs_to_required_by_default = false - config.active_record.legacy_connection_handling = true config.active_record.yaml_column_permitted_classes = [ Hash, HashWithIndifferentAccess, diff --git a/lib/freedom_patches/rails_multisite.rb b/lib/freedom_patches/rails_multisite.rb index 0a78baaf320..608bf580b03 100644 --- a/lib/freedom_patches/rails_multisite.rb +++ b/lib/freedom_patches/rails_multisite.rb @@ -12,18 +12,17 @@ module RailsMultisite reading_role = :"#{db}_#{ActiveRecord.reading_role}" spec = RailsMultisite::ConnectionManagement.connection_spec(db: db) + handler = ActiveRecord::Base.connection_handler - ActiveRecord::Base.connection_handlers[reading_role] ||= begin - handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new - RailsFailover::ActiveRecord.establish_reading_connection(handler, spec) - handler - end - + RailsFailover::ActiveRecord.establish_reading_connection( + handler, + spec.to_hash, + role: reading_role, + ) ActiveRecord::Base.connected_to(role: reading_role) { yield(db) if block_given? } rescue => e STDERR.puts "URGENT: Failed to initialize site #{db}: " \ "#{e.class} #{e.message}\n#{e.backtrace.join("\n")}" - # the show must go on, don't stop startup if multisite fails end end