octoshark 0.3.0 → 0.4.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 +4 -4
- data/.github/workflows/build.yml +130 -0
- data/.ruby-version +1 -1
- data/Appraisals +6 -6
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -1
- data/gemfiles/rails7.0.gemfile +9 -0
- data/lib/octoshark/active_record_extensions.rb +20 -6
- data/lib/octoshark/connection_pools_manager.rb +47 -16
- data/lib/octoshark/version.rb +1 -1
- metadata +8 -8
- data/.github/workflows/ci-legacy.yml +0 -66
- data/.github/workflows/ci.yml +0 -64
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 73492e9db9cf09a361e5be45ffd95b3557e2bfa70ddb102c60631d72ffa69ad2
|
|
4
|
+
data.tar.gz: f12275deb8e0e43ccc0f8b4b91975fa84808d2481ffb5e6698b55fd888d72bda
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 03751f458070db1b198c4c5cf9820d1269308758fc950fc42126d5f75c321e77b411a1959d2da0de69432b5c5d35cbdeb8ec7f78f378fcc1e39c7220179937b2
|
|
7
|
+
data.tar.gz: 5d2f7ff3902769fcd8b838215e40f0b9bc53dc8333c57fb88588b79732f11bd186a6f711f621d56ae00b955f8a4adf3ec52fc6698813569fdd14e87279a6b2ae
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
name: Build
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- "*"
|
|
7
|
+
push:
|
|
8
|
+
branches:
|
|
9
|
+
- master
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
legacy:
|
|
13
|
+
runs-on: ubuntu-18.04
|
|
14
|
+
services:
|
|
15
|
+
mysql:
|
|
16
|
+
image: mysql:5.5
|
|
17
|
+
env:
|
|
18
|
+
MYSQL_ROOT_PASSWORD: pass
|
|
19
|
+
ports:
|
|
20
|
+
- "3306:3306"
|
|
21
|
+
options: >-
|
|
22
|
+
--health-cmd="mysqladmin ping"
|
|
23
|
+
--health-interval=10s
|
|
24
|
+
--health-timeout=5s
|
|
25
|
+
--health-retries=3
|
|
26
|
+
|
|
27
|
+
name: ruby-${{ matrix.ruby }} ${{ matrix.gemfile }}
|
|
28
|
+
strategy:
|
|
29
|
+
matrix:
|
|
30
|
+
include:
|
|
31
|
+
- gemfile: rails3.0
|
|
32
|
+
ruby: 2.4
|
|
33
|
+
- gemfile: rails3.1
|
|
34
|
+
ruby: 2.4
|
|
35
|
+
- gemfile: rails3.2
|
|
36
|
+
ruby: 2.4
|
|
37
|
+
|
|
38
|
+
- gemfile: rails4.0
|
|
39
|
+
ruby: 2.4
|
|
40
|
+
- gemfile: rails4.1
|
|
41
|
+
ruby: 2.4
|
|
42
|
+
- gemfile: rails4.2
|
|
43
|
+
ruby: 2.4
|
|
44
|
+
|
|
45
|
+
env:
|
|
46
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
|
47
|
+
BUNDLE_PATH_RELATIVE_TO_CWD: true
|
|
48
|
+
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@master
|
|
51
|
+
|
|
52
|
+
- name: Set up Ruby
|
|
53
|
+
uses: ruby/setup-ruby@v1
|
|
54
|
+
with:
|
|
55
|
+
ruby-version: ${{ matrix.ruby }}
|
|
56
|
+
bundler: default
|
|
57
|
+
bundler-cache: true
|
|
58
|
+
|
|
59
|
+
- name: Set up database
|
|
60
|
+
run: |
|
|
61
|
+
cp spec/support/config.yml.github spec/support/config.yml
|
|
62
|
+
bundle exec rake db:create
|
|
63
|
+
|
|
64
|
+
- name: Run tests
|
|
65
|
+
run: |
|
|
66
|
+
bundle exec rspec spec
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
latest:
|
|
70
|
+
runs-on: ubuntu-latest
|
|
71
|
+
services:
|
|
72
|
+
mysql:
|
|
73
|
+
image: mysql:5.7
|
|
74
|
+
env:
|
|
75
|
+
MYSQL_ROOT_PASSWORD: pass
|
|
76
|
+
ports:
|
|
77
|
+
- "3306:3306"
|
|
78
|
+
options: >-
|
|
79
|
+
--health-cmd="mysqladmin ping"
|
|
80
|
+
--health-interval=10s
|
|
81
|
+
--health-timeout=5s
|
|
82
|
+
--health-retries=3
|
|
83
|
+
|
|
84
|
+
name: ruby-${{ matrix.ruby }} ${{ matrix.gemfile }}
|
|
85
|
+
strategy:
|
|
86
|
+
matrix:
|
|
87
|
+
include:
|
|
88
|
+
- gemfile: rails5.0
|
|
89
|
+
ruby: 2.6
|
|
90
|
+
- gemfile: rails5.1
|
|
91
|
+
ruby: 2.6
|
|
92
|
+
- gemfile: rails5.2
|
|
93
|
+
ruby: 2.6
|
|
94
|
+
- gemfile: rails5.2
|
|
95
|
+
ruby: 3.0
|
|
96
|
+
|
|
97
|
+
- gemfile: rails6.0
|
|
98
|
+
ruby: 2.7
|
|
99
|
+
- gemfile: rails6.1
|
|
100
|
+
ruby: 2.7
|
|
101
|
+
- gemfile: rails6.1
|
|
102
|
+
ruby: 3.0
|
|
103
|
+
|
|
104
|
+
- gemfile: rails7.0
|
|
105
|
+
ruby: 2.7
|
|
106
|
+
- gemfile: rails7.0
|
|
107
|
+
ruby: 3.0
|
|
108
|
+
|
|
109
|
+
env:
|
|
110
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
|
111
|
+
BUNDLE_PATH_RELATIVE_TO_CWD: true
|
|
112
|
+
|
|
113
|
+
steps:
|
|
114
|
+
- uses: actions/checkout@master
|
|
115
|
+
|
|
116
|
+
- name: Set up Ruby
|
|
117
|
+
uses: ruby/setup-ruby@v1
|
|
118
|
+
with:
|
|
119
|
+
ruby-version: ${{ matrix.ruby }}
|
|
120
|
+
bundler: default
|
|
121
|
+
bundler-cache: true
|
|
122
|
+
|
|
123
|
+
- name: Set up database
|
|
124
|
+
run: |
|
|
125
|
+
cp spec/support/config.yml.github spec/support/config.yml
|
|
126
|
+
bundle exec rake db:create
|
|
127
|
+
|
|
128
|
+
- name: Run tests
|
|
129
|
+
run: |
|
|
130
|
+
bundle exec rspec spec
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3.0.2
|
data/Appraisals
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
appraise "rails5.0" do
|
|
2
|
-
gem "activerecord", "~> 5.0.0"
|
|
3
|
-
gem "mysql2", "~> 0.5.2"
|
|
4
|
-
gem "sqlite3", "~> 1.3.13"
|
|
5
|
-
end
|
|
6
|
-
|
|
7
1
|
appraise "rails5.1" do
|
|
8
2
|
gem "activerecord", "~> 5.1.0"
|
|
9
3
|
gem "mysql2", "~> 0.5.2"
|
|
@@ -27,3 +21,9 @@ appraise "rails6.1" do
|
|
|
27
21
|
gem "mysql2", "~> 0.5.2"
|
|
28
22
|
gem "sqlite3", "~> 1.4.1"
|
|
29
23
|
end
|
|
24
|
+
|
|
25
|
+
appraise "rails7.0" do
|
|
26
|
+
gem "activerecord", "~> 7.0.0"
|
|
27
|
+
gem "mysql2", "~> 0.5"
|
|
28
|
+
gem "sqlite3", "~> 1.4"
|
|
29
|
+
end
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
module Octoshark
|
|
2
2
|
module ConnectionHandler
|
|
3
|
+
# def establish_connection(owner, spec) # Rails 3.x
|
|
4
|
+
# def establish_connection(config_or_env = nil) # Rails 4.x - 6.1
|
|
5
|
+
# def establish_connection(config, owner_name:, role:, shard:) # Rails 6.2+
|
|
6
|
+
def establish_connection(*args, **kwargs)
|
|
7
|
+
Octoshark::ConnectionPoolsManager.reset_connection_managers!
|
|
8
|
+
|
|
9
|
+
if kwargs.empty?
|
|
10
|
+
# For backward compatibility with older versions of Rails on Ruby 3
|
|
11
|
+
# that separates positional (args) and keyword arguments (kwargs).
|
|
12
|
+
super(*args)
|
|
13
|
+
else
|
|
14
|
+
super(*args, **kwargs)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module ConnectionHandlerRails3
|
|
3
20
|
def establish_connection(*args)
|
|
4
21
|
Octoshark::ConnectionPoolsManager.reset_connection_managers!
|
|
5
22
|
super(*args)
|
|
@@ -19,13 +36,10 @@ module Octoshark
|
|
|
19
36
|
end
|
|
20
37
|
end
|
|
21
38
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
ActiveRecord::ConnectionAdapters::ConnectionHandler.send(:prepend, Octoshark::ConnectionHandler)
|
|
25
|
-
else
|
|
26
|
-
# Rails 3.0 and 3.1 does not lazy load
|
|
39
|
+
# Rails 3.0 and 3.1 does not lazy load
|
|
40
|
+
unless defined?(ActiveRecord::ConnectionAdapters::ConnectionHandler)
|
|
27
41
|
require 'active_record/connection_adapters/abstract_adapter'
|
|
28
|
-
ActiveRecord::ConnectionAdapters::ConnectionHandler.send(:prepend, Octoshark::ConnectionHandler)
|
|
29
42
|
end
|
|
30
43
|
|
|
44
|
+
ActiveRecord::ConnectionAdapters::ConnectionHandler.send(:prepend, Octoshark::ConnectionHandler)
|
|
31
45
|
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:prepend, Octoshark::ActiveRecordAbstractAdapter)
|
|
@@ -71,27 +71,58 @@ module Octoshark
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def create_connection_pool(name, config)
|
|
74
|
-
spec =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
spec = build_connection_pool_spec(name, config)
|
|
75
|
+
|
|
76
|
+
ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
private
|
|
80
|
+
|
|
81
|
+
def build_connection_pool_spec(name, config)
|
|
82
|
+
if active_record_6_1_or_7?
|
|
83
|
+
env_name = defined?(Rails) ? Rails.env : nil
|
|
84
|
+
db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(env_name, name, config)
|
|
85
|
+
|
|
86
|
+
pool_config_class = ActiveRecord::ConnectionAdapters::PoolConfig
|
|
87
|
+
|
|
88
|
+
if pool_config_class.instance_method(:initialize).arity == 2
|
|
89
|
+
# ActiveRecord 6.1
|
|
90
|
+
pool_config_class.new(owner_name = ActiveRecord::Base, db_config)
|
|
79
91
|
else
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
# ActiveRecord 7.0
|
|
93
|
+
pool_config_class.new(
|
|
94
|
+
owner_name = ActiveRecord::Base,
|
|
95
|
+
db_config,
|
|
96
|
+
role = ActiveRecord::Base.current_role,
|
|
97
|
+
shard = ActiveRecord::Base.current_shard
|
|
98
|
+
)
|
|
99
|
+
end
|
|
100
|
+
else
|
|
101
|
+
adapter_method = "#{config[:adapter]}_connection"
|
|
102
|
+
|
|
103
|
+
if active_record_4_or_5_or_6?
|
|
104
|
+
spec_class = ActiveRecord::ConnectionAdapters::ConnectionSpecification
|
|
105
|
+
|
|
106
|
+
if spec_class.instance_method(:initialize).arity == 3
|
|
107
|
+
# ActiveRecord 5.x and 6.0
|
|
108
|
+
spec_class.new(name, config, adapter_method)
|
|
89
109
|
else
|
|
90
|
-
ActiveRecord
|
|
110
|
+
# ActiveRecord 4.x
|
|
111
|
+
spec_class.new(config, adapter_method)
|
|
91
112
|
end
|
|
113
|
+
else
|
|
114
|
+
# ActiveRecord 3.x
|
|
115
|
+
ActiveRecord::Base::ConnectionSpecification.new(config, adapter_method)
|
|
92
116
|
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
93
119
|
|
|
94
|
-
|
|
120
|
+
def active_record_6_1_or_7?
|
|
121
|
+
defined?(ActiveRecord::ConnectionAdapters::PoolConfig)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def active_record_4_or_5_or_6?
|
|
125
|
+
defined?(ActiveRecord::ConnectionAdapters::ConnectionSpecification)
|
|
95
126
|
end
|
|
96
127
|
end
|
|
97
128
|
end
|
data/lib/octoshark/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: octoshark
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dalibor Nasevic
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-02-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -101,8 +101,7 @@ executables: []
|
|
|
101
101
|
extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
|
103
103
|
files:
|
|
104
|
-
- ".github/workflows/
|
|
105
|
-
- ".github/workflows/ci.yml"
|
|
104
|
+
- ".github/workflows/build.yml"
|
|
106
105
|
- ".gitignore"
|
|
107
106
|
- ".rspec"
|
|
108
107
|
- ".ruby-version"
|
|
@@ -123,6 +122,7 @@ files:
|
|
|
123
122
|
- gemfiles/rails5.2.gemfile
|
|
124
123
|
- gemfiles/rails6.0.gemfile
|
|
125
124
|
- gemfiles/rails6.1.gemfile
|
|
125
|
+
- gemfiles/rails7.0.gemfile
|
|
126
126
|
- lib/octoshark.rb
|
|
127
127
|
- lib/octoshark/active_record_extensions.rb
|
|
128
128
|
- lib/octoshark/connection_manager.rb
|
|
@@ -143,7 +143,7 @@ homepage: https://github.com/dalibor/octoshark
|
|
|
143
143
|
licenses:
|
|
144
144
|
- MIT
|
|
145
145
|
metadata: {}
|
|
146
|
-
post_install_message:
|
|
146
|
+
post_install_message:
|
|
147
147
|
rdoc_options: []
|
|
148
148
|
require_paths:
|
|
149
149
|
- lib
|
|
@@ -158,8 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
158
158
|
- !ruby/object:Gem::Version
|
|
159
159
|
version: '0'
|
|
160
160
|
requirements: []
|
|
161
|
-
rubygems_version: 3.
|
|
162
|
-
signing_key:
|
|
161
|
+
rubygems_version: 3.3.7
|
|
162
|
+
signing_key:
|
|
163
163
|
specification_version: 4
|
|
164
164
|
summary: Octoshark is an ActiveRecord connection switcher
|
|
165
165
|
test_files:
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
name: Build Legacy
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
branches:
|
|
6
|
-
- "*"
|
|
7
|
-
push:
|
|
8
|
-
branches:
|
|
9
|
-
- master
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
test:
|
|
13
|
-
runs-on: ubuntu-16.04
|
|
14
|
-
services:
|
|
15
|
-
mysql:
|
|
16
|
-
image: mysql:5.5
|
|
17
|
-
env:
|
|
18
|
-
MYSQL_ROOT_PASSWORD: pass
|
|
19
|
-
ports:
|
|
20
|
-
- "3306:3306"
|
|
21
|
-
options: >-
|
|
22
|
-
--health-cmd="mysqladmin ping"
|
|
23
|
-
--health-interval=10s
|
|
24
|
-
--health-timeout=5s
|
|
25
|
-
--health-retries=3
|
|
26
|
-
|
|
27
|
-
name: ruby-${{ matrix.ruby }} ${{ matrix.gemfile }}
|
|
28
|
-
strategy:
|
|
29
|
-
matrix:
|
|
30
|
-
include:
|
|
31
|
-
- gemfile: rails3.0
|
|
32
|
-
ruby: 2.2
|
|
33
|
-
- gemfile: rails3.1
|
|
34
|
-
ruby: 2.2
|
|
35
|
-
- gemfile: rails3.2
|
|
36
|
-
ruby: 2.2
|
|
37
|
-
|
|
38
|
-
- gemfile: rails4.0
|
|
39
|
-
ruby: 2.4
|
|
40
|
-
- gemfile: rails4.1
|
|
41
|
-
ruby: 2.4
|
|
42
|
-
- gemfile: rails4.2
|
|
43
|
-
ruby: 2.4
|
|
44
|
-
|
|
45
|
-
env:
|
|
46
|
-
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
|
47
|
-
BUNDLE_PATH_RELATIVE_TO_CWD: true
|
|
48
|
-
|
|
49
|
-
steps:
|
|
50
|
-
- uses: actions/checkout@master
|
|
51
|
-
|
|
52
|
-
- name: Set up Ruby
|
|
53
|
-
uses: ruby/setup-ruby@v1
|
|
54
|
-
with:
|
|
55
|
-
ruby-version: ${{ matrix.ruby }}
|
|
56
|
-
bundler: default
|
|
57
|
-
bundler-cache: true
|
|
58
|
-
|
|
59
|
-
- name: Set up database
|
|
60
|
-
run: |
|
|
61
|
-
cp spec/support/config.yml.github spec/support/config.yml
|
|
62
|
-
bundle exec rake db:create
|
|
63
|
-
|
|
64
|
-
- name: Run tests
|
|
65
|
-
run: |
|
|
66
|
-
bundle exec rspec spec
|
data/.github/workflows/ci.yml
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
name: Build
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
branches:
|
|
6
|
-
- "*"
|
|
7
|
-
push:
|
|
8
|
-
branches:
|
|
9
|
-
- master
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
test:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
services:
|
|
15
|
-
mysql:
|
|
16
|
-
image: mysql:5.7
|
|
17
|
-
env:
|
|
18
|
-
MYSQL_ROOT_PASSWORD: pass
|
|
19
|
-
ports:
|
|
20
|
-
- "3306:3306"
|
|
21
|
-
options: >-
|
|
22
|
-
--health-cmd="mysqladmin ping"
|
|
23
|
-
--health-interval=10s
|
|
24
|
-
--health-timeout=5s
|
|
25
|
-
--health-retries=3
|
|
26
|
-
|
|
27
|
-
name: ruby-${{ matrix.ruby }} ${{ matrix.gemfile }}
|
|
28
|
-
strategy:
|
|
29
|
-
matrix:
|
|
30
|
-
include:
|
|
31
|
-
- gemfile: rails5.0
|
|
32
|
-
ruby: 2.6
|
|
33
|
-
- gemfile: rails5.1
|
|
34
|
-
ruby: 2.6
|
|
35
|
-
- gemfile: rails5.2
|
|
36
|
-
ruby: 2.6
|
|
37
|
-
|
|
38
|
-
- gemfile: rails6.0
|
|
39
|
-
ruby: 2.7
|
|
40
|
-
- gemfile: rails6.1
|
|
41
|
-
ruby: 2.7
|
|
42
|
-
|
|
43
|
-
env:
|
|
44
|
-
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
|
45
|
-
BUNDLE_PATH_RELATIVE_TO_CWD: true
|
|
46
|
-
|
|
47
|
-
steps:
|
|
48
|
-
- uses: actions/checkout@master
|
|
49
|
-
|
|
50
|
-
- name: Set up Ruby
|
|
51
|
-
uses: ruby/setup-ruby@v1
|
|
52
|
-
with:
|
|
53
|
-
ruby-version: ${{ matrix.ruby }}
|
|
54
|
-
bundler: default
|
|
55
|
-
bundler-cache: true
|
|
56
|
-
|
|
57
|
-
- name: Set up database
|
|
58
|
-
run: |
|
|
59
|
-
cp spec/support/config.yml.github spec/support/config.yml
|
|
60
|
-
bundle exec rake db:create
|
|
61
|
-
|
|
62
|
-
- name: Run tests
|
|
63
|
-
run: |
|
|
64
|
-
bundle exec rspec spec
|