rails-sharding 1.0.5 → 1.1.0

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
  SHA1:
3
- metadata.gz: 9fbf5cc3247b1d2a9046f4029dc1bd4c5e54e3c5
4
- data.tar.gz: f53f4bdcb282c4302173c1373925dbea133e734e
3
+ metadata.gz: 9f4f44b9e47e25d00cce1cd88897d85750be2465
4
+ data.tar.gz: c84a17b9c9a59fd471e627c0784450cba5930451
5
5
  SHA512:
6
- metadata.gz: 4b2d608de33eb59b96de0ceef6336892276cb5a302c9be6f4566dd005e90da39fa54e87e9042af7402ebdaaaa6aa2b3c03f6ded5f17e4035c22eecf4bf0dd454
7
- data.tar.gz: a9c137e16bc54ebd5660cb8fab6ad8398bec2f1b4edbf6c9af10232515f4b5e90079e4b48bc56edabc0f6ce84d7596efe8c8525031596292f9d4ef7e592f2623
6
+ metadata.gz: 113d4ba656d6ff072c81a116141cc4b7057d914fa64f9ccf00f64e4a0a08b062e4fde0b388216143ef5c5ba378c564b90fb2615b7d765683901d9d335b7ca28a
7
+ data.tar.gz: edda93d0db35871a3dd1b2cc0a95838112dfa928da60e925ae98f7d4467e298112907a6d3b800fc7267a9d0d41d8ee5a3d68d5433f629748e6dbad1b7dacf049
@@ -26,13 +26,30 @@ module Rails::Sharding
26
26
 
27
27
  resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(shard_group_configurations)
28
28
  begin
29
+ connection_spec = resolver.spec(shard_name.to_sym)
30
+
31
+ # since Rails 5.1 connection_spec already comes with :name set to whatever
32
+ # key you used to retrieve it from the resolver, in this case the shard_name.
33
+ # We don't want that, so we overwrite it with our connection name formed
34
+ # by shard_group:shard_name
29
35
  connection_name = connection_name(shard_group, shard_name)
30
- connection_spec = resolver.spec(shard_name.to_sym, connection_name)
36
+ connection_spec.instance_variable_set(:@name, connection_name)
31
37
  rescue ActiveRecord::AdapterNotSpecified
32
- raise Errors::ConfigNotFoundError, "Cannot find configuration for shard '#{shard_group}:#{shard_name}' in environment '#{environment}' in #{Config.shards_config_file}"
38
+ raise Errors::ConfigNotFoundError, "Cannot find configuration for shard '#{shard_group}:#{shard_name}' in environment '#{environment}' in #{Config.shards_config_file}, or it does not specify :adapter"
33
39
  end
34
40
 
35
- connection_handler.establish_connection(connection_spec)
41
+ # Since Rails 5.1 we cannot use connection_handler.establish_connection anymore,
42
+ # because it does more than establishing_connection. It does a second
43
+ # connection specification lookup on Base.configurations (where our spec
44
+ # is not, because we define it in a shards.yml instead of the regular
45
+ # database.yml) and it notifies subscribers of a event that does not concern
46
+ # us. Because of this we directly create the connection_pool and inject to
47
+ # the handler.
48
+ # Note: we should consider writting our connection handler from scratch, since
49
+ # it has become simpler than reusing the one from rails. And it will not break
50
+ # as long as the ConnectionPool interface is stable.
51
+ connection_handler.remove_connection(connection_spec.name)
52
+ connection_handler.send(:owner_to_pool)[connection_spec.name] = ActiveRecord::ConnectionAdapters::ConnectionPool.new(connection_spec)
36
53
  end
37
54
 
38
55
  def self.connection_pool(shard_group, shard_name)
@@ -111,7 +128,7 @@ module Rails::Sharding
111
128
  class << connection
112
129
  def log(sql, name="SQL", binds=[], type_casted_binds=[], statement_name=nil, &block)
113
130
  name = (name.to_s + " (#{shard_tag})").strip
114
- self.original_log(sql, name, binds, type_casted_binds, statement_name, &block)
131
+ original_log(sql, name, binds, type_casted_binds, statement_name, &block)
115
132
  end
116
133
  end
117
134
 
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Sharding
3
- VERSION = "1.0.5"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_runtime_dependency 'rails', '~> 5.0.0'
26
+ spec.add_runtime_dependency 'rails', '~> 5.1.0'
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.15"
29
29
  spec.add_development_dependency "rake", "~> 12.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-sharding
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Gubert
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0
19
+ version: 5.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.0
26
+ version: 5.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement