From df01aec6570e21420dbae59e3a5c48be8feaa25c Mon Sep 17 00:00:00 2001 From: Chris Yuska Date: Wed, 2 Oct 2019 19:16:37 -0400 Subject: [PATCH 1/5] BP-2147 | Hotfix: Added support for Rails 6 database switching In testing the Rails 6 final release, seeding the test database was failing due to the the new way connections are handled. It appears with Rails 6 that establishing the DB connection within the connection pool no longer automatically connects at the ActiveRecord::Base level. This adds a manual call to establish the connection when it's just added to the pool --- lib/apartment/adapters/abstract_adapter.rb | 1 + lib/apartment/version.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/apartment/adapters/abstract_adapter.rb b/lib/apartment/adapters/abstract_adapter.rb index 29e4988c..6e7d6be2 100644 --- a/lib/apartment/adapters/abstract_adapter.rb +++ b/lib/apartment/adapters/abstract_adapter.rb @@ -140,6 +140,7 @@ def connection_switch!(config, without_keys: []) unless Apartment.connection_handler.retrieve_connection_pool(config[:name]) Apartment.connection_handler.establish_connection(config) + Apartment.establish_connection(config) end Thread.current[:_apartment_connection_specification_name] = config[:name] diff --git a/lib/apartment/version.rb b/lib/apartment/version.rb index aedfbb55..28db8775 100644 --- a/lib/apartment/version.rb +++ b/lib/apartment/version.rb @@ -1,3 +1,3 @@ module Apartment - VERSION = "2.0.0" + VERSION = "2.0.1" end From 32a13f5dbac8e713e693f09a7877df3365383128 Mon Sep 17 00:00:00 2001 From: Chris Yuska Date: Wed, 2 Oct 2019 19:35:43 -0400 Subject: [PATCH 2/5] Travis config --- .travis.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.travis.yml b/.travis.yml index d800be75..e376ffa9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,29 @@ +addons: + postgresql: 9.6 +dist: trusty language: ruby +cache: bundler + rvm: - 2.2.4 - 2.3.1 - jruby-9.0.5.0 + gemfile: - gemfiles/rails_5_1.gemfile + bundler_args: --without local before_install: - gem install bundler -v '> 1.5.0' + env: RUBY_GC_MALLOC_LIMIT: 90000000 RUBY_FREE_MIN: 200000 + matrix: fast_finish: true + +notifications: + email: + on_success: never + on_failure: always From cf2d4fbb9fa300fa692e6c8bf95292aac7ac8947 Mon Sep 17 00:00:00 2001 From: Chris Yuska Date: Wed, 2 Oct 2019 19:38:30 -0400 Subject: [PATCH 3/5] More Travis --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e376ffa9..3f9937ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,7 @@ language: ruby cache: bundler rvm: - - 2.2.4 - - 2.3.1 + - 2.6.3 - jruby-9.0.5.0 gemfile: @@ -14,7 +13,8 @@ gemfile: bundler_args: --without local before_install: - - gem install bundler -v '> 1.5.0' + - gem update --system + - gem install bundler env: RUBY_GC_MALLOC_LIMIT: 90000000 From e1b09f5ec7d08630176ad8233db5d132eb20d651 Mon Sep 17 00:00:00 2001 From: Chris Yuska Date: Wed, 2 Oct 2019 19:47:05 -0400 Subject: [PATCH 4/5] More Travis config --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3f9937ab..afcf7e0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,9 @@ before_install: - gem update --system - gem install bundler +before_script: + - psql -c 'create database apartment_postgresql_test;' -U postgres + env: RUBY_GC_MALLOC_LIMIT: 90000000 RUBY_FREE_MIN: 200000 From 23aa07d6db470d052fe98f248a3a1313c37aa720 Mon Sep 17 00:00:00 2001 From: Chris Yuska Date: Tue, 8 Oct 2019 12:41:17 -0400 Subject: [PATCH 5/5] Fixed thread-safe switching, at least in Rails tests --- lib/apartment/adapters/abstract_adapter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/apartment/adapters/abstract_adapter.rb b/lib/apartment/adapters/abstract_adapter.rb index 6e7d6be2..2dd183ab 100644 --- a/lib/apartment/adapters/abstract_adapter.rb +++ b/lib/apartment/adapters/abstract_adapter.rb @@ -83,7 +83,7 @@ def switch!(tenant) @current = tenant - Apartment.connection.clear_query_cache + Apartment.connection_class.clear_query_caches_for_current_thread tenant end @@ -140,10 +140,10 @@ def connection_switch!(config, without_keys: []) unless Apartment.connection_handler.retrieve_connection_pool(config[:name]) Apartment.connection_handler.establish_connection(config) - Apartment.establish_connection(config) end Thread.current[:_apartment_connection_specification_name] = config[:name] + Apartment.connection_class.connection_specification_name = config[:name] simple_switch(config) end