https://github.com/jacobbednarz/rails-db-proxy
A better approach for using a primary and secondary database setup in Rails
https://github.com/jacobbednarz/rails-db-proxy
Last synced: about 1 month ago
JSON representation
A better approach for using a primary and secondary database setup in Rails
- Host: GitHub
- URL: https://github.com/jacobbednarz/rails-db-proxy
- Owner: jacobbednarz
- License: mit
- Created: 2016-08-15T01:05:55.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-08-15T01:20:26.000Z (over 8 years ago)
- Last Synced: 2025-02-07T13:54:24.881Z (3 months ago)
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rails-db-proxy
A better approach for using a primary and secondary database setup in
Rails.### Design
The idea is that this library would manage the connections based on the
existing database YAML file with minimum changes and remain compatible
with the base ActiveRecord implementation. Here is the proposed changes
to the `database.yml` file.```yaml
production:
adapter: mysql2
username: user
password: super_s3cret
host: my-db-host.domain.internalconnections:
primary: my-db-host.domain.internal
secondary: my-secondary-db-host.domain.internal
```### Usage examples
Model chaining
```rb
User.find(1).using_database_connection(:secondary)
```For the whole model
```rb
class User < ActiveRecord::Base
use_database_connection :secondary
end
```...Or individual methods
```rb
# For only a certain methods
class User < ActiveRecord::Base
use_database_connection :secondary, :only => [:get_all_users]
end# For all methods in a model except for a subset of them
class User < ActiveRecord::Base
use_database_connection :secondary, :except => [:quick_method]
end
```