octoshark 0.3.0 → 0.5.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: 743be64d2aeb897827aec871dfd86150ea1ca7ce6505839cea1caf16e85676bc
4
- data.tar.gz: a801773571a7388fed3d16179be6006d10a6e060fb514813a2e21ba3532816ee
3
+ metadata.gz: '08a9bf2ed4d65fbb159fc533e06faf1fee9bdc6b756d9ea291f1918240bddfab'
4
+ data.tar.gz: 7e8c1cd5604b308ce09c6b3227832eb42fc24b26591acf8a177817b679d98dc4
5
5
  SHA512:
6
- metadata.gz: 2fa8e793d0eae00f5d99420e1f3b5bc6218b9b5a5b8c27b0c63dbbde080265d5797cc4d56cbce049cd25459e0f8961228f0acb5d677f35f1de45a42fbd82f610
7
- data.tar.gz: 16f82b5d43d619ff5d8691229a8377189c10ef3b9d20752649d2e63725bff171afe9f232d2300916b573bff7260ff63d92be08bae567934ff7751285d6240728
6
+ metadata.gz: 721103095d5700ead78726a57a3e233212b523a80db732f5616b1151e61071f566a877fe30784ba4a6ab1b25b70b0041f6adc6136b5fed8185836e1f24b8af18
7
+ data.tar.gz: b8b939dd94e1bb789715501fbcf6502718cc029088f0915b157a0402efddcc0a3282a7da35a2d9d3f8dbb766300afb8633103564d3ef167c1101495369c0e8fb
@@ -9,10 +9,10 @@ on:
9
9
  - master
10
10
 
11
11
  jobs:
12
- test:
12
+ latest:
13
13
  runs-on: ubuntu-latest
14
14
  services:
15
- mysql:
15
+ mysql:
16
16
  image: mysql:5.7
17
17
  env:
18
18
  MYSQL_ROOT_PASSWORD: pass
@@ -34,11 +34,25 @@ jobs:
34
34
  ruby: 2.6
35
35
  - gemfile: rails5.2
36
36
  ruby: 2.6
37
+ - gemfile: rails5.2
38
+ ruby: 3.0
37
39
 
38
40
  - gemfile: rails6.0
39
41
  ruby: 2.7
40
42
  - gemfile: rails6.1
41
43
  ruby: 2.7
44
+ - gemfile: rails6.1
45
+ ruby: 3.0
46
+
47
+ - gemfile: rails7.0
48
+ ruby: 3.0
49
+ - gemfile: rails7.0
50
+ ruby: 3.1
51
+
52
+ - gemfile: rails7.1
53
+ ruby: 3.1
54
+ - gemfile: rails7.1
55
+ ruby: 3.2
42
56
 
43
57
  env:
44
58
  BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.4
1
+ 3.2.2
data/Appraisals CHANGED
@@ -1,29 +1,23 @@
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
- gem "mysql2", "~> 0.5.2"
10
- gem "sqlite3", "~> 1.4.1"
11
3
  end
12
4
 
13
5
  appraise "rails5.2" do
14
6
  gem "activerecord", "~> 5.2.0"
15
- gem "mysql2", "~> 0.5.2"
16
- gem "sqlite3", "~> 1.4.1"
17
7
  end
18
8
 
19
9
  appraise "rails6.0" do
20
10
  gem "activerecord", "~> 6.0.0"
21
- gem "mysql2", "~> 0.5.2"
22
- gem "sqlite3", "~> 1.4.1"
23
11
  end
24
12
 
25
13
  appraise "rails6.1" do
26
14
  gem "activerecord", "~> 6.1.0"
27
- gem "mysql2", "~> 0.5.2"
28
- gem "sqlite3", "~> 1.4.1"
15
+ end
16
+
17
+ appraise "rails7.0" do
18
+ gem "activerecord", "~> 7.0.0"
19
+ end
20
+
21
+ appraise "rails7.1" do
22
+ gem "activerecord", "~> 7.1.0"
29
23
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Change log
2
2
 
3
+ ## 0.5.0 2023-10-27
4
+
5
+ - Add support for Rails 7.1
6
+ - Drop legacy test job because ubuntu-18.04 build node is not available anymore
7
+
8
+ ## 0.4.0 2022-02-12
9
+
10
+ - Add support for Rails 7.0
11
+ - Fix `establish_connection` for Ruby 3
12
+
3
13
  ## 0.3.0 2021-07-20
4
14
 
