diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2018-10-10 13:58:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-10 13:58:17 -0400 |
commit | fb8bee4a479eac0c799df356374c8f72e7649527 (patch) | |
tree | 1d41985417f6c73799ff5cd6f60429e8967190a6 /activerecord/CHANGELOG.md | |
parent | 58999af99fa485f748ab33d4aa4254a4b4a50991 (diff) | |
parent | 31021a8c85bb80300deb01db96876858ff417f4a (diff) | |
download | rails-fb8bee4a479eac0c799df356374c8f72e7649527.tar.gz rails-fb8bee4a479eac0c799df356374c8f72e7649527.tar.bz2 rails-fb8bee4a479eac0c799df356374c8f72e7649527.zip |
Merge pull request #34052 from eileencodes/connection-switching
Part 4: Multi db improvements, Basic API for connection switching
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r-- | activerecord/CHANGELOG.md | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 6397bc361a..00f4ee1aaa 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,39 @@ +* Add basic API for connection switching to support multiple databases. + + 1) Adds a `connects_to` method for models to connect to multiple databases. Example: + + ``` + class AnimalsModel < ApplicationRecord + self.abstract_class = true + + connects_to database: { writing: :animals_primary, reading: :animals_replica } + end + + class Dog < AnimalsModel + # connected to both the animals_primary db for writing and the animals_replica for reading + end + ``` + + 2) Adds a `connected_to` block method for switching connection roles or connecting to + a database that the model didn't connect to. Connecting to the database in this block is + useful when you have another defined connection, for example `slow_replica` that you don't + want to connect to by default but need in the console, or a specific code block. + + ``` + ActiveRecord::Base.connected_to(role: :reading) do + Dog.first # finds dog from replica connected to AnimalsBase + Book.first # doesn't have a reading connection, will raise an error + end + ``` + + ``` + ActiveRecord::Base.connected_to(database: :slow_replica) do + SlowReplicaModel.first # if the db config has a slow_replica configuration this will be used to do the lookup, otherwise this will throw an exception + end + ``` + + *Eileen M. Uchitelle* + * Enum raises on invalid definition values When defining a Hash enum it can be easy to use [] instead of {}. This |