activerecord-turntable 2.0.0 → 2.0.1

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
  SHA1:
3
- metadata.gz: 5ed732d4f5ce27c8ec309d715a01e33bc4e287f2
4
- data.tar.gz: e026370254d526d21205b9a72cd0a05e8df5d355
3
+ metadata.gz: ea1d2ba178b8f954997d629e4c9a3a15778a4665
4
+ data.tar.gz: 927a91641d773d1581c8fcdbdbb9597254d12994
5
5
  SHA512:
6
- metadata.gz: 77aa461ca4b2c0ce44589ffb756f8c49cfa263040b435235cfd9afd38d0469086c8a6e33ee2b1d82badbefbede00d640cdae145581f4cae9363eac271ee16cbc
7
- data.tar.gz: f78bc87da3c3e41717f2a2cbd797a96fd7a07dc12daa274b7b8ff30c03055950f78c0b083b788d107e5744379acafea0cdde7d5f80e2cbe896d8b0c89db0fba5
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
@@ -22,7 +22,7 @@ Currently supports mysql only.
22
22
  Add to Gemfile:
23
23
 
24
24
  ```ruby
25
- gem 'activerecord-turntable', '~> 2.0.0.beta'
25
+ gem 'activerecord-turntable', '~> 2.0.0'
26
26
  ```
27
27
 
28
28
  Run a bundle install:
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', "= 4.2.0.beta4"
4
+ gem 'activesupport', "= 4.2.0.beta4"
5
+
6
+ gemspec :path => '../'
@@ -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
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Turntable
3
- VERSION = "2.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
5
5
  end
@@ -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.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-10 00:00:00.000000000 Z
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: