spec) 2 @class_to_pool.clear 3 raise RuntimeError, "Anonymous class is not allowed." unless owner.name 4 owner_to_pool[owner.name] = ConnectionAdapters::ConnectionPool.new(spec) 5 end
2 class_to_pool[klass.name] ||= begin 3 until pool = pool_for(klass) 4 klass = klass.superclass 5 break unless klass <= Base 6 end 7 8 class_to_pool[klass.name] = pool 9 end 10 end
1 class User < ActiveRecord::Base 2 establish_connection :user_db 3 switcher.with_readonly do 4 establish_connection :user_db_readonly 5 end 6 end 7 8 switcher.with_readonly do 9 user = User.find 10 end
Decouple Active Record model and connection pool • Model.establish_connection() method • Use a new key for the connection pools list • Fix all the things around it
< 5 • Lot of code necessary + Patches in AR • Rails 5 • Ground work is done for ease connection handling • Rails 5.1 • Will have even more improvements