ar_shard 0.2.3 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0adad6bd48adb13519adcff13cc216ca2ab3b33071b69c25fd4ed17502f9749
4
- data.tar.gz: 2c9208b7cdd2ca38750c44b2a3d13459c2163646cc96118cbd80ed0940529a12
3
+ metadata.gz: 35217aa1fbce62005178fe61b41c70a03cdbaf943f1700bebe92d608d8c521f2
4
+ data.tar.gz: b78dc7bb4e4a7ab7717343eecaac7293e152ed904953c7cb9ebb13bfbd178c92
5
5
  SHA512:
6
- metadata.gz: 745633132fe72a932a5f75228cc177e5605cf2fba707f533d2616ee2a1b88cbdf32906aeba2268f8db699593c2d88b3a1239c838cce0080bc9ac7a786b7d86a9
7
- data.tar.gz: 541d7e52fce0366c74d851b9b4be982858e01b86450d656955ab57361a97e82fa486f656404ed408de94693c99d68952305278f8ed6c787d889a8233005eb08b
6
+ metadata.gz: a0e7dc6cb5fe450771bbb2447bb447cb138f52706f0ddc4c64db7d8b89abfe57522ff9af63bc9e3b69167cf2e96144a1bcf37a7ff73bf87e1e203ccfced50824
7
+ data.tar.gz: 469810a9ac12ccd94ddfb522680230a6f0cbf4e3ebb4fe1c6b877d587fa6ad6e5d12040dfba6070658bb561aa0a54bdf48ae08218115ea10936d1942e3efc572
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ gemfile:
15
+ - gemfiles/rails_5.gemfile
16
+ - gemfiles/rails_6.gemfile
17
+ env:
18
+ BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: '2.5.3'
24
+ bundler-cache: true
25
+ - run: bundle exec rake test
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise 'rails-5' do
2
+ gem 'activerecord', '~> 5.0'
3
+ end
4
+
5
+ appraise 'rails-6' do
6
+ gem 'activerecord', '~> 6.0'
7
+ end
data/CHANGELOG.md CHANGED
@@ -1,7 +1,18 @@
1
+ ## 1.1.0
2
+
3
+ - Constrained activerecord to `>= 5.2, < 6.1` to match tested versions
4
+ - Documented tested Ruby/ActiveRecord compatibility in README
5
+
6
+ ## 1.0.0
7
+
8
+ - Added Rails5 support
9
+
1
10
  ## 0.2.3
11
+
2
12
  - Removed pry require in runtime
3
13
 
4
14
  ## 0.2.2
15
+
5
16
  - Fixed missing connection if loaded from YAML
6
17
  - Added tests for multiple connection switches with another block
7
18
 
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ar_shard (0.2.2)
5
- activerecord (>= 6)
4
+ ar_shard (1.0.0)
5
+ activerecord (>= 5.2, < 7)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -18,17 +18,17 @@ GEM
18
18
  minitest (~> 5.1)
19
19
  tzinfo (~> 1.1)
20
20
  zeitwerk (~> 2.2, >= 2.2.2)
