ar_shard 0.2.3 → 1.0.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: f0adad6bd48adb13519adcff13cc216ca2ab3b33071b69c25fd4ed17502f9749
4
- data.tar.gz: 2c9208b7cdd2ca38750c44b2a3d13459c2163646cc96118cbd80ed0940529a12
3
+ metadata.gz: 53c8a38a9c28498c974beb9599fbc5487ed5675565cbe779fff0c8eafa728225
4
+ data.tar.gz: b486fafe4cef8535a1e6a84bbe9d5e1411e5ca9371fcba8b53e5cddbb7cc41f5
5
5
  SHA512:
6
- metadata.gz: 745633132fe72a932a5f75228cc177e5605cf2fba707f533d2616ee2a1b88cbdf32906aeba2268f8db699593c2d88b3a1239c838cce0080bc9ac7a786b7d86a9
7
- data.tar.gz: 541d7e52fce0366c74d851b9b4be982858e01b86450d656955ab57361a97e82fa486f656404ed408de94693c99d68952305278f8ed6c787d889a8233005eb08b
6
+ metadata.gz: 675548c725fab7f9de04f0808ef2af806bdd0453a9a4e9ba83f84301f36bc35999a106c26be335ad2e45dfd0e4818d2c4c80525eec40313950512071bd3bb483
7
+ data.tar.gz: 8c33acf1a6deb0fc423e757a869b17bc9d4cffed952dabd899162959096f956446cbfeeb05152bbaa5be464c2b127380e9607bc0c7f6ca686a51a1f2f22013f5
@@ -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
@@ -1,3 +1,6 @@
1
+ ## 1.0.0
2
+ - Added Rails5 support
3
+
1
4
  ## 0.2.3
2
5
  - Removed pry require in runtime
3
6
 
@@ -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,25 @@
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
+ 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.
4
4
 
5
5
  ## Features
6
+ - Multiple Databases support for Rails5
7
+ - Define config as a Proc
6
8
  - Shard only part of you ActiveRecord w/o sharing connection
7
9
  - Work with you Sharded Model and AR model at the same time
8
10
  - 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
11
 
12
+ ## Limitations
13
+ - Doesn't care about migrations
14
+ - Due to nature of connection_handlers all DB connections are established at boot time
15
+ - if data structure is different between databases you should use `ModelName.reset_column_information`
11
16
 
12
17
  ## Installation
13
18
 
14
19
  Add this line to your application’s Gemfile:
15
20
 
16
21
  ```ruby
17
- gem 'ar_shard', '~> 0.2'
22
+ gem 'ar_shard', '~> 1.0'
18
23
  ```
19
24
 
20
25
  ## Usage
@@ -43,6 +48,28 @@ class ShardRecord < ActiveRecord::Base
43
48
  end
44
49
  ```
45
50
 
51
+ Where `shards.yml` is like:
52
+
53
+ ```yaml
54
+ - shard_1:
55
+ adapter: mysql2
56
+ host: blabla
57
+ username: blabla
58
+ password: secret
59
+ database: remote_database_name
60
+ port: 3306
61
+ pool: 10
62
+ - shard_2:
63
+ adapter: postgresql
64
+ host: blabla
65
+ username: blabla
66
+ password: secret
67
+ database: shard_name
68
+ port: 5432
69
+ pool: 10
70
+ ```
71
+
72
+
46
73
  given we have models like:
47
74
 
48
75
  ```ruby
@@ -81,7 +108,7 @@ To get started with development:
81
108
  git clone https://github.com/noma4i/ar_shard.git
82
109
  cd ar_shard
83
110
  bundle install
84
- bundle exec rake test
111
+ bundle exec appraisal rake test
85
112
  ```
86
113
 
87
114
  ## License
@@ -13,19 +13,18 @@ Gem::Specification.new do |spec|
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', '< 7']
28
27
 
29
- spec.add_development_dependency 'pry'
30
28
  spec.add_development_dependency 'sqlite3', '~> 1.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.0.0)
5
+ activerecord (>= 5.2, < 7)
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.2)
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)
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.0.0)
5
+ activerecord (>= 5.2, < 7)
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.2)
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)
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.0.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Tsirel
@@ -16,42 +16,48 @@ 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: '7'
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: '7'
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'
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'
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'
60
+ version: '2.3'
55
61
  description: Isolated Multibase Support for ActiveRecord Models with dynamic config
56
62
  email:
57
63
  - noma4i@gmail.com
@@ -61,6 +67,7 @@ extra_rdoc_files: []
61
67
  files:
62
68
  - ".gitignore"
63
69
  - ".travis.yml"
70
+ - Appraisals
64
71
  - CHANGELOG.md
65
72
  - Gemfile
66
73
  - Gemfile.lock
@@ -70,6 +77,11 @@ files:
70
77
  - ar_shard.gemspec
71
78
  - bin/console
72
79
  - bin/setup
80
+ - gemfiles/.bundle/config
81
+ - gemfiles/rails_5.gemfile
82
+ - gemfiles/rails_5.gemfile.lock
83
+ - gemfiles/rails_6.gemfile
84
+ - gemfiles/rails_6.gemfile.lock
73
85
  - lib/ar_shard.rb
74
86
  - lib/ar_shard/active_record.rb
75
87
  - lib/ar_shard/version.rb