fresh_connection 3.1.0 → 3.1.2

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: d21ad20eb5180bd0bfd7c7e4ec352328e73f4be954215aa49ea7056442738490
4
- data.tar.gz: 0f7acb28bd1c0fb738491036aa617e43ea0d994fef71d7151d0b977bbd9a28e8
3
+ metadata.gz: 3f15cd68e1c698b44827e12a246e2b54c363c307551bdf989c6bd15af4c2e6d6
4
+ data.tar.gz: 29058a7c1d77d83d234f994efde8f0184141179f067b20efb68fa7bcd307e03c
5
5
  SHA512:
6
- metadata.gz: 70d6f0fbb318ac1687e2ac2fe915c213fd25403f2938aa43037c0aa9bc618a29eaeb0806638390778b364ab7b8dde3488bd5f380cd31fd3ce68a04005793ddd8
7
- data.tar.gz: 820751f83fb8f143c700ad6073a72ee2d7427a9e907984c7afe7ed970d90bee40d913550c5f95ce3baff6e1fc3efd3388d6ff93d49039fda7ff206cc0fa84f1c
6
+ metadata.gz: 0e5a49b982a85d70348365fec1c238bb6cb90fde0a65592187790c7eec4c178046be9a0ca94dfb825172d92502e3893903e98b62a7a6af7cb5fb1d560c24f465
7
+ data.tar.gz: 3f454242af3b8e29dafd8fff2a9e4504cc220893b06c564192cfeb27c8b465d35280fc3ffd252191bfc1e9606c4df252e5e445a967fbc2688b8efdd778608469
data/.travis.yml CHANGED
@@ -6,14 +6,19 @@ before_install:
6
6
  - gem update --system
7
7
  - gem --version
8
8
  rvm:
9
- - 2.5.8
10
- - 2.6.6
11
- - 2.7.1
9
+ - 2.6.9
10
+ - 2.7.5
11
+ - 3.0.3
12
12
  gemfile:
13
13
  - gemfiles/rails52.gemfile
14
14
  - gemfiles/rails60.gemfile
15
+ - gemfiles/rails61.gemfile
15
16
  script:
16
17
  - "bin/test"
17
18
  matrix:
18
19
  fast_finish: true
20
+ exclude:
21
+ - rvm: 3.0.3
22
+ gemfile: gemfiles/rails52.gemfile
23
+
19
24
  bundler_args: --jobs 3 --retry 3
data/Appraisals CHANGED
@@ -6,3 +6,7 @@ end
6
6
  appraise "rails60" do
7
7
  gem 'activerecord', '~> 6.0.0'
8
8
  end
9
+
10
+ appraise "rails61" do
11
+ gem 'activerecord', '~> 6.1.0'
12
+ end
data/README.md CHANGED
@@ -139,6 +139,9 @@ production:
139
139
 
140
140
  `replica` is the configuration used for connecting read-only queries to the database replica. All other connections will use the database master settings.
141
141
 
142
+ **NOTE:**
143
+ The 'replica' stanza has a special meaning in Rails6.
144
+ In Rails6, use a name other than 'replica', and specify that name using establish_fresh_connection in ApplicationRecord etc.
142
145
 
143
146
  ### Multiple DB Replicas
144
147
  If you want to use multiple configured DB replicas, the configuration can contain multiple `replica` stanzas in the configuration file `config/database.yml`.
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency 'activerecord', '>= 5.2.0', '< 6.1'
22
+ spec.add_dependency 'activerecord', '>= 5.2.0', '< 7.0'
23
23
 
24
24
  spec.add_development_dependency 'mysql2', '>= 0.4.4'