5
15
  - Add support for Rails 6.1
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
- gem "activerecord", "~> 6.1.0"
2
+ gem "activerecord", "~> 7.1.0"
3
3
 
4
4
  # Specify your gem's dependencies in octoshark.gemspec
5
5
  gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ![Octoshark logo](http://dalibornasevic.com/images/octoshark.png)
2
2
 
3
- ![Travis status](https://travis-ci.org/dalibor/octoshark.png)
3
+ ![Build status](https://github.com/dalibor/octoshark/actions/workflows/build.yml/badge.svg)
4
4
 
5
5
  Octoshark is a simple ActiveRecord connection manager. It provides connection switching mechanisms that can be used in various scenarios like master-slave, sharding or multi-tenant architecture.
6
6
 
@@ -3,7 +3,5 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.1.0"
6
- gem "mysql2", "~> 0.5.2"
7
- gem "sqlite3", "~> 1.4.1"
8
6
 
9
7
  gemspec path: "../"
@@ -3,7 +3,5 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.2.0"
6
- gem "mysql2", "~> 0.5.2"
7
- gem "sqlite3", "~> 1.4.1"
8
6
 
9
7
  gemspec path: "../"
@@ -3,7 +3,5 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 6.0.0"
6
- gem "mysql2", "~> 0.5.2"
7
- gem "sqlite3", "~> 1.4.1"
8
6
 
9
7
  gemspec path: "../"
@@ -3,7 +3,5 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 6.1.0"
6
- gem "mysql2", "~> 0.5.2"
7
- gem "sqlite3", "~> 1.4.1"
8
6
 
9
7
  gemspec path: "../"
@@ -2,8 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.0.0"
6
- gem "mysql2", "< 0.3"
7
- gem "sqlite3", "~> 1.3.13"
5
+ gem "activerecord", "~> 7.0.0"
8
6
 
9
7
  gemspec path: "../"
@@ -2,8 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.2.0"
6
- gem "mysql2", "~> 0.3.10"
7
- gem "sqlite3", "~> 1.3.13"
5
+ gem "activerecord", "~> 7.1.0"
8
6
 
9
7
  gemspec path: "../"
@@ -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
- if defined?(ActiveRecord::ConnectionAdapters::ConnectionHandler)
23
- # Rails 3.2, 4.0, 4.1, 4.2, 5.0
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,59 @@ module Octoshark
71
71
  end
72
72
 
73
73
  def create_connection_pool(name, config)
74
- spec =
75
- if defined?(ActiveRecord::ConnectionAdapters::PoolConfig)
76
- env_name = defined?(Rails) ? Rails.env : nil
77
- db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(env_name, name, config)
78
- ActiveRecord::ConnectionAdapters::PoolConfig.new(owner_name = ActiveRecord::Base, db_config)
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
+ require "active_record/database_configurations"
85
+ db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(env_name, name, config)
86
+
87
+ pool_config_class = ActiveRecord::ConnectionAdapters::PoolConfig
88
+
89
+ if pool_config_class.instance_method(:initialize).arity == 2
90
+ # ActiveRecord 6.1
91
+ pool_config_class.new(owner_name = ActiveRecord::Base, db_config)
79
92
  else
80
- adapter_method = "#{config[:adapter]}_connection"
81
- if defined?(ActiveRecord::ConnectionAdapters::ConnectionSpecification)
82
- spec_class = ActiveRecord::ConnectionAdapters::ConnectionSpecification
83
-
84
- if spec_class.instance_method(:initialize).arity == 3
85
- spec_class.new(name, config, adapter_method)
86
- else
87
- spec_class.new(config, adapter_method)
88
- end
93
+ # ActiveRecord 7.0
94
+ pool_config_class.new(
95
+ owner_name = ActiveRecord::Base,
96
+ db_config,
97
+ role = ActiveRecord::Base.current_role,
98
+ shard = ActiveRecord::Base.current_shard
99
+ )
100
+ end
101
+ else
102
+ adapter_method = "#{config[:adapter]}_connection"
103
+
104
+ if active_record_4_or_5_or_6?
105
+ spec_class = ActiveRecord::ConnectionAdapters::ConnectionSpecification
106
+
107
+ if spec_class.instance_method(:initialize).arity == 3
108
+ # ActiveRecord 5.x and 6.0
109
+ spec_class.new(name, config, adapter_method)
89
110
  else
90
- ActiveRecord::Base::ConnectionSpecification.new(config, adapter_method)
111
+ # ActiveRecord 4.x
112
+ spec_class.new(config, adapter_method)
91
113
  end
114
+ else
115
+ # ActiveRecord 3.x
116
+ ActiveRecord::Base::ConnectionSpecification.new(config, adapter_method)
92
117
  end
118
+ end
119
+ end
93
120
 
94
- ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec)
121
+ def active_record_6_1_or_7?
122
+ defined?(ActiveRecord::ConnectionAdapters::PoolConfig)
123
+ end
124
+
125
+ def active_record_4_or_5_or_6?
126
+ defined?(ActiveRecord::ConnectionAdapters::ConnectionSpecification)
95
127
  end
96
128
  end
97
129
  end
@@ -1,3 +1,3 @@
1
1
  module Octoshark
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/octoshark.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency "activerecord", ">= 3.0"
22
22
 
23
23
  spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec", "~> 3.7.0"
24
+ spec.add_development_dependency "rspec", "~> 3.12.0"
25
25
  spec.add_development_dependency "sqlite3", "~> 1.4.1"
26
26
  spec.add_development_dependency "mysql2", "~> 0.5.2"
27
27
  spec.add_development_dependency "appraisal"
@@ -1,7 +1,6 @@
1
1
  db1:
2
2
  adapter: mysql2
3
3
  encoding: utf8
4
- reconnect: false
5
4
  database: octoshark_db1
6
5
  pool: 5
7
6
  username: root
@@ -12,7 +11,6 @@ db1:
12
11
  db2:
13
12
  adapter: mysql2
14
13
  encoding: utf8
15
- reconnect: false
16
14
  database: octoshark_db2
17
15
  pool: 5
18
16
  username: root
@@ -1,7 +1,6 @@
1
1
  db1:
2
2
  adapter: mysql2
3
3
  encoding: utf8
4
- reconnect: false
5
4
  database: octoshark_db1
6
5
  pool: 5
7
6
  username: root
@@ -12,7 +11,6 @@ db1:
12
11
  db2:
13
12
  adapter: mysql2
14
13
  encoding: utf8
15
- reconnect: false
16
14
  database: octoshark_db2
17
15
  pool: 5
18
16
  username: root
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.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dalibor Nasevic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2023-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.7.0
47
+ version: 3.12.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.7.0
54
+ version: 3.12.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -101,8 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - ".github/workflows/ci-legacy.yml"
105
- - ".github/workflows/ci.yml"
104
+ - ".github/workflows/build.yml"
106
105
  - ".gitignore"
107
106
  - ".rspec"
108
107
  - ".ruby-version"
@@ -112,17 +111,13 @@ files:
112
111
  - LICENSE.txt
113
112
  - README.md
114
113
  - Rakefile
115
- - gemfiles/rails3.0.gemfile
116
- - gemfiles/rails3.1.gemfile
117
- - gemfiles/rails3.2.gemfile
118
- - gemfiles/rails4.0.gemfile
119
- - gemfiles/rails4.1.gemfile
120
- - gemfiles/rails4.2.gemfile
121
114
  - gemfiles/rails5.0.gemfile
122
115
  - gemfiles/rails5.1.gemfile
123
116
  - gemfiles/rails5.2.gemfile
124
117
  - gemfiles/rails6.0.gemfile
125
118
  - gemfiles/rails6.1.gemfile
119
+ - gemfiles/rails7.0.gemfile
120
+ - gemfiles/rails7.1.gemfile
126
121
  - lib/octoshark.rb
127
122
  - lib/octoshark/active_record_extensions.rb
128
123
  - lib/octoshark/connection_manager.rb
@@ -158,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
153
  - !ruby/object:Gem::Version
159
154
  version: '0'
160
155
  requirements: []
161
- rubygems_version: 3.1.6
156
+ rubygems_version: 3.4.10
162
157
  signing_key:
163
158
  specification_version: 4
164
159
  summary: Octoshark is an ActiveRecord connection switcher
@@ -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
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 3.1.0"
6
- gem "mysql2", "~> 0.3.10"
7
- gem "sqlite3", "~> 1.3.13"
8
-
9
- gemspec path: "../"
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.0.0"
6
- gem "mysql2", "~> 0.3.10"
7
- gem "sqlite3", "~> 1.3.13"
8
-
9
- gemspec path: "../"
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.1.0"
6
- gem "mysql2", "~> 0.3.13"
7
- gem "sqlite3", "~> 1.3.13"
8
-
9
- gemspec path: "../"
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.2.0"
6
- gem "mysql2", "~> 0.3.13"
7
- gem "sqlite3", "~> 1.3.13"
8
-
9
- gemspec path: "../"