21
- coderay (1.1.3)
21
+ appraisal (2.3.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
22
25
  concurrent-ruby (1.1.7)
23
26
  i18n (1.8.5)
24
27
  concurrent-ruby (~> 1.0)
25
- method_source (1.0.0)
26
- minitest (5.11.3)
27
- pry (0.13.1)
28
- coderay (~> 1.1)
29
- method_source (~> 1.0)
30
- rake (12.3.2)
28
+ minitest (5.14.1)
29
+ rake (12.3.3)
31
30
  sqlite3 (1.4.2)
31
+ thor (1.0.1)
32
32
  thread_safe (0.3.6)
33
33
  tzinfo (1.2.7)
34
34
  thread_safe (~> 0.1)
@@ -38,9 +38,9 @@ PLATFORMS
38
38
  ruby
39
39
 
40
40
  DEPENDENCIES
41
+ appraisal (~> 2.3)
41
42
  ar_shard!
42
43
  minitest (~> 5.0)
43
- pry
44
44
  rake (~> 12.0)
45
45
  sqlite3 (~> 1.4)
46
46
 
data/README.md CHANGED
@@ -1,20 +1,39 @@
1
1
  # AR Shard
2
2
 
3
- AR Shard is non-intrusive extenstion for ActiveRecord to add threadsafe Model based sharding or just multidatabase connection. As this gem uses connection_handlers it can work only with ActiveRecord 6 and above.
3
+ [![Gem Version](https://badge.fury.io/rb/ar_shard.svg)](https://badge.fury.io/rb/ar_shard)
4
+ [![CI](https://github.com/noma4i/ar_shard/actions/workflows/ci.yml/badge.svg)](https://github.com/noma4i/ar_shard/actions/workflows/ci.yml)
5
+
6
+ AR Shard is non-intrusive extenstion for ActiveRecord to add threadsafe Model based sharding or just multidatabase connection. As this gem uses connection_handlers it can work only with ActiveRecord version 5 and above.
7
+
8
+ ## Compatibility
9
+
10
+ This gem was tested against:
11
+
12
+ - Ruby 2.5.3
13
+ - ActiveRecord 5.2.4.3 and 6.0.3.2 (see `Appraisals` and `gemfiles/`)
14
+
15
+ Rails 6.1 reworked `connection_handlers` into its own sharding framework, the same API this gem patches, so versions 6.1 and above were never tested and are not supported. The gemspec enforces `activerecord >= 5.2, < 6.1`.
4
16
 
5
17
  ## Features
18
+
19
+ - Multiple Databases support for Rails5
20
+ - Define config as a Proc
6
21
  - Shard only part of you ActiveRecord w/o sharing connection
7
22
  - Work with you Sharded Model and AR model at the same time
8
23
  - Threadsafe. Battle-tested with Sidekiq and 4 mixed Databases
9
- - Define config as a Proc. `Due to nature of connection_handlers all DB connections are established at boot time`
10
24
 
25
+ ## Limitations
26
+
27
+ - Doesn't care about migrations
28
+ - Due to nature of connection_handlers all DB connections are established at boot time
29
+ - if data structure is different between databases you should use `ModelName.reset_column_information`
11
30
 
12
31
  ## Installation
13
32
 
14
33
  Add this line to your application’s Gemfile:
15
34
 
16
35
  ```ruby
17
- gem 'ar_shard', '~> 0.2'
36
+ gem 'ar_shard', '~> 1.0'
18
37
  ```
19
38
 
20
39
  ## Usage
@@ -43,6 +62,27 @@ class ShardRecord < ActiveRecord::Base
43
62
  end
44
63
  ```
45
64
 
65
+ Where `shards.yml` is like:
66
+
67
+ ```yaml
68
+ - shard_1:
69
+ adapter: mysql2
70
+ host: blabla
71
+ username: blabla
72
+ password: secret
73
+ database: remote_database_name
74
+ port: 3306
75
+ pool: 10
76
+ - shard_2:
77
+ adapter: postgresql
78
+ host: blabla
79
+ username: blabla
80
+ password: secret
81
+ database: shard_name
82
+ port: 5432
83
+ pool: 10
84
+ ```
85
+
46
86
  given we have models like:
47
87
 
48
88
  ```ruby
@@ -81,7 +121,7 @@ To get started with development:
81
121
  git clone https://github.com/noma4i/ar_shard.git
82
122
  cd ar_shard
83
123
  bundle install
84
- bundle exec rake test
124
+ bundle exec appraisal rake test
85
125
  ```
86
126
 
87
127
  ## License
data/ar_shard.gemspec CHANGED
@@ -7,25 +7,24 @@ Gem::Specification.new do |spec|
7
7
  spec.email = ['noma4i@gmail.com']
8
8
 
9
9
  spec.summary = 'Isolated Multibase Support for ActiveRecord Models with dynamic config'
10
- spec.description = 'Isolated Multibase Support for ActiveRecord Models with dynamic config'
10
+ spec.description = 'DB Rails Sharding. Isolated Multibase Support for ActiveRecord Models with dynamic config'
11
11
  spec.homepage = 'https://github.com/noma4i/ar_shard'
12
12
  spec.license = 'MIT'
13
13
  spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
14
 
15
15
  spec.metadata['homepage_uri'] = spec.homepage
16
- spec.metadata['source_code_uri'] = 'https://github.com/noma4i/ar_shard'
16
+ spec.metadata['source_code_uri'] = spec.homepage
17
17
 
18
- # Specify which files should be added to the gem when it is released.
19
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
18
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
19
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
20
  end
21
+
23
22
  spec.bindir = 'exe'
24
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
24
  spec.require_paths = ['lib']
26
25
 
27
- spec.add_dependency 'activerecord', '>= 6'
26
+ spec.add_dependency 'activerecord', ['>= 5.2', '< 6.1']
28
27
 
29
- spec.add_development_dependency 'pry'
30
- spec.add_development_dependency 'sqlite3', '~> 1.4'
28
+ spec.add_development_dependency 'sqlite3', '~> 1.4.4'
29
+ spec.add_development_dependency 'appraisal', '~> 2.3'
31
30
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 12.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "activerecord", "~> 5.0"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ ar_shard (1.1.0)
5
+ activerecord (>= 5.2, < 6.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.2.4.3)
11
+ activesupport (= 5.2.4.3)
12
+ activerecord (5.2.4.3)
13
+ activemodel (= 5.2.4.3)
14
+ activesupport (= 5.2.4.3)
15
+ arel (>= 9.0)
16
+ activesupport (5.2.4.3)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ appraisal (2.3.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ arel (9.0.0)
26
+ concurrent-ruby (1.1.7)
27
+ i18n (1.8.5)
28
+ concurrent-ruby (~> 1.0)
29
+ minitest (5.11.3)
30
+ rake (12.3.3)
31
+ sqlite3 (1.4.4)
32
+ thor (1.0.1)
33
+ thread_safe (0.3.6)
34
+ tzinfo (1.2.7)
35
+ thread_safe (~> 0.1)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ activerecord (~> 5.0)
42
+ appraisal (~> 2.3)
43
+ ar_shard!
44
+ minitest (~> 5.0)
45
+ rake (~> 12.0)
46
+ sqlite3 (~> 1.4.4)
47
+
48
+ BUNDLED WITH
49
+ 1.17.3
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 12.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "activerecord", "~> 6.0"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ ar_shard (1.1.0)
5
+ activerecord (>= 5.2, < 6.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (6.0.3.2)
11
+ activesupport (= 6.0.3.2)
12
+ activerecord (6.0.3.2)
13
+ activemodel (= 6.0.3.2)
14
+ activesupport (= 6.0.3.2)
15
+ activesupport (6.0.3.2)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ zeitwerk (~> 2.2, >= 2.2.2)
21
+ appraisal (2.3.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ concurrent-ruby (1.1.7)
26
+ i18n (1.8.5)
27
+ concurrent-ruby (~> 1.0)
28
+ minitest (5.11.3)
29
+ rake (12.3.3)
30
+ sqlite3 (1.4.4)
31
+ thor (1.0.1)
32
+ thread_safe (0.3.6)
33
+ tzinfo (1.2.7)
34
+ thread_safe (~> 0.1)
35
+ zeitwerk (2.4.0)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ activerecord (~> 6.0)
42
+ appraisal (~> 2.3)
43
+ ar_shard!
44
+ minitest (~> 5.0)
45
+ rake (~> 12.0)
46
+ sqlite3 (~> 1.4.4)
47
+
48
+ BUNDLED WITH
49
+ 1.17.3
@@ -14,6 +14,8 @@ module ActiveRecord
14
14
  end
15
15
 
16
16
  module ConnectionHandling
17
+ mattr_accessor :connection_handlers, instance_accessor: false, default: {}
18
+
17
19
  def connected_shards(shards: nil)
18
20
  @connected_shards ||= begin
19
21
  config_data = parse_config(shards)
@@ -45,14 +47,21 @@ module ActiveRecord
45
47
  end
46
48
 
47
49
  def lookup_connect(handler_key)
48
- connection_handlers[handler_key] ||= ActiveRecord::ConnectionAdapters::ConnectionHandler.new
50
+ if defined?(connection_handlers)
51
+ connection_handlers[handler_key] ||= ActiveRecord::ConnectionAdapters::ConnectionHandler.new
52
+ else
53
+ @@connection_handlers[handler_key] ||= ActiveRecord::ConnectionAdapters::ConnectionHandler.new
54
+ end
49
55
  end
50
56
 
51
57
  def with_shard(handler_key, &blk)
52
58
  shard_model.isolated_connection = connected_shards[handler_key].connection
53
- yield
59
+ return_value = yield
60
+ return_value.load if return_value.is_a? ActiveRecord::Relation
61
+ return_value
54
62
  ensure
55
63
  shard_model.isolated_connection = nil
56
64
  end
57
65
  end
58
66
  end
67
+
@@ -1,3 +1,3 @@
1
1
  module ARShard
2
- VERSION = "0.2.3"
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_shard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Tsirel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-15 00:00:00.000000000 Z
11
+ date: 2026-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,51 +16,59 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6'
19
+ version: '5.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '6'
29
+ version: '5.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.1'
27
33
  - !ruby/object:Gem::Dependency
28
- name: pry
34
+ name: sqlite3
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
37
+ - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '0'
39
+ version: 1.4.4
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - ">="
44
+ - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: '0'
46
+ version: 1.4.4
41
47
  - !ruby/object:Gem::Dependency
42
- name: sqlite3
48
+ name: appraisal
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '1.4'
53
+ version: '2.3'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '1.4'
55
- description: Isolated Multibase Support for ActiveRecord Models with dynamic config
60
+ version: '2.3'
61
+ description: DB Rails Sharding. Isolated Multibase Support for ActiveRecord Models
62
+ with dynamic config
56
63
  email:
57
64
  - noma4i@gmail.com
58
65
  executables: []
59
66
  extensions: []
60
67
  extra_rdoc_files: []
61
68
  files:
69
+ - ".github/workflows/ci.yml"
62
70
  - ".gitignore"
63
- - ".travis.yml"
71
+ - Appraisals
64
72
  - CHANGELOG.md
65
73
  - Gemfile
66
74
  - Gemfile.lock
@@ -70,6 +78,11 @@ files:
70
78
  - ar_shard.gemspec
71
79
  - bin/console
72
80
  - bin/setup
81
+ - gemfiles/.bundle/config
82
+ - gemfiles/rails_5.gemfile
83
+ - gemfiles/rails_5.gemfile.lock
84
+ - gemfiles/rails_6.gemfile
85
+ - gemfiles/rails_6.gemfile.lock
73
86
  - lib/ar_shard.rb
74
87
  - lib/ar_shard/active_record.rb
75
88
  - lib/ar_shard/version.rb
@@ -94,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
107
  - !ruby/object:Gem::Version
95
108
  version: '0'
96
109
  requirements: []
97
- rubygems_version: 3.0.8
110
+ rubygems_version: 3.4.19
98
111
  signing_key:
99
112
  specification_version: 4
100
113
  summary: Isolated Multibase Support for ActiveRecord Models with dynamic config
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.5.3
6
- before_install: gem install bundler -v 2.1.4