activerecord-turntable 2.0.0 → 2.0.1
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 +8 -0
- data/CHANGELOG.md +7 -2
- data/README.md +1 -1
- data/gemfiles/rails4_2.gemfile +6 -0
- data/lib/active_record/turntable/active_record_ext/persistence.rb +23 -0
- data/lib/active_record/turntable/version.rb +1 -1
- data/spec/active_record/turntable/active_record_ext/persistence_spec.rb +9 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea1d2ba178b8f954997d629e4c9a3a15778a4665
|
4
|
+
data.tar.gz: 927a91641d773d1581c8fcdbdbb9597254d12994
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad6610a34a060ab4bb06c89b3c33acda3578a47b72e69b68acdd3ddb81d2beb245dd27c32f26bdc5af740ecf2b4a3d419465e54da287c46f12147285c0fce497
|
7
|
+
data.tar.gz: 0ab419118d5511b0176a2720d26a4cb24c29336c823f949eb5e4538fb69a567b5dc111cd40e1e5a677d15eb48c4e81a326e684b93f4ae46eca0fea8e9d9602b1
|
data/.travis.yml
CHANGED
@@ -3,9 +3,17 @@ rvm:
|
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
5
|
- 2.1.2
|
6
|
+
- 2.2
|
7
|
+
- ruby-head
|
6
8
|
gemfile:
|
7
9
|
- gemfiles/rails4_0.gemfile
|
8
10
|
- gemfiles/rails4_1.gemfile
|
11
|
+
- gemfiles/rails4_2.gemfile
|
9
12
|
before_script:
|
10
13
|
- bundle exec rake turntable:db:reset
|
11
14
|
script: bundle exec rake spec
|
15
|
+
matrix:
|
16
|
+
allow_failures:
|
17
|
+
- rvm: 2.2
|
18
|
+
- rvm: ruby-head
|
19
|
+
- gemfile: gemfiles/rails4_2.gemfile
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## activerecord-turntable 2.0.1 ##
|
2
|
+
|
3
|
+
### Bugfixes
|
4
|
+
* support `update_columns`
|
5
|
+
|
1
6
|
## activerecord-turntable 2.0.0 ##
|
2
7
|
|
3
8
|
First release for ActiveRecord 4.x
|
@@ -34,7 +39,7 @@ Supported [barrage](http://github.com/drecom/barrage) gem as sequencer
|
|
34
39
|
|
35
40
|
When using association(or association preloading), Turntable would add shard key condition to relation object if associated models has the same shard key name.
|
36
41
|
|
37
|
-
If two related models has different named keys(but same meaning), you can pass option `foreign_shard_key` to association option.
|
42
|
+
If two related models has different named keys(but same meaning), you can pass option `foreign_shard_key` to association option.
|
38
43
|
|
39
44
|
Example:
|
40
45
|
|
@@ -58,7 +63,7 @@ Add follow option to `turntable.yml`:
|
|
58
63
|
To create transaction to all shards on the cluster:
|
59
64
|
|
60
65
|
```ruby
|
61
|
-
User.user_cluster_transaction do
|
66
|
+
User.user_cluster_transaction do
|
62
67
|
# transaction opened on all shards in 'user_cluster'
|
63
68
|
end
|
64
69
|
```
|
data/README.md
CHANGED
@@ -56,6 +56,29 @@ module ActiveRecord::Turntable::ActiveRecordExt
|
|
56
56
|
|
57
57
|
finder_scope.where(primary_key => self[primary_key]).update_all(changes) == 1
|
58
58
|
end
|
59
|
+
|
60
|
+
# @note Override to add sharding scope on `update_columns`
|
61
|
+
def update_columns(attributes)
|
62
|
+
raise ActiveRecordError, "cannot update on a new record object" unless persisted?
|
63
|
+
|
64
|
+
attributes.each_key do |key|
|
65
|
+
verify_readonly_attribute(key.to_s)
|
66
|
+
end
|
67
|
+
|
68
|
+
update_scope = if turntable_enabled? and self.class.primary_key != self.class.turntable_shard_key.to_s
|
69
|
+
self.class.unscoped.where(self.class.turntable_shard_key => self.send(turntable_shard_key))
|
70
|
+
else
|
71
|
+
self.class.unscoped
|
72
|
+
end
|
73
|
+
|
74
|
+
updated_count = update_scope.where(self.class.primary_key => id).update_all(attributes)
|
75
|
+
|
76
|
+
attributes.each do |k, v|
|
77
|
+
raw_write_attribute(k, v)
|
78
|
+
end
|
79
|
+
|
80
|
+
updated_count == 1
|
81
|
+
end
|
59
82
|
end
|
60
83
|
|
61
84
|
private
|
@@ -152,6 +152,15 @@ describe ActiveRecord::Turntable::ActiveRecordExt::Persistence do
|
|
152
152
|
expect { user_status.lock! }.to_not raise_error
|
153
153
|
expect(strio.string.split("\n").select {|stmt| stmt =~ /SELECT/ and stmt !~ /Turntable/ }).to have(1).items
|
154
154
|
end
|
155
|
+
|
156
|
+
it "should execute one query when update_columns" do
|
157
|
+
user; user_status
|
158
|
+
strio = StringIO.new
|
159
|
+
ActiveRecord::Base.logger = Logger.new(strio)
|
160
|
+
|
161
|
+
expect { user_status.update_columns(hp: 10) }.to_not raise_error
|
162
|
+
expect(strio.string.split("\n").select {|stmt| stmt =~ /UPDATE/ and stmt !~ /Turntable/ }).to have(1).items
|
163
|
+
end
|
155
164
|
end
|
156
165
|
|
157
166
|
context "When the model is not sharded" 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: 2.0.
|
4
|
+
version: 2.0.1
|
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: 2014-11-
|
12
|
+
date: 2014-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -314,6 +314,7 @@ files:
|
|
314
314
|
- activerecord-turntable.gemspec
|
315
315
|
- gemfiles/rails4_0.gemfile
|
316
316
|
- gemfiles/rails4_1.gemfile
|
317
|
+
- gemfiles/rails4_2.gemfile
|
317
318
|
- lib/active_record/turntable.rb
|
318
319
|
- lib/active_record/turntable/active_record_ext.rb
|
319
320
|
- lib/active_record/turntable/active_record_ext/.gitkeep
|
@@ -480,4 +481,3 @@ test_files:
|
|
480
481
|
- spec/spec_helper.rb
|
481
482
|
- spec/support/matchers/be_saved_to.rb
|
482
483
|
- spec/support/turntable_helper.rb
|
483
|
-
has_rdoc:
|