fresh_connection 3.0.3 → 3.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
  SHA256:
3
- metadata.gz: a42d31d4d7dd4dff53494ddcb9e0b79162c4b4e0dd21dcbb49f58de3eb16de8a
4
- data.tar.gz: eeb1e26a61e73dc041b9e1e41722eb98bd509a0eac919033353c941a8a4fd7b0
3
+ metadata.gz: d21ad20eb5180bd0bfd7c7e4ec352328e73f4be954215aa49ea7056442738490
4
+ data.tar.gz: 0f7acb28bd1c0fb738491036aa617e43ea0d994fef71d7151d0b977bbd9a28e8
5
5
  SHA512:
6
- metadata.gz: dad510ed81c9a392cdecad5d30a1183bf21df98d82be8b3f6a8828a5d88ea507cd0bcf0fe49d43ae00bb7d32ad9ebf027d759a2276c9561f45dc66bef6ee4533
7
- data.tar.gz: a9983d1bb6cb5f71ca75da62d05d49a09ef1a2105ca07990a16a5a4b89bbdb7f7e27fc4ad068914e8c9f5ccff9d1b55f1dde2e78c9c734be234d8a1d3375663f
6
+ metadata.gz: 70d6f0fbb318ac1687e2ac2fe915c213fd25403f2938aa43037c0aa9bc618a29eaeb0806638390778b364ab7b8dde3488bd5f380cd31fd3ce68a04005793ddd8
7
+ data.tar.gz: 820751f83fb8f143c700ad6073a72ee2d7427a9e907984c7afe7ed970d90bee40d913550c5f95ce3baff6e1fc3efd3388d6ff93d49039fda7ff206cc0fa84f1c
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ Gemfile.lock
5
5
  gemfiles/*.lock
6
6
  log/*
7
7
  .*.sw[a-z]
8
+ /bin/test_local
@@ -2,22 +2,18 @@ language: ruby
2
2
  services:
3
3
  - mysql
4
4
  - postgresql
5
- before_script:
6
- - bundle update
7
- - cp test/config/database_postgresql.yml.travis test/config/database_postgresql.yml
8
- - psql -c 'create database fresh_connection_test_master;' -U postgres
9
- - psql -c 'create database fresh_connection_test_replica1;' -U postgres
10
- - psql -c 'create database fresh_connection_test_replica2;' -U postgres
11
- cache: bundler
5
+ before_install:
6
+ - gem update --system
7
+ - gem --version
12
8
  rvm:
13
- - 2.3.8
14
- - 2.4.5
15
- - 2.5.3
16
- - 2.6.0
9
+ - 2.5.8
10
+ - 2.6.6
11
+ - 2.7.1
17
12
  gemfile:
18
- - gemfiles/rails50.gemfile
19
- - gemfiles/rails51.gemfile
20
13
  - gemfiles/rails52.gemfile
14
+ - gemfiles/rails60.gemfile
15
+ script:
16
+ - "bin/test"
21
17
  matrix:
22
18
  fast_finish: true
23
19
  bundler_args: --jobs 3 --retry 3
data/Appraisals CHANGED
@@ -1,20 +1,8 @@
1
- appraise "rails50" do
2
- gem 'activerecord', '~> 5.0.0'
3
- gem 'activesupport', '~> 5.0.0'
4
- gem 'mysql2', '>= 0.3.18', '< 0.6.0'
5
- gem 'pg', '>= 0.18', '< 2.0'
6
- end
7
-
8
- appraise "rails51" do
9
- gem 'activerecord', '~> 5.1.0'
10
- gem 'activesupport', '~> 5.1.0'
11
- gem 'mysql2', '>= 0.3.18', '< 0.6.0'
12
- gem 'pg', '>= 0.18', '< 2.0'
13
- end
14
-
15
1
  appraise "rails52" do
16
2
  gem 'activerecord', '~> 5.2.0'
17
- gem 'activesupport', '~> 5.2.0'
18
- gem 'mysql2', '>= 0.4.4', '< 0.6.0'
19
- gem 'pg', '>= 0.18', '< 2.0'
3
+ gem 'mysql2', '>= 0.4.4', "< 0.6.0"
4
+ end
5
+
6
+ appraise "rails60" do
7
+ gem 'activerecord', '~> 6.0.0'
20
8
  end
data/README.md CHANGED
@@ -29,8 +29,6 @@ FreshConnction connects one or more configured DB replicas, or with multiple rep
29
29
  - Write queries go to the DB master.
30
30
  - Within a transaction, all queries go to the DB master.
31
31
 
32
- If you wish to use multiple DB replicas on any given connection but do not have a load balancer (such as [`pgbouncer`](https://pgbouncer.github.io) for Posgres databases), you can use [EbisuConnection](https://github.com/tsukasaoishi/ebisu_connection).
33
-
34
32
  ### Failover
35
33
  FreshConnection assumes that there is a load balancer in front of multi replica servers.
36
34
  When what happens one of the replicas is unreachable for any reason, FreshConnection will try three retries to access to a replica via a load balancer.
@@ -80,8 +78,12 @@ old_article.destroy
80
78
 
81
79
  ## ActiveRecord Versions Supported
82
80
 
83
- - FreshConnection supports ActiveRecord version 5.0 or later.
84
- - If you are using Rails 4.2, you can use FreshConnection version 2.4.4 or before.
81
+ - FreshConnection supports ActiveRecord version 5.2 or later.
82
+ - If you are using Rails 5.1, you can use FreshConnection version 3.0.3 or before.
83
+
84
+ ### Not Support Multiple Database
85
+ I haven't tested it in an environment using MultipleDB in Rails 6.
86
+ I plan to enable use with MultipleDB in FreshConnection version 4.0 or later.
85
87
 
86
88
  ## Databases Supported
87
89
  FreshConnection currently supports MySQL and PostgreSQL.
data/Rakefile CHANGED
@@ -1,20 +1,13 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rake/testtask'
3
3
 
4
- desc 'Run mysql2 and postgresql tests'
4
+ desc 'Run tests'
5
5
  task :test do
6
- Rake::Task["test:mysql2"].invoke
7
- Rake::Task["test:postgresql"].invoke
8
- end
9
-
10
- namespace :test do
11
- %w(mysql2 postgresql).each do |test_name|
12
- Rake::TestTask.new(test_name) do |t|
13
- t.libs << "test"
14
- t.libs << "lib"
15
- t.test_files = FileList["test/config/prepare_#{test_name}", 'test/**/*_test.rb']
16
- t.verbose = true
17
- end
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ t.verbose = true
18
11
  end