25
25
  spec.add_development_dependency 'pg', '>= 0.18', '< 2.0'
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FreshConnection
4
+ class ConnectionSpecification
5
+ module Rails60
6
+ def spec
7
+ ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(config_with_spec_name).spec(@spec_name.to_sym)
8
+ end
9
+
10
+ private
11
+
12
+ def config_with_spec_name
13
+ if defined?(ActiveRecord::DatabaseConfigurations)
14
+ ActiveRecord::DatabaseConfigurations.new(@spec_name => build_config)
15
+ else
16
+ { @spec_name => build_config }
17
+ end
18
+ end
19
+
20
+ def config_from_url
21
+ ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(database_group_url).to_hash
22
+ end
23
+
24
+ def base_config
25
+ ActiveRecord::Base.connection_pool.spec.config
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FreshConnection
4
+ class ConnectionSpecification
5
+ module Rails61
6
+ def spec
7
+ db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@spec_name.to_sym, ActiveRecord::Base.connection_pool.db_config.name, build_config)
8
+ ActiveRecord::ConnectionAdapters::PoolConfig.new(ActiveRecord::Base, db_config)
9
+ end
10
+
11
+ private
12
+
13
+ def config_from_url
14
+ ActiveRecord::DatabaseConfigurations::ConnectionUrlResolver.new(database_group_url).to_hash
15
+ end
16
+
17
+ def base_config
18
+ ActiveRecord::Base.connection_pool.db_config.configuration_hash
19
+ end
20
+ end
21
+ end
22
+ end
@@ -9,16 +9,8 @@ module FreshConnection
9
9
  @modify_spec = modify_spec.with_indifferent_access if modify_spec
10
10
  end
11
11
 
12
- def spec
13
- resolver.spec(@spec_name.to_sym)
14
- end
15
-
16
12
  private
17
13
 
18
- def resolver
19
- ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(build_config)
20
- end
21
-
22
14
  def build_config
23
15
  config = base_config.with_indifferent_access
24
16
 
@@ -27,11 +19,7 @@ module FreshConnection
27
19
 
28
20
  config = config.merge(@modify_spec) if defined?(@modify_spec)
29
21
 
30
- if defined?(ActiveRecord::DatabaseConfigurations)
31
- ActiveRecord::DatabaseConfigurations.new(@spec_name => config)
32
- else
33
- { @spec_name => config }
34
- end
22
+ config
35
23
  end
36
24
 
37
25
  def replica_config(config)
@@ -42,14 +30,6 @@ module FreshConnection
42
30
  end
43
31
  end
44
32
 
45
- def config_from_url
46
- ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(database_group_url).to_hash
47
- end
48
-
49
- def base_config
50
- ActiveRecord::Base.connection_pool.spec.config
51
- end
52
-
53
33
  def database_group_url
54
34
  ENV["DATABASE_#{@spec_name.upcase}_URL"]
55
35
  end
@@ -12,11 +12,11 @@ module FreshConnection
12
12
  super
13
13
  end
14
14
 
15
- def select_all(*args)
15
+ def select_all(*, **)
16
16
  __change_connection { super }
17
17
  end
18
18
 
19
- def select_value(*args)
19
+ def select_value(*)
20
20
  __change_connection { super }
21
21
  end
22
22
 
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FreshConnection
4
+ module Extend
5
+ module ArConnectionHandler
6
+ private def resolve_pool_config(*args)
7
+ pool_config = super
8
+
9
+ case pool_config.db_config.adapter.to_s
10
+ when "mysql", "mysql2"
11
+ require 'fresh_connection/extend/adapters/m2_adapter'
12
+ __extend_adapter_by_fc(::ActiveRecord::ConnectionAdapters::Mysql2Adapter, M2Adapter)
13
+ when "postgresql"
14
+ require 'fresh_connection/extend/adapters/pg_adapter'
15
+ __extend_adapter_by_fc(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, PgAdapter)
16
+ else
17
+ raise NotImplementedError, "This adapter('#{pool_config.db_config.adapter}') is not supported. If you specified the mysql or postgres adapter, it's probably a bug in FreshConnection. Please teach me (https://github.com/tsukasaoishi/fresh_connection/issues/new)"
18
+ end
19
+
20
+ pool_config
21
+ end
22
+
23
+ def __extend_adapter_by_fc(klass, extend_adapter)
24
+ return if klass.include?(extend_adapter)
25
+ klass.prepend BaseAdapter
26
+ klass.prepend extend_adapter
27
+ end
28
+ end
29
+ end
30
+ end
@@ -3,15 +3,15 @@
3
3
  module FreshConnection
4
4
  module Extend
5
5
  module ArRelation
6
- def calculate(*args)
6
+ def calculate(*)
7
7
  manage_access { super }
8
8
  end
9
9
 
10
- def exists?(*args)
10
+ def exists?(*)
11
11
  manage_access { super }
12
12
  end
13
13
 
