1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Open transaction for multi-db apps

With a multiple database application `rails console --sandbox` becomes
problematic. We can't rollback any modifications for every database
because we can't open transaction for the connections that haven't not
yet been loaded.

To solve this I handled that if the database is connected then it
will open transaction.
This commit is contained in:
alpaca-tc 2020-11-28 15:48:05 +09:00
parent 257f151ffd
commit 67517fde49

View file

@ -1,7 +1,5 @@
# frozen_string_literal: true
ActiveRecord::Base.connection.begin_transaction(joinable: false)
at_exit do
ActiveRecord::Base.connection.rollback_transaction
ActiveRecord::ConnectionAdapters::AbstractAdapter.set_callback(:checkout, :after) do
begin_transaction(joinable: false)
end