activerecord-turntable 2.3.3 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/CHANGELOG.md +11 -0
- data/Rakefile +1 -0
- data/activerecord-turntable.gemspec +4 -3
- data/lib/active_record/turntable/active_record_ext/abstract_adapter.rb +6 -5
- data/lib/active_record/turntable/active_record_ext/locking_optimistic.rb +7 -8
- data/lib/active_record/turntable/active_record_ext/schema_dumper.rb +8 -2
- data/lib/active_record/turntable/version.rb +1 -1
- data/spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb +14 -1
- data/spec/models/user_status.rb +1 -0
- metadata +24 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d9d385f15413261bc87c1e2444193c53a9ee657
|
4
|
+
data.tar.gz: '009577b936eded2be655a3b850787a14dfd03cbf'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce1c55a07c1b94377e206d4cf97b2fbb961bb0bf1025d0150c540771eff0fa56df3f0360741b4102aaef698c5913da463fc459c23016b7c28c699fac79e5c548
|
7
|
+
data.tar.gz: e74cfd821f2c84ddeec7a950335a017f8cc058cece9daee3ce2f5c3a67a3969009a5486714cd822eef412c6f01f595e001f8685f1bce4cdb82f750951ea008e5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## activerecord-turntable 2.4.0 ##
|
2
|
+
|
3
|
+
### Incompatible Change
|
4
|
+
|
5
|
+
* Drop support for ruby 1.9.3
|
6
|
+
|
7
|
+
### Bugfix
|
8
|
+
|
9
|
+
* Update activerecord 4.2 patches
|
10
|
+
* Fixes optimistic locking with a serialized column causes JSON::Error.
|
11
|
+
|
1
12
|
## activerecord-turntable 2.3.3 ##
|
2
13
|
|
3
14
|
### Bugfix
|
data/Rakefile
CHANGED
@@ -62,6 +62,7 @@ namespace :turntable do
|
|
62
62
|
t.belongs_to :user, :null => false
|
63
63
|
t.integer :hp, :null => false, :default => 0
|
64
64
|
t.integer :mp, :null => false, :default => 0
|
65
|
+
t.text :data
|
65
66
|
t.integer :lock_version, :null => false, :default => 0
|
66
67
|
t.datetime :deleted_at, :default => nil
|
67
68
|
t.timestamps
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
23
|
spec.require_paths = ["lib"]
|
24
|
-
spec.required_ruby_version = '>=
|
24
|
+
spec.required_ruby_version = '>= 2.0.0'
|
25
25
|
|
26
26
|
spec.add_runtime_dependency "activerecord", ">= 4.0.0", "< 5.0"
|
27
27
|
spec.add_runtime_dependency "activesupport", ">= 4.0.0", "< 5.0"
|
@@ -35,8 +35,8 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency "mysql2"
|
36
36
|
|
37
37
|
spec.add_development_dependency "rake"
|
38
|
-
spec.add_development_dependency "rack"
|
39
|
-
spec.add_development_dependency "rspec", "~> 3.
|
38
|
+
spec.add_development_dependency "rack", "< 2"
|
39
|
+
spec.add_development_dependency "rspec", "~> 3.5.0"
|
40
40
|
spec.add_development_dependency "rspec-its"
|
41
41
|
spec.add_development_dependency "rspec-collection_matchers"
|
42
42
|
spec.add_development_dependency "fabrication"
|
@@ -47,6 +47,7 @@ Gem::Specification.new do |spec|
|
|
47
47
|
spec.add_development_dependency "pry-byebug"
|
48
48
|
end
|
49
49
|
spec.add_development_dependency "guard-rspec"
|
50
|
+
spec.add_development_dependency "listen", "= 3.0.6"
|
50
51
|
spec.add_development_dependency "coveralls"
|
51
52
|
|
52
53
|
if RUBY_PLATFORM =~ /darwin/
|
@@ -7,13 +7,14 @@ module ActiveRecord::Turntable
|
|
7
7
|
protected
|
8
8
|
|
9
9
|
# @note override for logging current shard name
|
10
|
-
def log(sql, name = "SQL", binds = [])
|
10
|
+
def log(sql, name = "SQL", binds = [], statement_name = nil)
|
11
11
|
@instrumenter.instrument(
|
12
12
|
"sql.active_record",
|
13
|
-
:sql
|
14
|
-
:name
|
15
|
-
:connection_id
|
16
|
-
:
|
13
|
+
:sql => sql,
|
14
|
+
:name => name,
|
15
|
+
:connection_id => object_id,
|
16
|
+
:statement_name => statement_name,
|
17
|
+
:binds => binds,
|
17
18
|
:turntable_shard_name => turntable_shard_name) { yield }
|
18
19
|
rescue Exception => e
|
19
20
|
message = "#{e.class.name}: #{e.message}: #{sql} : #{turntable_shard_name}"
|
@@ -122,10 +122,10 @@ module ActiveRecord::Turntable
|
|
122
122
|
relation = self.class.unscoped
|
123
123
|
|
124
124
|
condition_scope = relation.where(
|
125
|
-
|
126
|
-
|
127
|
-
)
|
125
|
+
self.class.primary_key => id,
|
126
|
+
lock_col => previous_lock_value,
|
128
127
|
)
|
128
|
+
|
129
129
|
if klass.turntable_enabled? and klass.primary_key != klass.turntable_shard_key.to_s
|
130
130
|
condition_scope = condition_scope.where(
|
131
131
|
relation.table[klass.turntable_shard_key].eq(
|
@@ -134,13 +134,12 @@ module ActiveRecord::Turntable
|
|
134
134
|
)
|
135
135
|
end
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
137
|
+
affected_rows = condition_scope.update_all(
|
138
|
+
Hash[attributes_for_update(attribute_names).map do |name|
|
139
|
+
[name, _read_attribute(name)]
|
140
|
+
end]
|
140
141
|
)
|
141
142
|
|
142
|
-
affected_rows = self.class.connection.update stmt
|
143
|
-
|
144
143
|
unless affected_rows == 1
|
145
144
|
raise ActiveRecord::StaleObjectError.new(self, "update")
|
146
145
|
end
|
@@ -32,14 +32,20 @@ module ActiveRecord::Turntable
|
|
32
32
|
if pkcol
|
33
33
|
if pk != 'id'
|
34
34
|
tbl.print %Q(, primary_key: "#{pk}")
|
35
|
+
elsif pkcol.sql_type == 'bigint'
|
36
|
+
tbl.print ", id: :bigserial"
|
35
37
|
elsif pkcol.sql_type == 'uuid'
|
36
38
|
tbl.print ", id: :uuid"
|
37
|
-
tbl.print %Q(, default: "#{pkcol.default_function}")
|
39
|
+
tbl.print %Q(, default: "#{pkcol.default_function.inspect}")
|
38
40
|
end
|
39
41
|
else
|
40
42
|
tbl.print ", id: false"
|
41
43
|
end
|
42
|
-
|
44
|
+
if Util.earlier_than_ar42?
|
45
|
+
tbl.print ", force: true"
|
46
|
+
else
|
47
|
+
tbl.print ", force: :cascade"
|
48
|
+
end
|
43
49
|
tbl.puts " do |t|"
|
44
50
|
|
45
51
|
# then dump all non-primary key columns
|
@@ -10,10 +10,14 @@ describe ActiveRecord::Turntable::ActiveRecordExt::LockingOptimistic do
|
|
10
10
|
truncate_shard
|
11
11
|
end
|
12
12
|
|
13
|
-
before do
|
13
|
+
before(:each) do
|
14
14
|
ActiveRecord::Base.turntable_config.instance_variable_get(:@config)[:raise_on_not_specified_shard_update] = true
|
15
15
|
end
|
16
16
|
|
17
|
+
after(:each) do
|
18
|
+
ActiveRecord::Base.turntable_config.instance_variable_get(:@config)[:raise_on_not_specified_shard_update] = false
|
19
|
+
end
|
20
|
+
|
17
21
|
let!(:user_status) do
|
18
22
|
user_status = UserStatus.new(user_id: 1)
|
19
23
|
user_status.id = 10
|
@@ -25,4 +29,13 @@ describe ActiveRecord::Turntable::ActiveRecordExt::LockingOptimistic do
|
|
25
29
|
subject { user_status.update_attributes(hp: 20) }
|
26
30
|
it { expect { subject }.to change(user_status, :lock_version).by(1) }
|
27
31
|
end
|
32
|
+
|
33
|
+
describe "Json serialized column is saved" do
|
34
|
+
before do
|
35
|
+
user_status.update_attributes(data: {foo: 'bar'})
|
36
|
+
user_status.reload
|
37
|
+
end
|
38
|
+
subject { user_status.data }
|
39
|
+
it { expect { subject }.to_not raise_error }
|
40
|
+
end
|
28
41
|
end
|
data/spec/models/user_status.rb
CHANGED
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.
|
4
|
+
version: 2.4.0
|
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
|
@@ -153,30 +153,30 @@ dependencies:
|
|
153
153
|
name: rack
|
154
154
|
requirement: !ruby/object:Gem::Requirement
|
155
155
|
requirements:
|
156
|
-
- - "
|
156
|
+
- - "<"
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version: '
|
158
|
+
version: '2'
|
159
159
|
type: :development
|
160
160
|
prerelease: false
|
161
161
|
version_requirements: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
|
-
- - "
|
163
|
+
- - "<"
|
164
164
|
- !ruby/object:Gem::Version
|
165
|
-
version: '
|
165
|
+
version: '2'
|
166
166
|
- !ruby/object:Gem::Dependency
|
167
167
|
name: rspec
|
168
168
|
requirement: !ruby/object:Gem::Requirement
|
169
169
|
requirements:
|
170
170
|
- - "~>"
|
171
171
|
- !ruby/object:Gem::Version
|
172
|
-
version: 3.
|
172
|
+
version: 3.5.0
|
173
173
|
type: :development
|
174
174
|
prerelease: false
|
175
175
|
version_requirements: !ruby/object:Gem::Requirement
|
176
176
|
requirements:
|
177
177
|
- - "~>"
|
178
178
|
- !ruby/object:Gem::Version
|
179
|
-
version: 3.
|
179
|
+
version: 3.5.0
|
180
180
|
- !ruby/object:Gem::Dependency
|
181
181
|
name: rspec-its
|
182
182
|
requirement: !ruby/object:Gem::Requirement
|
@@ -289,6 +289,20 @@ dependencies:
|
|
289
289
|
- - ">="
|
290
290
|
- !ruby/object:Gem::Version
|
291
291
|
version: '0'
|
292
|
+
- !ruby/object:Gem::Dependency
|
293
|
+
name: listen
|
294
|
+
requirement: !ruby/object:Gem::Requirement
|
295
|
+
requirements:
|
296
|
+
- - '='
|
297
|
+
- !ruby/object:Gem::Version
|
298
|
+
version: 3.0.6
|
299
|
+
type: :development
|
300
|
+
prerelease: false
|
301
|
+
version_requirements: !ruby/object:Gem::Requirement
|
302
|
+
requirements:
|
303
|
+
- - '='
|
304
|
+
- !ruby/object:Gem::Version
|
305
|
+
version: 3.0.6
|
292
306
|
- !ruby/object:Gem::Dependency
|
293
307
|
name: coveralls
|
294
308
|
requirement: !ruby/object:Gem::Requirement
|
@@ -464,7 +478,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
464
478
|
requirements:
|
465
479
|
- - ">="
|
466
480
|
- !ruby/object:Gem::Version
|
467
|
-
version:
|
481
|
+
version: 2.0.0
|
468
482
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
469
483
|
requirements:
|
470
484
|
- - ">="
|
@@ -472,7 +486,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
472
486
|
version: '0'
|
473
487
|
requirements: []
|
474
488
|
rubyforge_project: activerecord-turntable
|
475
|
-
rubygems_version: 2.5.
|
489
|
+
rubygems_version: 2.5.2
|
476
490
|
signing_key:
|
477
491
|
specification_version: 4
|
478
492
|
summary: ActiveRecord sharding extension
|
@@ -524,4 +538,3 @@ test_files:
|
|
524
538
|
- spec/spec_helper.rb
|
525
539
|
- spec/support/matchers/be_saved_to.rb
|
526
540
|
- spec/support/turntable_helper.rb
|
527
|
-
has_rdoc:
|