I use connection switching in AA backend. Depending on session i switch to the archive db. The problem is that calling ActiveRecord::Base.connected_to with database key switches the connection forever, not only inside the block. And another queries outside of AA start to go to the archive db.
# config/initializers/active_admin.rb
config.around_action do |controller, action|
if session['ARCHIVE'] == 'archive'
ActiveRecord::Base.connected_to(database: :archive, prevent_writes: true) do
action.call
end
else
action.call
end
Is it possible to handle it?
i may be wrong ,is this is what you are looking for?