active_record_host_pool 0.6.5 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Readme.md +8 -7
- data/lib/active_record_host_pool/connection_adapter_mixin.rb +8 -2
- data/test/database.yml +7 -7
- data/test/helper.rb +1 -1
- data/test/test_arhp.rb +2 -2
- metadata +9 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3afb58583904ec2e606e050f1a2a13dff283d13e
|
4
|
+
data.tar.gz: 28250948075a9e1e29778b2fdd4a08075da2d4f7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30de25c6e3cc4f8caf0a1f89ed2d07eda70288e4860728190e8efdd0b82cb1b27010399d35c98465319099526bbe124672d05655f52b474c1bc6e13661eaa557
|
7
|
+
data.tar.gz: 11d9b5be51cae0d7e23924cf054a6baca3ba4a3ab1080b55b5a73a42213c094106b157d0ae55cb622d627f7627c3df5a3959d770791b429f93918c378cbb6f06
|
data/Readme.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://travis-ci.org/zendesk/active_record_host_pool)
|
2
|
+
|
1
3
|
# ActiveRecord host pooling
|
2
4
|
|
3
5
|
This gem allows for one ActiveRecord connection to be used to connect to multiple databases on a server.
|
@@ -5,9 +7,8 @@ It accomplishes this by calling select_db() as necessary to switch databases bet
|
|
5
7
|
|
6
8
|
## Support
|
7
9
|
|
8
|
-
For now, the only backend known to work is
|
9
|
-
Postgres, from an informal reading of the docs, will never support the concept of one
|
10
|
-
server connection sharing multiple dbs.
|
10
|
+
For now, the only backend known to work is MySQL, with the mysql2 gem.
|
11
|
+
Postgres, from an informal reading of the docs, will never support the concept of one server connection sharing multiple dbs.
|
11
12
|
|
12
13
|
## Installation
|
13
14
|
|
@@ -16,11 +17,11 @@ server connection sharing multiple dbs.
|
|
16
17
|
and make sure to require 'active\_record\_host\_pool' in some way.
|
17
18
|
|
18
19
|
## Testing
|
19
|
-
You need a local user called
|
20
|
+
You need a local user called 'travis'.
|
20
21
|
|
21
22
|
mysql -uroot
|
22
|
-
CREATE USER '
|
23
|
-
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX ON *.* TO '
|
23
|
+
CREATE USER 'travis'@'localhost';
|
24
|
+
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX ON *.* TO 'travis'@'localhost';
|
24
25
|
FLUSH PRIVILEGES;
|
25
26
|
|
26
27
|
## Copyright
|
@@ -28,5 +29,5 @@ You need a local user called snoopy.
|
|
28
29
|
Copyright (c) 2011 Zendesk. See MIT-LICENSE for details.
|
29
30
|
|
30
31
|
## Authors
|
31
|
-
Ben Osheroff <ben@gimbo.net>,
|
32
|
+
Ben Osheroff <ben@gimbo.net>,
|
32
33
|
Mick Staugaard <mick@staugaard.com>
|
@@ -79,10 +79,16 @@ module ActiveRecord
|
|
79
79
|
module ConnectionAdapters
|
80
80
|
class ConnectionHandler
|
81
81
|
def establish_connection(name, spec)
|
82
|
-
if
|
82
|
+
if ActiveRecord::VERSION::MAJOR >= 4
|
83
|
+
owner = name
|
84
|
+
|
85
|
+
@class_to_pool.clear
|
86
|
+
raise RuntimeError, "Anonymous class is not allowed." unless owner.name
|
87
|
+
owner_to_pool[owner.name] = ActiveRecordHostPool::PoolProxy.new(spec)
|
88
|
+
elsif ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 2
|
83
89
|
@connection_pools[spec] ||= ActiveRecordHostPool::PoolProxy.new(spec)
|
84
90
|
@class_to_pool[name] = @connection_pools[spec]
|
85
|
-
else
|
91
|
+
else
|
86
92
|
@connection_pools[name] = ActiveRecordHostPool::PoolProxy.new(spec)
|
87
93
|
end
|
88
94
|
end
|
data/test/database.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
test_host_1_db_1:
|
2
|
-
adapter:
|
2
|
+
adapter: mysql2
|
3
3
|
encoding: utf8
|
4
4
|
database: arhp_test_1
|
5
5
|
username: root
|
@@ -8,7 +8,7 @@ test_host_1_db_1:
|
|
8
8
|
reconnect: true
|
9
9
|
|
10
10
|
test_host_1_db_2:
|
11
|
-
adapter:
|
11
|
+
adapter: mysql2
|
12
12
|
encoding: utf8
|
13
13
|
database: arhp_test_2
|
14
14
|
username: root
|
@@ -17,7 +17,7 @@ test_host_1_db_2:
|
|
17
17
|
reconnect: true
|
18
18
|
|
19
19
|
test_host_2_db_3:
|
20
|
-
adapter:
|
20
|
+
adapter: mysql2
|
21
21
|
encoding: utf8
|
22
22
|
database: arhp_test_3
|
23
23
|
username: root
|
@@ -27,7 +27,7 @@ test_host_2_db_3:
|
|
27
27
|
reconnect: true
|
28
28
|
|
29
29
|
test_host_2_db_4:
|
30
|
-
adapter:
|
30
|
+
adapter: mysql2
|
31
31
|
encoding: utf8
|
32
32
|
database: arhp_test_4
|
33
33
|
username: root
|
@@ -37,17 +37,17 @@ test_host_2_db_4:
|
|
37
37
|
reconnect: true
|
38
38
|
|
39
39
|
test_host_2_db_5:
|
40
|
-
adapter:
|
40
|
+
adapter: mysql2
|
41
41
|
encoding: utf8
|
42
42
|
database: arhp_test_4
|
43
|
-
username:
|
43
|
+
username: travis
|
44
44
|
password:
|
45
45
|
host: 127.0.0.1
|
46
46
|
port: 3306
|
47
47
|
reconnect: true
|
48
48
|
|
49
49
|
test_host_1_db_not_there:
|
50
|
-
adapter:
|
50
|
+
adapter: mysql2
|
51
51
|
encoding: utf8
|
52
52
|
database: arhp_test_no_create
|
53
53
|
username: root
|
data/test/helper.rb
CHANGED
data/test/test_arhp.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('helper', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
class ActiveRecordHostPoolTest <
|
3
|
+
class ActiveRecordHostPoolTest < MiniTest::Unit::TestCase
|
4
4
|
include ARHPTestSetup
|
5
5
|
def setup
|
6
6
|
arhp_create_databases
|
@@ -97,7 +97,7 @@ class ActiveRecordHostPoolTest < Test::Unit::TestCase
|
|
97
97
|
|
98
98
|
# now, disable our auto-switching and trigger a mysql reconnect
|
99
99
|
switch_to_klass.connection.unproxied.stubs(:_switch_connection).returns(true)
|
100
|
-
|
100
|
+
Test3.connection.execute("KILL #{thread_id}")
|
101
101
|
|
102
102
|
# and finally, did mysql reconnect correctly?
|
103
103
|
puts "\nAnd now we end up on #{current_database(switch_to_klass)}" if debug_me
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_host_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.7.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ben Osheroff
|
@@ -14,17 +13,15 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: ''
|
@@ -36,12 +33,12 @@ extra_rdoc_files:
|
|
36
33
|
- MIT-LICENSE
|
37
34
|
- Readme.md
|
38
35
|
files:
|
36
|
+
- MIT-LICENSE
|
39
37
|
- Readme.md
|
40
38
|
- lib/active_record_host_pool.rb
|
41
39
|
- lib/active_record_host_pool/connection_adapter_mixin.rb
|
42
40
|
- lib/active_record_host_pool/connection_proxy.rb
|
43
41
|
- lib/active_record_host_pool/pool_proxy.rb
|
44
|
-
- MIT-LICENSE
|
45
42
|
- test/database.yml
|
46
43
|
- test/helper.rb
|
47
44
|
- test/schema.rb
|
@@ -49,27 +46,26 @@ files:
|
|
49
46
|
homepage: https://github.com/zendesk/active_record_host_pool
|
50
47
|
licenses:
|
51
48
|
- MIT
|
49
|
+
metadata: {}
|
52
50
|
post_install_message:
|
53
51
|
rdoc_options: []
|
54
52
|
require_paths:
|
55
53
|
- lib
|
56
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
55
|
requirements:
|
59
|
-
- -
|
56
|
+
- - ">="
|
60
57
|
- !ruby/object:Gem::Version
|
61
58
|
version: '0'
|
62
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
60
|
requirements:
|
65
|
-
- -
|
61
|
+
- - ">="
|
66
62
|
- !ruby/object:Gem::Version
|
67
63
|
version: '0'
|
68
64
|
requirements: []
|
69
65
|
rubyforge_project:
|
70
|
-
rubygems_version:
|
66
|
+
rubygems_version: 2.2.2
|
71
67
|
signing_key:
|
72
|
-
specification_version:
|
68
|
+
specification_version: 4
|
73
69
|
summary: Allow ActiveRecord to share a connection to multiple databases on the same
|
74
70
|
host
|
75
71
|
test_files:
|
@@ -77,4 +73,3 @@ test_files:
|
|
77
73
|
- test/helper.rb
|
78
74
|
- test/schema.rb
|
79
75
|
- test/test_arhp.rb
|
80
|
-
has_rdoc:
|