14
- def pluck(*args)
14
+ def pluck(*)
15
15
  manage_access { super }
16
16
  end
17
17
 
@@ -10,13 +10,31 @@ ActiveSupport.on_load(:active_record) do
10
10
  require 'fresh_connection/extend/ar_relation'
11
11
  require 'fresh_connection/extend/ar_relation_merger'
12
12
  require 'fresh_connection/extend/ar_statement_cache'
13
- require 'fresh_connection/extend/ar_resolver'
14
13
 
15
14
  ActiveRecord::Base.extend FreshConnection::Extend::ArBase
16
15
  ActiveRecord::Relation.prepend FreshConnection::Extend::ArRelation
17
16
  ActiveRecord::Relation::Merger.prepend FreshConnection::Extend::ArRelationMerger
18
17
  ActiveRecord::StatementCache.prepend FreshConnection::Extend::ArStatementCache
19
- ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.prepend(
20
- FreshConnection::Extend::ArResolver
21
- )
18
+
19
+ if ActiveRecord::VERSION::MAJOR == 6 && ActiveRecord::VERSION::MINOR == 1
20
+ require 'fresh_connection/extend/ar_connection_handler'
21
+ ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(
22
+ FreshConnection::Extend::ArConnectionHandler
23
+ )
24
+
25
+ require 'fresh_connection/connection_specification/rails_61'
26
+ FreshConnection::ConnectionSpecification.include(
27
+ FreshConnection::ConnectionSpecification::Rails61
28
+ )
29
+ else
30
+ require 'fresh_connection/extend/ar_resolver'
31
+ ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.prepend(
32
+ FreshConnection::Extend::ArResolver
33
+ )
34
+
35
+ require 'fresh_connection/connection_specification/rails_60'
36
+ FreshConnection::ConnectionSpecification.include(
37
+ FreshConnection::ConnectionSpecification::Rails60
38
+ )
39
+ end
22
40
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FreshConnection
4
- VERSION = "3.1.0"
4
+ VERSION = "3.1.2"
5
5
  end
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fresh_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tsukasa OISHI
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-02 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 5.2.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.1'
22
+ version: '7.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 5.2.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: '7.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: mysql2
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -156,17 +156,21 @@ files:
156
156
  - fresh_connection.gemspec
157
157
  - gemfiles/rails52.gemfile
158
158
  - gemfiles/rails60.gemfile
159
+ - gemfiles/rails61.gemfile
159
160
  - lib/fresh_connection.rb
160
161
  - lib/fresh_connection/abstract_connection_manager.rb
161
162
  - lib/fresh_connection/access_control.rb
162
163
  - lib/fresh_connection/connection_manager.rb
163
164
  - lib/fresh_connection/connection_specification.rb
165
+ - lib/fresh_connection/connection_specification/rails_60.rb
166
+ - lib/fresh_connection/connection_specification/rails_61.rb
164
167
  - lib/fresh_connection/executor_hook.rb
165
168
  - lib/fresh_connection/extend.rb
166
169
  - lib/fresh_connection/extend/adapters/base_adapter.rb
167
170
  - lib/fresh_connection/extend/adapters/m2_adapter.rb
168
171
  - lib/fresh_connection/extend/adapters/pg_adapter.rb
169
172
  - lib/fresh_connection/extend/ar_base.rb
173
+ - lib/fresh_connection/extend/ar_connection_handler.rb
170
174
  - lib/fresh_connection/extend/ar_relation.rb
171
175
  - lib/fresh_connection/extend/ar_relation_merger.rb
172
176
  - lib/fresh_connection/extend/ar_resolver.rb
@@ -179,7 +183,7 @@ homepage: https://github.com/tsukasaoishi/fresh_connection
179
183
  licenses:
180
184
  - MIT
181
185
  metadata: {}
182
- post_install_message:
186
+ post_install_message:
183
187
  rdoc_options: []
184
188
  require_paths:
185
189
  - lib
@@ -194,8 +198,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
198
  - !ruby/object:Gem::Version
195
199
  version: '0'
196
200
  requirements: []
197
- rubygems_version: 3.1.2
198
- signing_key:
201
+ rubygems_version: 3.2.15
202
+ signing_key:
199
203
  specification_version: 4
200
204
  summary: FreshConnection supports connections with configured replica servers.
201
205
  test_files: []