19
12
  end
20
13
 
data/bin/setup CHANGED
@@ -3,7 +3,8 @@ set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
- bundle install --path .bundle
6
+ bundle config set path '.bundle'
7
+ bundle install
7
8
  bundle exec appraisal install
8
9
 
9
10
  # Do any other automated setup that you need to do here
data/bin/test CHANGED
@@ -2,16 +2,23 @@
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
 
5
- for dbname in fresh_connection_test_master fresh_connection_test_replica1 fresh_connection_test_replica2 ; do
6
- if ! psql $dbname -c '\q' 2>/dev/null ; then
7
- if [[ -n "`psql -l | grep \"$dbname\"`" ]]; then
8
- echo "Dropping database $dbname .."
9
- dropdb $dbname
10
- fi
11
- echo "Creating database $dbname .."
12
- createdb $dbname
13
- fi
14
- done
15
-
16
5
  set -vx
17
- bundle exec appraisal rake test
6
+
7
+ if [ -v DATABASE_URL ]; then
8
+ echo "[specified config]"
9
+ bundle exec rake test
10
+ else
11
+ echo "[mysql]"
12
+ DATABASE_URL="mysql2://root@localhost/fresh_connection_test_master" \
13
+ DATABASE_REPLICA1_URL="mysql2://root@localhost/fresh_connection_test_replica1" \
14
+ DATABASE_REPLICA2_URL="mysql2://root@localhost/fresh_connection_test_replica2" \
15
+ DATABASE_FAKE_REPLICA_URL="mysql2://root@localhost/fresh_connection_test_master" \
16
+ bundle exec rake test
17
+
18
+ echo "[postgresql]"
19
+ DATABASE_URL="postgresql://localhost/fresh_connection_test_master" \
20
+ DATABASE_REPLICA1_URL="postgresql://localhost/fresh_connection_test_replica1" \
21
+ DATABASE_REPLICA2_URL="postgresql://localhost/fresh_connection_test_replica2" \
22
+ DATABASE_FAKE_REPLICA_URL="postgresql://localhost/fresh_connection_test_master" \
23
+ bundle exec rake test
24
+ fi
@@ -19,16 +19,11 @@ 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.required_ruby_version = '>= 2.2'
22
+ spec.add_dependency 'activerecord', '>= 5.2.0', '< 6.1'
23
23
 
