Add multiple database support for write operations during GET requests#1791
Add multiple database support for write operations during GET requests#1791
Conversation
Co-authored-by: nbulaj <1443426+nbulaj@users.noreply.github.com>
Co-authored-by: nbulaj <1443426+nbulaj@users.noreply.github.com>
Co-authored-by: nbulaj <1443426+nbulaj@users.noreply.github.com>
Co-authored-by: nbulaj <1443426+nbulaj@users.noreply.github.com>
Co-authored-by: nbulaj <1443426+nbulaj@users.noreply.github.com>
|
@copilot rename active_record_options config option to enable_multiple_databases - let's avoid coupling to ActiveRecord so any Doorkeeper extension (like for Sequel or any other ORM) can use it's own implementation to support primary-replica. |
Co-authored-by: nbulaj <1443426+nbulaj@users.noreply.github.com>
Done! Renamed Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot let's swap conditions in |
Co-authored-by: nbulaj <1443426+nbulaj@users.noreply.github.com>
Co-authored-by: nbulaj <1443426+nbulaj@users.noreply.github.com>
Done! Added guard clause Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
All was good @copilot before you changed 3000+ files. Why did you touch vendor/ folder? Remove these changes |
I apologize for the issue. The vendor/bundle files were accidentally committed in afc4fca when running tests locally. The files are now properly excluded via .gitignore (commit 0e013e7), but they remain in the commit history. To completely remove them from the repository history, the branch needs to be force-pushed after rewriting history with Would you like me to:
The actual code changes in afc4fca (guard clause and condition swap in write_to_primary.rb) are correct and working. |
Co-authored-by: nbulaj <1443426+nbulaj@users.noreply.github.com>
|
@copilot fix tests |
All tests are currently passing locally (1,258 examples, 0 failures). Could you clarify which tests need fixing? Are there specific CI failures I should address, or is there a particular test scenario you'd like me to add or modify? Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Summary
This PR adds support for Rails read replicas with automatic role switching by introducing a new configuration option
enable_multiple_databases.Implementation Checklist
active_record_options[:handle_read_write_roles]toenable_multiple_databasesfor ORM-agnostic designConfiguration
The configuration is ORM-agnostic, allowing other ORM extensions (Sequel, MongoDB, etc.) to implement their own logic for directing writes to the primary database.
Usage
What It Does
When enabled:
ActiveRecord::Base.connected_to(role: :writing)Operations Protected
Backward Compatibility
Original prompt
ActiveRecord::ReadOnlyErrorwhen using Rails read replicas #1783💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.