activerecord-shard_for 0.6.1 → 0.7.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
- SHA1:
3
- metadata.gz: 18b127f1099df390fc67db8548a308d1dc66cded
4
- data.tar.gz: 25f90de3cad7a5824d1f164370e6b146589614b8
2
+ SHA256:
3
+ metadata.gz: 67af2da78df9da03fc8dcb0f8ec43360ef50ef2db165b8aca97c2f11d70c81f2
4
+ data.tar.gz: 7a3c2ad776f3a73efd5a8eb4116fc47404a02837374cf9f30c7903dae05922f3
5
5
  SHA512:
6
- metadata.gz: f0b5fc995889395482558bc950bc113a2692e21f8dc7a5ef0d75de8a1cb172e0c100cfeb28c77fc05536df4243513c5a4a54316d94d34299e7605cc9044fd764
7
- data.tar.gz: 15dda5d854a5191a9559b020722a1fc6c960f8412479fda3d53a4fe6beeb2e6a738d0f948f29c5eb942ed31058e7bd474851b26bb79c3cee6e39c843d21112fb
6
+ metadata.gz: 47a9f15465c8c921ee26df83a327d81776eff5f348314f83a907fb9b0af3b7c442209581369168dd0e6c76260143ee47bdc9f0893b5ba605e49416dccf24c489
7
+ data.tar.gz: c38eb2a219785ce3d350b9158e7fdf635b35b2fbe508850039df06f60b5478bd005b20e14109b8335c4a39337b21fd874151c47d2b976e5c5a36712ba9f5be1a
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 2.2.7
5
- - 2.3.4
6
- - 2.4.1
4
+ - 2.3.8
5
+ - 2.4.5
6
+ - 2.5.3
7
+ - 2.6.1
7
8
  branches:
8
9
  only:
9
10
  - master
@@ -20,16 +21,22 @@ gemfile:
20
21
  - gemfiles/ar_5.0.gemfile
21
22
  - gemfiles/ar_5.1.gemfile
22
23
  - gemfiles/ar_5.2.gemfile
24
+ - gemfiles/ar_6.0.gemfile
23
25
  - gemfiles/rails_edge.gemfile
24
26
  matrix:
25
27
  allow_failures:
28
+ - gemfile: gemfiles/ar_6.0.gemfile
26
29
  - gemfile: gemfiles/rails_edge.gemfile
27
- # rails_edge required ruby version over 2.4.1
30
+ # rails_edge required ruby version over 2.5.0
28
31
  exclude:
29
- - rvm: 2.2.7
32
+ - rvm: 2.3.8
30
33
  gemfile: gemfiles/rails_edge.gemfile
31
- - rvm: 2.3.4
34
+ - rvm: 2.4.5
32
35
  gemfile: gemfiles/rails_edge.gemfile
36
+ - rvm: 2.3.8
37
+ gemfile: gemfiles/ar_6.0.gemfile
38
+ - rvm: 2.4.5
39
+ gemfile: gemfiles/ar_6.0.gemfile
33
40
  notifications:
34
41
  slack:
35
42
  secure: S1W/Lw+dH3wb8FfkMIWPZmr6M4Q6S2WMkSlanpKva1HM7K5QL7hXdmUl2yBUxJE26BHSsb1ScozMEzadyda2+i/W34UvZ7LXgKeHkUKEdjy/AmsSJPK1ZjMfgnv10tVgbEIusNb4bF/sSuChdZKK3ILwOlqIPDlQNdMwF1xRA2xt5J7tb26UgyIzoCI4P3bJYMULWsEkk+UwHiJH0YO9ulkTZI/j0N+hLXQLJTZPjmKtMk/tE0NbBmFVL4md89hUcR5gKTGGrNzEMJ58K+zqeDG/DubkcIbA5ZuqKv+oE5m0pDODZExxnC+oeENTvq/VfYwOfD0pTDrBNYjj+Bm3YiyGDzQAgov9XPDG8g/fKEs/LNAT79UZXkZlFO99Yn/vrYH9o5DKpOE9smENUXylb55MgLTUiYe17CTp7pB3trbJl3wwIbLjSmTjAdSUNgPv8qDP4uk3K4U32mknXCDDkU9EI7f6F731ocdoxsGarEBcPcgjs73Y84iwDteQp847Gigtgo4Y4TCWH657uzLolR2O8NSw+vWT0VNI9qtR5PZD7iVYtSp1qHtPAKowCztodewY2Nu+Ds9Z95udf4GPUkFg/SNEJPTPrQFLiiJZ8UYP8NJEuA+IP1tc2zG3zU/ADrjenRC1ZiupQG7OMH82y11408U6PcHFSlF+7NuDkac=
data/Appraisals CHANGED
@@ -12,6 +12,10 @@ appraise 'ar-5.2' do
12
12
  gem 'activerecord', '~> 5.2.1'
13
13
  end