24
- spec.add_dependency 'activerecord', '>= 5.0.0', '< 5.3'
25
- spec.add_dependency 'activesupport', '>= 5.0.0', '< 5.3'
26
- spec.add_dependency 'concurrent-ruby', '~> 1.0'
27
-
28
- spec.add_development_dependency 'mysql2', '>= 0.3.18', '< 0.6.0'
24
+ spec.add_development_dependency 'mysql2', '>= 0.4.4'
29
25
  spec.add_development_dependency 'pg', '>= 0.18', '< 2.0'
30
- spec.add_development_dependency "bundler", ">= 1.3.0", "< 2.0"
31
- spec.add_development_dependency "rake", ">= 0.8.7"
26
+ spec.add_development_dependency "rake"
32
27
  spec.add_development_dependency 'appraisal'
33
28
  spec.add_development_dependency "minitest", "~> 5.10.0"
34
29
  spec.add_development_dependency "minitest-reporters"
@@ -3,8 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.2.0"
6
- gem "activesupport", "~> 5.2.0"
7
6
  gem "mysql2", ">= 0.4.4", "< 0.6.0"
8
- gem "pg", ">= 0.18", "< 2.0"
9
7
 
10
8
  gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.0"
6
+
7
+ gemspec path: "../"
@@ -15,10 +15,6 @@ module FreshConnection
15
15
  FreshConnection::ReplicaConnectionHandler.instance.refresh_all
16
16
  @connection_manager = mgr
17
17
  end
18
-
19
- def rails_52?
20
- [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2]
21
- end
22
18
  end
23
19
  end
24
20
 
@@ -16,7 +16,7 @@ module FreshConnection
16
16
  private
17
17
 
18
18
  def resolver
19
- ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(@spec_name => build_config)
19
+ ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(build_config)
20
20
  end
21
21
 
22
22
  def build_config
@@ -26,7 +26,12 @@ module FreshConnection
26
26
  config = config.merge(s_config) if s_config
27
27
 
28
28
  config = config.merge(@modify_spec) if defined?(@modify_spec)
29
- config
29
+
30
+ if defined?(ActiveRecord::DatabaseConfigurations)
31
+ ActiveRecord::DatabaseConfigurations.new(@spec_name => config)
32
+ else
33
+ { @spec_name => config }
34
+ end
30
35
  end
31
36
 
32
37
  def replica_config(config)
@@ -2,6 +2,10 @@
2
2
  require 'active_support'
3
3
 
4
4
  ActiveSupport.on_load(:active_record) do
5
+ if respond_to?(:connection_handlers) && connection_handlers.empty?
6
+ self.connection_handlers = { writing_role => ActiveRecord::Base.default_connection_handler }
7
+ end
8
+
5
9
  require 'fresh_connection/extend/ar_base'
6
10
  require 'fresh_connection/extend/ar_relation'
7
11
  require 'fresh_connection/extend/ar_relation_merger'
@@ -3,14 +3,8 @@
3
3
  module FreshConnection
4
4
  module Extend
5
5
  module ArStatementCache
6
- if FreshConnection.rails_52?
7
- def execute(params, connection, &block)
8
- klass.all.manage_access { super }
9
- end
10
- else
11
- def execute(params, klass, connection, &block)
12
- klass.all.manage_access { super }
13
- end
6
+ def execute(params, connection, &block)
7
+ klass.all.manage_access { super }
14
8
  end
15
9
  end
16
10
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FreshConnection
4
- VERSION = "3.0.3"
4
+ VERSION = "3.1.0"
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.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tsukasa OISHI
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-04 00:00:00.000000000 Z
11
+ date: 2020-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,74 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0
19
+ version: 5.2.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.3'
22
+ version: '6.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 5.0.0
29
+ version: 5.2.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.3'
33
- - !ruby/object:Gem::Dependency
34
- name: activesupport
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 5.0.0
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '5.3'
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 5.0.0
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '5.3'
53
- - !ruby/object:Gem::Dependency
54
- name: concurrent-ruby
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '1.0'
60
- type: :runtime
61
- prerelease: false
62
- version_requirements: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '1.0'
32
+ version: '6.1'
67
33
  - !ruby/object:Gem::Dependency
