New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for rails console --sandbox
for multiple database applications
#40704
Conversation
47218b1
to
ae674f5
Compare
ActiveRecord::Base.connection.begin_transaction(joinable: false) | ||
|
||
at_exit do | ||
ActiveRecord::Base.connection.rollback_transaction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to call rollback_transaction
manually because the all connections will be rolled back on disconnected/exited.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
rails console --sandbox
for multiple database applicationsrails console --sandbox
for multiple database applications
rails console --sandbox
for multiple database applicationsrails console --sandbox
for multiple database applications
ActiveRecord::Base.connection.begin_transaction(joinable: false) | ||
|
||
at_exit do | ||
ActiveRecord::Base.connection.rollback_transaction |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
activerecord/CHANGELOG.md
Outdated
@@ -1,3 +1,9 @@ | |||
* Add support for `rails console --sandbox` for multiple database applications. | |||
|
|||
Multiple database applications will now be rolled back on exit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this changelog is really necessary. It implies it's adding support for multiple databases but it's really fixing a bug. We don't add changelogs when fixing a bug. Can you remove this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 👍
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.
ae674f5
to
67517fd
Compare
Add support for `rails console --sandbox` for multiple database applications
Backported this to 6-1-stable 9cc99d7. |
Summary
With a multiple database application
rails console --sandbox
becomes problematic. We can't rollback any modifications for every non-primary database because we can't open transaction for the connections that haven't yet been loaded.To solve this I handled that if the database is connected then it will open transaction. This way can handle all connections.