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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e055c742a6029415524f28349e3241360013adc1184666609ed854273b0bd0af
4
- data.tar.gz: dad603f9c611e867dfba0a83f2253cedbcfa5b20b75459d645105d9ed57c8faf
3
+ metadata.gz: 191bf9ea7a4823bd2c2148a13a3d7e19518233fafaac0be30aa1b018e50057ac
4
+ data.tar.gz: 0a722ce4f9289e9a1e8bf4c2200ef3243119fff97e570eb8787254f6d4f8aac2
5
5
  SHA512:
6
- metadata.gz: 80653278f75c95b67e5813c0307b26ff63e5796dd9371228911200ed532711370d7e48e6ec7d841ca59ba820e14843d15a7603099d5f20a451d3f03e3a4c54a9
7
- data.tar.gz: 11feb31f0e7aed8f9059a91a1da11393df366da7c7d3960a68704ae078dca92e520524a4f23eec7754210a09fac407bb5b449dca1b9dcf449d3b447590f6eb40
6
+ metadata.gz: 7d0da233e8c260b3e1893f1a259fc7014d49bc7fd17bc937c5f0436e6297af1cf794e56b611001a4670dd6a20fc7dc27359cb2ff41d26af5dd42d125b44ce03d
7
+ data.tar.gz: 3fa308aeb36f94c7717e46c6c1758a66609c278500ccf65141992fc0de0902293a2edfe2a6d358972b8a7dcd8c85784328770e9b2f43c670fe09b8b3558c0269
@@ -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
+
@@ -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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Multidb
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -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
@@ -14,7 +14,10 @@ multidb:
14
14
  slave3:
15
15
  - database: spec/test-slave3-1.sqlite
16
16
  - database: spec/test-slave3-2.sqlite
17
+ slave_alias:
18
+ database: spec/test-slave2.sqlite
19
+ alias: slave2
17
20
  end
18
21
  end
19
22
 
20
- end
23
+ end
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.0
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-01-15 00:00:00.000000000 Z
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
- rubyforge_project: ar-multidb
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