aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/core.rb
diff options
context:
space:
mode:
authorEileen Uchitelle <eileencodes@gmail.com>2019-02-01 11:33:48 -0500
committerEileen Uchitelle <eileencodes@gmail.com>2019-02-01 14:11:35 -0500
commit8d32346cdec04dd85ab682eeb9f4edfcd0c9ccef (patch)
tree35ad1286d0328876eb6e49c61d8ed2044e38f023 /activerecord/lib/active_record/core.rb
parent79bc9e81c3d47be6336223be39cb3bcaeddc0a39 (diff)
downloadrails-8d32346cdec04dd85ab682eeb9f4edfcd0c9ccef.tar.gz
rails-8d32346cdec04dd85ab682eeb9f4edfcd0c9ccef.tar.bz2
rails-8d32346cdec04dd85ab682eeb9f4edfcd0c9ccef.zip
Add ability to change the names of the default handlers
When I wrote the `connected_to` and `connects_to` API's I wrote them with the idea in mind that it didn't really matter what the handlers/roles were called as long as those connecting to the roles knew which one wrote and which one read. With the introduction of the middleware Rails begins to assume it's `writing` and `reading` and there's no room for other roles. At GitHub we've been using this method for a long time so we have a ton of legacy code that uses different handler names `default` and `readonly`. We could rename all our code but I think this is better for a few reasons: - Legacy apps that have been using multiple databases for a long time can have an eaiser time switching. - If we later find this to cause more issues than it's worth we can easily deprecate. - We won't force old apps to rewrite the resolver middleware just to use a different handler. Adding the writing_role/reading_role required that I move the code that creates the first handler for writing to the railtie. If I didn't move this the core class would assign the handler before I was able to assign a new one in my configuration and I'd end up with 3 handlers instead of 2.
Diffstat (limited to 'activerecord/lib/active_record/core.rb')
-rw-r--r--activerecord/lib/active_record/core.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 519acd7605..84604452f7 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -125,6 +125,10 @@ module ActiveRecord
mattr_accessor :connection_handlers, instance_accessor: false, default: {}
+ mattr_accessor :writing_role, instance_accessor: false, default: :writing
+
+ mattr_accessor :reading_role, instance_accessor: false, default: :reading
+
class_attribute :default_connection_handler, instance_writer: false
self.filter_attributes = []
@@ -138,7 +142,6 @@ module ActiveRecord
end
self.default_connection_handler = ConnectionAdapters::ConnectionHandler.new
- self.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
end
module ClassMethods