README.md in ebisu_connection-2.4.2 vs README.md in ebisu_connection-3.0.0
- old
+ new
@@ -48,13 +48,12 @@
article.save
article.destory
```
## Support ActiveRecord version
-EbisuConnection supports ActiveRecord version 4.2 or later.
-If you are using Rails 4.1 or 4.0, you can use EbisuConnection version 2.1.0 or before.
-If you are using Rails 3.2, could use EbisuConnection version 1.0.0 or before.
+EbisuConnection supports ActiveRecord version 5.0 or later.
+If you are using Rails 4.2, you can use EbisuConnection version 2.4.2 or before.
## Support DB
EbisuConnection supports MySQL and PostgreSQL.
## Installation
@@ -80,30 +79,31 @@
## Config
config/database.yml
```yaml
-production:
+default: &default
adapter: mysql2
encoding: utf8
- reconnect: true
- database: kaeru
- pool: 5
- username: master
- password: master
- host: localhost
- socket: /var/run/mysqld/mysqld.sock
+ pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+ username: root
+ password:
+production:
+ <<: *default
+ database: blog_production
+ username: master_db_user
+ password: <%= ENV['MASTER_DATABASE_PASSWORD'] %>
+ host: master_db
+
replica:
- username: replica
- password: replica
- host: replica
+ username: replica_db_user
+ password: <%= ENV['REPLICA_DATABASE_PASSWORD'] %>
```
-```replica``` is a config to connect to replica servers.
-Others will use the master server settings.
-
+`replica` is the configuration used for connecting read-only queries to the database replica. All other connections will use the database master settings.
+
Config of each replica server fill out to `config/replica.yml`
```yaml
production:
- "replica1, 10"
@@ -121,30 +121,31 @@
### use multiple replica servers group
If you may want to user multiple replica group, write multiple replica group to config/database.yml.
```yaml
-production:
+default: &default
adapter: mysql2
encoding: utf8
- reconnect: true
- database: kaeru
- pool: 5
- username: master
- password: master
- host: localhost
- socket: /var/run/mysqld/mysqld.sock
+ pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+ username: root
+ password:
+production:
+ <<: *default
+ database: blog_production
+ username: master_db_user
+ password: <%= ENV['MASTER_DATABASE_PASSWORD'] %>
+ host: master_db
+
replica:
- username: replica
- password: replica
- host: replica
+ username: replica_db_user
+ password: <%= ENV['REPLICA_DATABASE_PASSWORD'] %>
admin_replica:
- username: replica
- password: replica
- host: admin_replica
+ username: admin_replica_db_user
+ password: <%= ENV['ADMIN_REPLICA_DATABASE_PASSWORD'] %>
```
Config of each replica server fill out to `config/replica.yml`
```yaml
@@ -158,19 +159,19 @@
admin_replica:
- "replica4, 10"
- "replica5, 20"
```
-And call establish_fresh_connection method in model that access to ```admin_replica``` replica group.
+The custom replica stanza can then be applied as an argument to the `establish_fresh_connection` method in the models that should use it. For example:
```ruby
class AdminUser < ActiveRecord::Base
establish_fresh_connection :admin_replica
end
```
-The children is access to same replica group of parent.
+The child (sub) classes of the configured model will inherit the same access as the parent class. Example:
```ruby
class Parent < ActiveRecord::Base
establish_fresh_connection :admin_replica
end
@@ -180,35 +181,30 @@
class Benefit < Parent
end
```
-AdminUser and Benefit access to ```admin_replica``` replica group.
+The `AdminUser` and `Benefit` models will access the database configured for the `admin_replica` group.
-### Declare model that doesn't use replica db
+### Master-only Models
+It is possible to declare that specific models always use the DB master for all connections, using the `master_db_only!` method:
+
```ruby
class SomethingModel < ActiveRecord::Base
master_db_only!
end
```
-If model that always access to master servers is exist, You may want to write ```master_db_only!``` in model.
-The model that master_db_only model's child is always access to master db.
+All queries generated by methods on the `CustomerState` model will be directed to the DB master.
-### for Unicorn
+### Using EbisuConnection With Unicorn
```ruby
before_fork do |server, worker|
...
ActiveRecord::Base.clear_all_replica_connections!
- ...
-end
-
-after_fork do |server, worker|
- ...
- ActiveRecord::Base.establish_fresh_connection
...
end
```
## Contributing