activerecord-turntable 3.0.0.alpha1 → 3.0.0.alpha2
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/.travis.yml +2 -2
- data/CHANGELOG.md +9 -2
- data/Gemfile +2 -2
- data/activerecord-turntable.gemspec +1 -1
- data/gemfiles/rails5_0.gemfile +2 -2
- data/lib/active_record/turntable/active_record_ext.rb +1 -1
- data/lib/active_record/turntable/active_record_ext/association.rb +10 -35
- data/lib/active_record/turntable/version.rb +1 -1
- data/spec/active_record/turntable/active_record_ext/association_spec.rb +12 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab82abdd16e36a30d5c3b55f5cb5ff61d7142dcd
|
4
|
+
data.tar.gz: 4ece75789087ee54b31484601390ed16392aca31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f11dca6559d5539c44cf82d863e88acb793eace6fc527d1fe900d8c424fc3f633615242eebd9e86c7977b92b05cb64e0e2f799826e19c12fc13ac84165fac13d
|
7
|
+
data.tar.gz: 250ab4d9806440953e10acb8f7b94a6b0fc564f54859e8f6c99e69396c598246b1d85f6a0193d76e4555ef366baee651091740733948808c1f6111c259568e4c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
-
## activerecord-turntable 3.0.0.
|
1
|
+
## activerecord-turntable 3.0.0.alpha2 ##
|
2
|
+
|
3
|
+
### Improvement
|
4
|
+
|
5
|
+
* Fix to propagate shard conditions to `AssociationRelation` too
|
6
|
+
|
7
|
+
## activerecord-turntable 3.0.0.alpha1 ##
|
8
|
+
|
9
|
+
### Major Changes
|
2
10
|
|
3
11
|
* Rails5 compatibility
|
4
12
|
* Minimum ruby requirement version is `2.2.2`
|
5
13
|
* Rails 4.x support has been dropped.
|
6
14
|
|
7
|
-
|
8
15
|
## activerecord-turntable 2.3.3 ##
|
9
16
|
|
10
17
|
### Bugfix
|
data/Gemfile
CHANGED
@@ -43,7 +43,7 @@ Gem::Specification.new do |spec|
|
|
43
43
|
spec.add_development_dependency "pry-byebug"
|
44
44
|
spec.add_development_dependency "rack"
|
45
45
|
spec.add_development_dependency "rake"
|
46
|
-
spec.add_development_dependency "rspec", "~> 3.
|
46
|
+
spec.add_development_dependency "rspec", "~> 3.5.0"
|
47
47
|
spec.add_development_dependency "rspec-collection_matchers"
|
48
48
|
spec.add_development_dependency "rspec-its"
|
49
49
|
spec.add_development_dependency "rubocop"
|
data/gemfiles/rails5_0.gemfile
CHANGED
@@ -30,7 +30,7 @@ module ActiveRecord::Turntable
|
|
30
30
|
ActiveRecord::Migration.include(ActiveRecord::Turntable::Migration)
|
31
31
|
ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(ConnectionHandlerExtension)
|
32
32
|
ActiveRecord::Associations::Preloader::Association.prepend(AssociationPreloader)
|
33
|
-
ActiveRecord::Associations::Association.
|
33
|
+
ActiveRecord::Associations::Association.prepend(Association)
|
34
34
|
require "active_record/turntable/active_record_ext/fixtures"
|
35
35
|
require "active_record/turntable/active_record_ext/migration_proxy"
|
36
36
|
require "active_record/turntable/active_record_ext/activerecord_import_ext"
|
@@ -3,49 +3,24 @@ require "active_record/associations"
|
|
3
3
|
module ActiveRecord::Turntable
|
4
4
|
module ActiveRecordExt
|
5
5
|
module Association
|
6
|
-
extend ActiveSupport::Concern
|
7
6
|
include ShardingCondition
|
8
7
|
|
9
|
-
|
10
|
-
ActiveRecord::Associations::SingularAssociation.prepend(SingularAssociationExt)
|
11
|
-
ActiveRecord::Associations::CollectionAssociation.prepend(CollectionAssociationExt)
|
8
|
+
def self.prepended(mod)
|
12
9
|
ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :foreign_shard_key
|
13
10
|
end
|
14
11
|
|
15
|
-
|
16
|
-
module SingularAssociationExt
|
17
|
-
private
|
18
|
-
def get_records
|
19
|
-
# OPTIMIZE: statement caching
|
20
|
-
if should_use_shard_key?
|
21
|
-
return turntable_scope(scope).limit(1).records
|
22
|
-
end
|
12
|
+
protected
|
23
13
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
# @note Inject to add sharding condition for collection association
|
29
|
-
module CollectionAssociationExt
|
30
|
-
private
|
31
|
-
def get_records
|
32
|
-
# OPTIMIZE: statement caching
|
33
|
-
if should_use_shard_key?
|
34
|
-
return turntable_scope(scope).to_a
|
35
|
-
end
|
14
|
+
# @note Override to pass shard key conditions
|
15
|
+
def target_scope
|
16
|
+
return super unless should_use_shard_key?
|
36
17
|
|
37
|
-
|
38
|
-
|
18
|
+
scope = klass.where(
|
19
|
+
klass.turntable_shard_key =>
|
20
|
+
owner.send(foreign_shard_key)
|
21
|
+
)
|
22
|
+
super.merge!(scope)
|
39
23
|
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def turntable_scope(scope, bind = nil)
|
44
|
-
if should_use_shard_key?
|
45
|
-
scope = scope.where(klass.turntable_shard_key => owner.send(foreign_shard_key))
|
46
|
-
end
|
47
|
-
scope
|
48
|
-
end
|
49
24
|
end
|
50
25
|
end
|
51
26
|
end
|
@@ -47,11 +47,20 @@ describe ActiveRecord::Turntable::ActiveRecordExt::Association do
|
|
47
47
|
ActiveRecord::Base.turntable_config.instance_variable_get(:@config)[:raise_on_not_specified_shard_query] = true
|
48
48
|
end
|
49
49
|
let(:cards_user) { CardsUser.where(user: user).first }
|
50
|
+
let(:cards_users_history) { cards_users_histories.find { |history| history.user_id == user.id } }
|
50
51
|
|
51
52
|
context "associated objects has same turntable_key" do
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
context "AssociationRelation#to_a" do
|
54
|
+
subject { cards_user.cards_users_histories.to_a }
|
55
|
+
it { expect { subject }.to_not raise_error }
|
56
|
+
it { is_expected.to include(*cards_users_histories.select { |history| history.cards_user_id == cards_user.id }) }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "AssociationRelation#where" do
|
60
|
+
subject { cards_user.cards_users_histories.where(id: cards_users_history.id).to_a }
|
61
|
+
it { expect { subject }.to_not raise_error }
|
62
|
+
it { is_expected.to include(cards_users_history) }
|
63
|
+
end
|
55
64
|
end
|
56
65
|
|
57
66
|
context "associated objects has different turntable_key" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-turntable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.alpha2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gussan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -281,14 +281,14 @@ dependencies:
|
|
281
281
|
requirements:
|
282
282
|
- - "~>"
|
283
283
|
- !ruby/object:Gem::Version
|
284
|
-
version: 3.
|
284
|
+
version: 3.5.0
|
285
285
|
type: :development
|
286
286
|
prerelease: false
|
287
287
|
version_requirements: !ruby/object:Gem::Requirement
|
288
288
|
requirements:
|
289
289
|
- - "~>"
|
290
290
|
- !ruby/object:Gem::Version
|
291
|
-
version: 3.
|
291
|
+
version: 3.5.0
|
292
292
|
- !ruby/object:Gem::Dependency
|
293
293
|
name: rspec-collection_matchers
|
294
294
|
requirement: !ruby/object:Gem::Requirement
|
@@ -526,7 +526,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
526
526
|
version: 1.3.1
|
527
527
|
requirements: []
|
528
528
|
rubyforge_project: activerecord-turntable
|
529
|
-
rubygems_version: 2.5.
|
529
|
+
rubygems_version: 2.5.2
|
530
530
|
signing_key:
|
531
531
|
specification_version: 4
|
532
532
|
summary: ActiveRecord sharding extension
|