14
14
 
15
+ appraise 'ar-6.0' do
16
+ gem 'activerecord', '~> 6.0.0.beta1'
17
+ end
18
+
15
19
  appraise 'rails-edge' do
16
20
  gem 'activerecord', github: 'rails/rails'
17
21
  gem 'arel', github: 'rails/arel'
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG for activerecord-shard_for
2
2
 
3
+ ## 0.7.0
4
+
5
+ - Fix establish_connection is called on class loading. [#20](https://github.com/yuemori/activerecord-shard_for/pull/20)
6
+ - Bump up supporeted rails versions. [#21](https://github.com/yuemori/activerecord-shard_for/pull/21)
7
+ - Add rails 6.0.0.beta1(experimental)
8
+ - Drop ruby 2.2.x support
9
+ - Fix set_callback raises NoMethodError when already defined callback. [#22](https://github.com/yuemori/activerecord-shard_for/pull/22)
10
+
3
11
  ## 0.6.1
4
12
 
5
13
  - Allow settings `thread_pool_base_size` and command executor. [#18](https://github.com/yuemori/activerecord-shard_for/pull/18)
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
  lib = File.expand_path('../lib', __FILE__)
4
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -20,19 +19,19 @@ Gem::Specification.new do |spec|
20
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
20
  spec.require_paths = ['lib']
22
21
 
23
- spec.add_dependency 'activerecord', '>= 5.0.0'
24
- spec.add_dependency 'activesupport', '>= 5.0.0'
22
+ spec.add_dependency 'activerecord'
23
+ spec.add_dependency 'activesupport'
25
24
  spec.add_dependency 'expeditor', '>= 0.1.0'
25
+ spec.add_development_dependency 'appraisal'
26
26
  spec.add_development_dependency 'bundler', '>= 1.14'
27
- spec.add_development_dependency 'rake'
28
- spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
29
28
  spec.add_development_dependency 'guard'
30
- spec.add_development_dependency 'guard-rubocop'
31
29
  spec.add_development_dependency 'guard-rspec'
30
+ spec.add_development_dependency 'guard-rubocop'
32
31
  spec.add_development_dependency 'pry-byebug'
33
- spec.add_development_dependency 'rubocop'
34
- spec.add_development_dependency 'appraisal'
35
- spec.add_development_dependency 'sqlite3'
32
+ spec.add_development_dependency 'rake'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
34
  spec.add_development_dependency 'rspec-parameterized'
37
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
35
+ spec.add_development_dependency 'rubocop'
36
+ spec.add_development_dependency 'sqlite3', '~> 1.3.6'
38
37
  end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.0.beta1"
6
+
7
+ gemspec path: "../"
@@ -14,6 +14,8 @@ module ActiveRecord
14
14
  # @raise [RuntimeError] when duplicate entry of key
15
15
  def register(key, connection_name)
16
16
  raise RuntimeError.new, "#{key} is registered" if connection_registry.key?(key)
17
+
18
+ establish_connection(connection_name)
17
19
  connection_registry[key] = connection_name
18
20
  end
19
21
 
@@ -35,6 +37,38 @@ module ActiveRecord
35
37
 
36
38
  raise KeyError.new, "#{key} is not registerd connection"
37
39
  end
40
+
41
+ private
42
+
43
+ # @param [Symbol] connection_name
44
+ # @return [String]
45
+ def generate_shard_name(connection_name)
46
+ "ShardFor#{connection_name.to_s.tr('-', '_').classify}"
47
+ end
48
+
49
+ # Establish connection for shard.
50
+ # @param [Symbol] connection_name
51
+ def establish_connection(connection_name)
52
+ shard_name = generate_shard_name(connection_name)
53
+
54
+ model = shard_name.safe_constantize
55
+
56
+ return if model
57
+
58
+ model = Class.new(ActiveRecord::Base) do
59
+ self.abstract_class = true
60
+
61
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
62
+ def self.name
63
+ "#{shard_name}"
64
+ end
65
+ RUBY
66
+ end
67
+
68
+ Object.const_set(shard_name, model)
69
+
70
+ model.establish_connection connection_name
71
+ end
38
72
  end
39
73
  end
40
74
  end
@@ -3,6 +3,11 @@ module ActiveRecord
3
3
  module DatabaseTasks
4
4
  module_function
5
5
 
6
+ # @return [Boolean]
7
+ def ar6?
8
+ ActiveRecord::VERSION::MAJOR == 6
9
+ end
10
+
6
11
  # @return [Boolean]
7
12
  def ar5?
8
13
  ActiveRecord::VERSION::MAJOR == 5
@@ -167,7 +172,7 @@ module ActiveRecord
167
172
  configuration = ActiveRecord::Base.configurations[connection_name]
168
173
 
169
174
  case
170
- when ar5?
175
+ when ar5? || ar6?
171
176
  ActiveRecord::Tasks::DatabaseTasks.load_schema(configuration, :ruby)
172
177
  when ar42? || ar417_above?
173
178
  ActiveRecord::Tasks::DatabaseTasks.load_schema_for(configuration, :ruby)
@@ -69,6 +69,7 @@ module ActiveRecord
69
69
  # @raise [ActiveRecord::ShardFor::MissingDistkeyAttribute]
70
70
  def put!(attributes)
71
71
  raise '`distkey` is not defined. Use `def_distkey`.' unless distkey
72
+
72
73
  @before_put_callback.call(attributes) if defined?(@before_put_callback) && @before_put_callback
73
74
 
74
75
  key = fetch_distkey_from_attributes(attributes)
@@ -10,6 +10,20 @@ module ActiveRecord
10
10
  super
11
11
  shard_repository.all.each { |shard| shard.defined_enums = defined_enums }
12
12
  end
13
+
14
+ # For ActiveSupport::Callbacks patch.
15
+ #
16
+ # Since define_callbacks has not been successfully propagated to the shard class when called,
17
+ # we also call define_callback of the shard class.
18
+ def define_callbacks(*args)
19
+ if abstract_class
20
+ all_shards.each do |model|
21
+ model.define_callbacks(*args)
22
+ end
23
+ end
24
+
25
+ super
26
+ end
13
27
  end
14
28
  end
15
29
  end
@@ -9,7 +9,6 @@ module ActiveRecord
9
9
  @base_class = base_class
10
10
 
11
11
  @shards = cluster_config.connection_registry.each_with_object({}) do |(key, connection_name), hash|
12
- establish_connection(connection_name)
13
12
  model = generate_model_for_shard(connection_name, key)
14
13
  base_class.const_set(:"#{generate_shard_name(connection_name)}", model)
15
14
  hash[connection_name] = model
@@ -18,24 +17,6 @@ module ActiveRecord
18
17
 
19
18
  private
20
19
 
21
- # Establish connection for shard.
22
- # @param [Symbol] connection_name
23
- def establish_connection(connection_name)
24
- shard_name = generate_shard_name(connection_name)
25
-
26
- model = Class.new(base_class) do
27
- self.table_name = base_class.table_name
28
-
29
- module_eval <<-RUBY, __FILE__, __LINE__ + 1
30
- def self.name
31
- "#{shard_name}"
32
- end
33
- RUBY
34
- end
35
-
36
- model.establish_connection connection_name
37
- end
38
-
39
20
  # @param [Symbol] connection_name
40
21
  # @param [Range] slot_range
41
22
  # @return [Class] A sub class of given AR model.
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module ShardFor
3
- VERSION = '0.6.1'.freeze
3
+ VERSION = '0.7.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-shard_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yuemori
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-29 00:00:00.000000000 Z
11
+ date: 2019-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.0
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 5.0.0
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 5.0.0
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: expeditor
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,47 +53,47 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.1.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: bundler
56
+ name: appraisal
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.14'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1.14'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '1.14'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '1.14'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rspec
84
+ name: codeclimate-test-reporter
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.0'
89
+ version: 1.0.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '3.0'
96
+ version: 1.0.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: guard-rubocop
112
+ name: guard-rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: guard-rspec
126
+ name: guard-rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: rubocop
154
+ name: rake
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -165,21 +165,21 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
- name: appraisal
168
+ name: rspec
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ">="
171
+ - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0'
173
+ version: '3.0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ">="
178
+ - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '0'
180
+ version: '3.0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: sqlite3
182
+ name: rspec-parameterized
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
@@ -193,7 +193,7 @@ dependencies:
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
- name: rspec-parameterized
196
+ name: rubocop
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - ">="
@@ -207,19 +207,19 @@ dependencies:
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  - !ruby/object:Gem::Dependency
210
- name: codeclimate-test-reporter
210
+ name: sqlite3
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: 1.0.0
215
+ version: 1.3.6
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: 1.0.0
222
+ version: 1.3.6
223
223
  description: Database sharding library for ActiveRecord
224
224
  email:
225
225
  - yuemori@aiming-inc.com
@@ -245,6 +245,7 @@ files:
245
245
  - gemfiles/ar_5.0.gemfile
246
246
  - gemfiles/ar_5.1.gemfile
247
247
  - gemfiles/ar_5.2.gemfile
248
+ - gemfiles/ar_6.0.gemfile
248
249
  - gemfiles/rails_edge.gemfile
249
250
  - lib/activerecord/shard_for.rb
250
251
  - lib/activerecord/shard_for/abstract_shard_repository.rb
@@ -285,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
286
  version: '0'
286
287
  requirements: []
287
288
  rubyforge_project:
288
- rubygems_version: 2.6.13
289
+ rubygems_version: 2.7.6
289
290
  signing_key:
290
291
  specification_version: 4
291
292
  summary: Database sharding library for ActiveRecord