ar-multidb 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.markdown +17 -0
- data/lib/multidb/balancer.rb +5 -0
- data/lib/multidb/version.rb +1 -1
- data/spec/balancer_spec.rb +6 -1
- data/spec/helpers.rb +4 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 191bf9ea7a4823bd2c2148a13a3d7e19518233fafaac0be30aa1b018e50057ac
|
4
|
+
data.tar.gz: 0a722ce4f9289e9a1e8bf4c2200ef3243119fff97e570eb8787254f6d4f8aac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d0da233e8c260b3e1893f1a259fc7014d49bc7fd17bc937c5f0436e6297af1cf794e56b611001a4670dd6a20fc7dc27359cb2ff41d26af5dd42d125b44ce03d
|
7
|
+
data.tar.gz: 3fa308aeb36f94c7717e46c6c1758a66609c278500ccf65141992fc0de0902293a2edfe2a6d358972b8a7dcd8c85784328770e9b2f43c670fe09b8b3558c0269
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
|
6
|
+
|
7
|
+
## [0.4.1]
|
8
|
+
### Added
|
9
|
+
- Added support for database aliases ( PR #26 )
|
10
|
+
|
data/README.markdown
CHANGED
@@ -81,6 +81,23 @@ If multiple elements are specified, Multidb will use the list to pick a random c
|
|
81
81
|
|
82
82
|
The database hashes follow the same format as the top-level adapter configuration. In other words, each database connection may override the adapter, database name, username and so on.
|
83
83
|
|
84
|
+
You may also add an "alias" record to the configuration to support more than one name for a given database configuration.
|
85
|
+
|
86
|
+
production:
|
87
|
+
adapter: postgresql
|
88
|
+
database: myapp_production
|
89
|
+
username: ohoh
|
90
|
+
password: mymy
|
91
|
+
host: db1
|
92
|
+
multidb:
|
93
|
+
databases:
|
94
|
+
main_db:
|
95
|
+
host: db1-a
|
96
|
+
secondary_db:
|
97
|
+
alias: main_db
|
98
|
+
|
99
|
+
With the above, `Multidb.use(:main_db)` and `Multidb.use(:secondary_db)` will work identically. This can be useful to support naming scheme migrations transparently: once your application is updated to use `secondary_db` where necessary, you can swap out the configuration.
|
100
|
+
|
84
101
|
To use the connection, modify your code by wrapping database access logic in blocks:
|
85
102
|
|
86
103
|
Multidb.use(:slave) do
|
data/lib/multidb/balancer.rb
CHANGED
@@ -28,6 +28,11 @@ module Multidb
|
|
28
28
|
databases.each_pair do |name, config|
|
29
29
|
configs = config.is_a?(Array) ? config : [config]
|
30
30
|
configs.each do |config|
|
31
|
+
if config["alias"]
|
32
|
+
@candidates[name] = @candidates[config["alias"]]
|
33
|
+
next
|
34
|
+
end
|
35
|
+
|
31
36
|
candidate = Candidate.new(name, @default_configuration.default_adapter.merge(config))
|
32
37
|
@candidates[name] ||= []
|
33
38
|
@candidates[name].push(candidate)
|
data/lib/multidb/version.rb
CHANGED
data/spec/balancer_spec.rb
CHANGED
@@ -134,6 +134,11 @@ describe 'Multidb.balancer' do
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
+
it 'returns the parent connection for aliases' do
|
138
|
+
Multidb.use(:slave1).should_not eq Multidb.use(:slave_alias)
|
139
|
+
Multidb.use(:slave2).should eq Multidb.use(:slave_alias)
|
140
|
+
end
|
141
|
+
|
137
142
|
it 'returns random candidate' do
|
138
143
|
names = []
|
139
144
|
100.times do
|
@@ -151,4 +156,4 @@ describe 'Multidb.balancer' do
|
|
151
156
|
end
|
152
157
|
end
|
153
158
|
|
154
|
-
end
|
159
|
+
end
|
data/spec/helpers.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-multidb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Staubo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -102,6 +102,7 @@ extra_rdoc_files: []
|
|
102
102
|
files:
|
103
103
|
- ".gitignore"
|
104
104
|
- ".travis.yml"
|
105
|
+
- CHANGELOG.md
|
105
106
|
- Gemfile
|
106
107
|
- LICENSE
|
107
108
|
- README.markdown
|
@@ -138,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
139
|
- !ruby/object:Gem::Version
|
139
140
|
version: '0'
|
140
141
|
requirements: []
|
141
|
-
|
142
|
-
rubygems_version: 2.7.8
|
142
|
+
rubygems_version: 3.0.6
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: Multidb is an ActiveRecord extension for switching between multiple database
|