68
34
  name: mysql2
69
35
  requirement: !ruby/object:Gem::Requirement
70
36
  requirements:
71
37
  - - ">="
72
38
  - !ruby/object:Gem::Version
73
- version: 0.3.18
74
- - - "<"
75
- - !ruby/object:Gem::Version
76
- version: 0.6.0
39
+ version: 0.4.4
77
40
  type: :development
78
41
  prerelease: false
79
42
  version_requirements: !ruby/object:Gem::Requirement
80
43
  requirements:
81
44
  - - ">="
82
45
  - !ruby/object:Gem::Version
83
- version: 0.3.18
84
- - - "<"
85
- - !ruby/object:Gem::Version
86
- version: 0.6.0
46
+ version: 0.4.4
87
47
  - !ruby/object:Gem::Dependency
88
48
  name: pg
89
49
  requirement: !ruby/object:Gem::Requirement
@@ -104,40 +64,20 @@ dependencies:
104
64
  - - "<"
105
65
  - !ruby/object:Gem::Version
106
66
  version: '2.0'
107
- - !ruby/object:Gem::Dependency
108
- name: bundler
109
- requirement: !ruby/object:Gem::Requirement
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- version: 1.3.0
114
- - - "<"
115
- - !ruby/object:Gem::Version
116
- version: '2.0'
117
- type: :development
118
- prerelease: false
119
- version_requirements: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: 1.3.0
124
- - - "<"
125
- - !ruby/object:Gem::Version
126
- version: '2.0'
127
67
  - !ruby/object:Gem::Dependency
128
68
  name: rake
129
69
  requirement: !ruby/object:Gem::Requirement
130
70
  requirements:
131
71
  - - ">="
132
72
  - !ruby/object:Gem::Version
133
- version: 0.8.7
73
+ version: '0'
134
74
  type: :development
135
75
  prerelease: false
136
76
  version_requirements: !ruby/object:Gem::Requirement
137
77
  requirements:
138
78
  - - ">="
139
79
  - !ruby/object:Gem::Version
140
- version: 0.8.7
80
+ version: '0'
141
81
  - !ruby/object:Gem::Dependency
142
82
  name: appraisal
143
83
  requirement: !ruby/object:Gem::Requirement
@@ -214,9 +154,8 @@ files:
214
154
  - bin/setup
215
155
  - bin/test
216
156
  - fresh_connection.gemspec
217
- - gemfiles/rails50.gemfile
218
- - gemfiles/rails51.gemfile
219
157
  - gemfiles/rails52.gemfile
158
+ - gemfiles/rails60.gemfile
220
159
  - lib/fresh_connection.rb
221
160
  - lib/fresh_connection/abstract_connection_manager.rb
222
161
  - lib/fresh_connection/access_control.rb
@@ -248,15 +187,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
248
187
  requirements:
249
188
  - - ">="
250
189
  - !ruby/object:Gem::Version
251
- version: '2.2'
190
+ version: '0'
252
191
  required_rubygems_version: !ruby/object:Gem::Requirement
253
192
  requirements:
254
193
  - - ">="
255
194
  - !ruby/object:Gem::Version
256
195
  version: '0'
257
196
  requirements: []
258
- rubyforge_project:
259
- rubygems_version: 2.7.6
197
+ rubygems_version: 3.1.2
260
198
  signing_key:
261
199
  specification_version: 4
262
200
  summary: FreshConnection supports connections with configured replica servers.
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.0.0"
6
- gem "activesupport", "~> 5.0.0"
7
- gem "mysql2", ">= 0.3.18", "< 0.6.0"
8
- gem "pg", ">= 0.18", "< 2.0"
9
-
10
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.1.0"
6
- gem "activesupport", "~> 5.1.0"
7
- gem "mysql2", ">= 0.3.18", "< 0.6.0"
8
- gem "pg", ">= 0.18", "< 2.0"
9
-
10
- gemspec path: "../"