activerecord-sharding 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/.travis.yml +8 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile +2 -0
- data/README.md +18 -2
- data/activerecord-sharding.gemspec +1 -3
- data/ar41.gemfile +6 -0
- data/ar416.gemfile +6 -0
- data/lib/active_record/sharding/abstract_repository.rb +1 -1
- data/lib/active_record/sharding/cluster_config.rb +1 -1
- data/lib/active_record/sharding/database_tasks.rb +57 -40
- data/lib/active_record/sharding/errors.rb +3 -0
- data/lib/active_record/sharding/model.rb +19 -4
- data/lib/active_record/sharding/sequencer.rb +14 -5
- data/lib/active_record/sharding/sequencer_config.rb +2 -2
- data/lib/active_record/sharding/sequencer_repository.rb +3 -3
- data/lib/active_record/sharding/shard_repository.rb +3 -3
- data/lib/active_record/sharding/version.rb +1 -1
- data/spec/active_record/sharding/model_spec.rb +53 -0
- data/spec/active_record/sharding/sequencer_spec.rb +32 -7
- metadata +9 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74c9354eb637b74252c1ee7631037140ad0326ea
|
4
|
+
data.tar.gz: c6adaf64d167afd9dbf16a0e3982158181255a9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c74278a9bae13cf05ccbf4fda5abf98cebec86c90ad3489cb2f18ea3eb0c4e150a0725b8151003d95712a9f989b7812f6b8da007fe01ea78e9738f94c77c0b5
|
7
|
+
data.tar.gz: b0ed70dc49f1d1cb389ed6313991b1ac21013f7720211d62ff57e1e253a82c3fcdbaa6ebd0d938227c0d80d324ca6044532160abdac7f9ac2c1f569168c8accb
|
data/.rubocop.yml
CHANGED
@@ -27,6 +27,12 @@ Style/ModuleFunction:
|
|
27
27
|
Style/StringLiterals:
|
28
28
|
EnforcedStyle: double_quotes
|
29
29
|
|
30
|
+
Style/IndentationConsistency:
|
31
|
+
EnforcedStyle: rails
|
32
|
+
|
33
|
+
Style/SignalException:
|
34
|
+
EnforcedStyle: only_raise
|
35
|
+
|
30
36
|
Style/HashSyntax:
|
31
37
|
EnforcedStyle: ruby19_no_mixed_keys
|
32
38
|
Exclude:
|
@@ -41,6 +47,9 @@ Metrics/LineLength:
|
|
41
47
|
Lint/AssignmentInCondition:
|
42
48
|
Enabled: false
|
43
49
|
|
50
|
+
Lint/BlockAlignment:
|
51
|
+
Enabled: false
|
52
|
+
|
44
53
|
Metrics/MethodLength:
|
45
54
|
Max: 12
|
46
55
|
|
data/.travis.yml
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
language: ruby
|
2
|
+
install: bundle install --jobs=3 --retry=3
|
2
3
|
rvm:
|
3
|
-
- 2.2.
|
4
|
-
- 2.1.
|
5
|
-
- 2.0.0-
|
6
|
-
|
4
|
+
- 2.2.4
|
5
|
+
- 2.1.8
|
6
|
+
- 2.0.0-p648
|
7
|
+
gemfile:
|
8
|
+
- Gemfile
|
9
|
+
- ar41.gemfile
|
10
|
+
- ar416.gemfile
|
7
11
|
services:
|
8
12
|
- mysql
|
9
13
|
script:
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [v0.1.0](https://github.com/hirocaster/activerecord-sharding/tree/v0.1.0) (2015-08-27)
|
4
|
+
**Merged pull requests:**
|
5
|
+
|
6
|
+
- Refactor etc ... [\#7](https://github.com/hirocaster/activerecord-sharding/pull/7) ([hirocaster](https://github.com/hirocaster))
|
7
|
+
- Refactor class repository [\#6](https://github.com/hirocaster/activerecord-sharding/pull/6) ([hirocaster](https://github.com/hirocaster))
|
8
|
+
- Add codeclimate-test-reporter [\#5](https://github.com/hirocaster/activerecord-sharding/pull/5) ([hirocaster](https://github.com/hirocaster))
|
9
|
+
- Change coding style [\#4](https://github.com/hirocaster/activerecord-sharding/pull/4) ([hirocaster](https://github.com/hirocaster))
|
10
|
+
- Setup coveralls [\#3](https://github.com/hirocaster/activerecord-sharding/pull/3) ([hirocaster](https://github.com/hirocaster))
|
11
|
+
- Setup travis ci [\#2](https://github.com/hirocaster/activerecord-sharding/pull/2) ([hirocaster](https://github.com/hirocaster))
|
12
|
+
- Change namespace ActiveRecordSharding to ActiveRecord::Sharding [\#1](https://github.com/hirocaster/activerecord-sharding/pull/1) ([hirocaster](https://github.com/hirocaster))
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActiveRecord::Sharding
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/hirocaster/activerecord-sharding.svg)](https://travis-ci.org/hirocaster/activerecord-sharding) [![Coverage Status](https://coveralls.io/repos/hirocaster/activerecord-sharding/badge.svg?branch=
|
3
|
+
[![Build Status](https://travis-ci.org/hirocaster/activerecord-sharding.svg)](https://travis-ci.org/hirocaster/activerecord-sharding) [![Coverage Status](https://coveralls.io/repos/hirocaster/activerecord-sharding/badge.svg?branch=master&service=github)](https://coveralls.io/github/hirocaster/activerecord-sharding?branch=master) [![Code Climate](https://codeclimate.com/github/hirocaster/activerecord-sharding/badges/gpa.svg)](https://codeclimate.com/github/hirocaster/activerecord-sharding) [![Dependency Status](https://gemnasium.com/hirocaster/activerecord-sharding.svg)](https://gemnasium.com/hirocaster/activerecord-sharding)
|
4
4
|
|
5
5
|
Simple Database Sharding in ActiveRecord.
|
6
6
|
|
@@ -54,7 +54,7 @@ user_002:
|
|
54
54
|
host: localhost
|
55
55
|
|
56
56
|
user_003:
|
57
|
-
<<: *default
|
57
|
+
<<: *default
|
58
58
|
database: user_003
|
59
59
|
host: localhost
|
60
60
|
```
|
@@ -123,6 +123,16 @@ using `#put!` method.
|
|
123
123
|
user = User.put! name: 'foobar'
|
124
124
|
```
|
125
125
|
|
126
|
+
if transaction to shard database and nest other database transactions.
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
User.put!(name: 'foobar') do |new_user| # transaction for user shard database
|
130
|
+
OTHER_MODEL.transaction do
|
131
|
+
OTHER_MODEL.create!(user_id: new_user.id)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
126
136
|
returns User new object.
|
127
137
|
|
128
138
|
#### Select Query
|
@@ -136,6 +146,12 @@ User.shard_for(sharding_key).where(name: 'foorbar')
|
|
136
146
|
|
137
147
|
`#sahrd_for` is returns User class.
|
138
148
|
|
149
|
+
for all shards query
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
User.all_shards.flat_map { |model| model.find_by(name: 'foorbar') }.compact
|
153
|
+
```
|
154
|
+
|
139
155
|
#### Association/Relation
|
140
156
|
|
141
157
|
if use database association/relation in sharding databases.
|
@@ -20,12 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = ">= 2.0"
|
22
22
|
|
23
|
-
spec.add_dependency "activerecord", ">= 4.1.0"
|
24
|
-
|
25
23
|
spec.add_development_dependency "bundler", "~> 1.5"
|
26
24
|
spec.add_development_dependency "rake"
|
27
25
|
spec.add_development_dependency "rspec"
|
28
|
-
spec.add_development_dependency "mysql2"
|
26
|
+
spec.add_development_dependency "mysql2", "~> 0.3.18"
|
29
27
|
spec.add_development_dependency "pry"
|
30
28
|
spec.add_development_dependency "pry-byebug"
|
31
29
|
spec.add_development_dependency "awesome_print"
|
data/ar41.gemfile
ADDED
data/ar416.gemfile
ADDED
@@ -22,7 +22,7 @@ module ActiveRecord
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def generate_class_name(connection_name) # rubocop:disable Lint/UnusedMethodArgument
|
25
|
-
|
25
|
+
raise NotImplementedError, "#{self.class.name}.#{__method__} is an abstract method."
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -118,30 +118,30 @@ module ActiveRecord
|
|
118
118
|
|
119
119
|
private
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
121
|
+
def exec_task_for_all_databases(task_name, args)
|
122
|
+
cluster_name = cluster_name_or_error task_name, args
|
123
|
+
cluster = cluster_or_error cluster_name
|
124
|
+
cluster.connections.each do |connection_name|
|
125
|
+
__send__ task_name, connection_name.to_s
|
126
|
+
end
|
126
127
|
end
|
127
|
-
end
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
def cluster_name_or_error(name, args)
|
130
|
+
unless cluster_name = args[:cluster_name]
|
131
|
+
$stderr.puts <<-MSG
|
132
132
|
Missing cluster_name. Find cluster_name via `rake active_record:sharding:info` then call `rake "active_record:sharding:#{name}[$cluster_name]"`.
|
133
133
|
MSG
|
134
|
-
|
134
|
+
exit
|
135
|
+
end
|
136
|
+
cluster_name
|
135
137
|
end
|
136
|
-
cluster_name
|
137
|
-
end
|
138
138
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
139
|
+
def cluster_or_error(cluster_name)
|
140
|
+
fetch_cluster_config cluster_name.to_sym
|
141
|
+
rescue KeyError
|
142
|
+
$stderr.puts %(cluster name "#{cluster_name}" not found.)
|
143
|
+
exit
|
144
|
+
end
|
145
145
|
end
|
146
146
|
extend TaskOrganizerForSingleClusterTask
|
147
147
|
|
@@ -174,7 +174,7 @@ Missing cluster_name. Find cluster_name via `rake active_record:sharding:info` t
|
|
174
174
|
ActiveRecord::Base.establish_connection configuration
|
175
175
|
ActiveRecord::Tasks::DatabaseTasks.load_schema :ruby
|
176
176
|
else
|
177
|
-
|
177
|
+
raise "This version of ActiveRecord is not supported: v#{ActiveRecord::VERSION::STRING}"
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|
@@ -197,36 +197,53 @@ Missing cluster_name. Find cluster_name via `rake active_record:sharding:info` t
|
|
197
197
|
|
198
198
|
def insert_initial_record_sequencer_database(args)
|
199
199
|
sequencer = sequencer_or_error "insert_initial_record", args
|
200
|
-
|
201
|
-
|
200
|
+
records_count = sequencer_records_count sequencer
|
201
|
+
|
202
|
+
if records_count == 0
|
203
|
+
insert_initial_record_sql = "INSERT INTO #{sequencer.table_name} VALUES (0)"
|
204
|
+
execute sequencer.connection_name.to_s, insert_initial_record_sql
|
205
|
+
else
|
206
|
+
puts "Exist sequencer record in #{sequencer.table_name} table."
|
207
|
+
end
|
202
208
|
end
|
203
209
|
|
204
210
|
private
|
205
211
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
end
|
212
|
+
def sequencer_records_count(sequencer)
|
213
|
+
count_sql = "SELECT COUNT(*) FROM #{sequencer.table_name}"
|
214
|
+
count_result = execute sequencer.connection_name.to_s, count_sql
|
210
215
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
end
|
216
|
+
if count_result
|
217
|
+
count_result.first.first.to_i
|
218
|
+
else
|
219
|
+
0
|
220
|
+
end
|
221
|
+
end
|
218
222
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
+
def exec_task_for_sequencer_database(task_name, args)
|
224
|
+
sequencer = sequencer_or_error task_name, args
|
225
|
+
__send__ task_name, sequencer.connection_name.to_s
|
226
|
+
end
|
227
|
+
|
228
|
+
def sequencer_or_error(task_name, args)
|
229
|
+
sequencer_name = sequencer_name_or_error task_name, args
|
230
|
+
fetch_sequencer_config sequencer_name.to_sym
|
231
|
+
rescue KeyError
|
232
|
+
$stderr.puts %(sequencer name "#{sequencer_name}" not found.)
|
233
|
+
exit
|
234
|
+
end
|
235
|
+
|
236
|
+
def sequencer_name_or_error(task_name, args)
|
237
|
+
unless sequencer_name = args[:sequencer_name]
|
238
|
+
# rubocop:disable Metrics/LineLength
|
239
|
+
$stderr.puts <<-MSG
|
223
240
|
Missing sequencer_name. Find sequencer_name via `rake active_record:sharding:info` then call `rake "active_record:sharding:sequencer#{task_name}[$sequencer_name]"`.
|
224
241
|
MSG
|
225
|
-
|
226
|
-
|
242
|
+
exit
|
243
|
+
# rubocop:enable Metrics/LineLength
|
244
|
+
end
|
245
|
+
sequencer_name
|
227
246
|
end
|
228
|
-
sequencer_name
|
229
|
-
end
|
230
247
|
end
|
231
248
|
extend TasksForSingleSequencerTask
|
232
249
|
end # module DatabaseTasks
|
@@ -5,7 +5,9 @@ module ActiveRecord
|
|
5
5
|
module Model
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
included do
|
8
|
+
included do |base|
|
9
|
+
base.before_create :validate_id!
|
10
|
+
|
9
11
|
class_attribute :cluster_router, instance_writer: false
|
10
12
|
class_attribute :shard_repository, instance_writer: false
|
11
13
|
class_attribute :sharding_key, instance_writer: false
|
@@ -30,14 +32,21 @@ module ActiveRecord
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def put!(attributes)
|
33
|
-
|
35
|
+
raise "`sharding_key` is not defined. Use `define_sharding_key`." unless sharding_key
|
34
36
|
|
35
37
|
@before_put_callback.call(attributes) if @before_put_callback
|
36
38
|
|
37
39
|
if key = attributes[sharding_key] || attributes[sharding_key.to_s]
|
38
|
-
|
40
|
+
if block_given?
|
41
|
+
shard_for(key).transaction do
|
42
|
+
object = shard_for(key).create!(attributes)
|
43
|
+
yield(object)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
shard_for(key).create!(attributes)
|
47
|
+
end
|
39
48
|
else
|
40
|
-
|
49
|
+
raise ActiveRecord::Sharding::MissingShardingKeyAttribute
|
41
50
|
end
|
42
51
|
end
|
43
52
|
|
@@ -54,6 +63,12 @@ module ActiveRecord
|
|
54
63
|
instance_eval(&block)
|
55
64
|
end
|
56
65
|
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def validate_id!
|
70
|
+
raise ActiveRecord::Sharding::MissingPrimaryKey if attributes[self.class.primary_key].nil?
|
71
|
+
end
|
57
72
|
end
|
58
73
|
end
|
59
74
|
end
|
@@ -3,6 +3,13 @@ require "active_support/concern"
|
|
3
3
|
module ActiveRecord
|
4
4
|
module Sharding
|
5
5
|
module Sequencer
|
6
|
+
|
7
|
+
class Error < ActiveRecord::Sharding::Error
|
8
|
+
end
|
9
|
+
|
10
|
+
class NegativeNumberOffsetError < Error
|
11
|
+
end
|
12
|
+
|
6
13
|
extend ActiveSupport::Concern
|
7
14
|
|
8
15
|
included do
|
@@ -23,14 +30,16 @@ module ActiveRecord
|
|
23
30
|
execute_sql "id"
|
24
31
|
end
|
25
32
|
|
26
|
-
def next_sequence_id
|
27
|
-
|
33
|
+
def next_sequence_id(offset = 1)
|
34
|
+
raise NegativeNumberOffsetError if offset < 1
|
35
|
+
execute_sql "id +#{offset}"
|
28
36
|
end
|
29
37
|
|
30
38
|
def execute_sql(last_insert_id_args)
|
31
|
-
|
32
|
-
connection
|
33
|
-
|
39
|
+
sequencer_klass = sequencer_repository.fetch(sequencer_name)
|
40
|
+
connection = sequencer_klass.connection
|
41
|
+
connection.execute "UPDATE `#{sequencer_config.table_name}` SET id = LAST_INSERT_ID(#{last_insert_id_args})", sequencer_klass.name
|
42
|
+
res = connection.execute "SELECT LAST_INSERT_ID()", sequencer_klass.name
|
34
43
|
new_id = res.first.first.to_i
|
35
44
|
new_id
|
36
45
|
end
|
@@ -18,8 +18,8 @@ module ActiveRecord
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def validate_config!
|
21
|
-
|
22
|
-
|
21
|
+
raise "Nothing connection. Please call register_connection" if @connection_name.blank?
|
22
|
+
raise "Nothing table_name. Please call register_table_name" if @table_name.blank?
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -14,9 +14,9 @@ module ActiveRecord
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def generate_class_name(connection_name)
|
18
|
+
"SequencerFor#{connection_name.to_s.tr('-', '_').classify}"
|
19
|
+
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -23,9 +23,9 @@ module ActiveRecord
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def generate_class_name(connection_name)
|
27
|
+
"ShardFor#{connection_name.to_s.tr('-', '_').classify}"
|
28
|
+
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -42,6 +42,21 @@ describe ActiveRecord::Sharding::Model do
|
|
42
42
|
expect(alice.class.name).to match(/User::ShardFor/)
|
43
43
|
end
|
44
44
|
|
45
|
+
context "in transaction" do
|
46
|
+
it "when rollback" do
|
47
|
+
before_record_count = model.all_shards.map(&:count).reduce(:+)
|
48
|
+
|
49
|
+
model.put!(name: "Bob") do |bob|
|
50
|
+
expect(bob.persisted?).to be true
|
51
|
+
raise ActiveRecord::Rollback
|
52
|
+
end
|
53
|
+
|
54
|
+
after_record_count = model.all_shards.map(&:count).reduce(:+)
|
55
|
+
|
56
|
+
expect(after_record_count).to eq before_record_count
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
45
60
|
context 'next call #put!' do
|
46
61
|
let(:bob) { model.put! name: "Bob" }
|
47
62
|
let(:alice_connect_db) { alice.class.connection.pool.spec.config[:database] }
|
@@ -87,4 +102,42 @@ describe ActiveRecord::Sharding::Model do
|
|
87
102
|
expect(record.name).to eq("foo")
|
88
103
|
end
|
89
104
|
end
|
105
|
+
|
106
|
+
describe "Irregular use case" do
|
107
|
+
context "Not write before_put block" do
|
108
|
+
let!(:model) do
|
109
|
+
Class.new(ActiveRecord::Base) do
|
110
|
+
def self.name
|
111
|
+
"User"
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.sequence_id
|
115
|
+
@sequence_id ||= 0
|
116
|
+
end
|
117
|
+
|
118
|
+
class << self
|
119
|
+
attr_writer :sequence_id
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.next_sequence_id
|
123
|
+
self.sequence_id += 1
|
124
|
+
end
|
125
|
+
|
126
|
+
include ActiveRecord::Sharding::Model
|
127
|
+
use_sharding :user, :modulo
|
128
|
+
define_sharding_key :id
|
129
|
+
|
130
|
+
define_parent_methods do
|
131
|
+
def find_from_all_by_name(name)
|
132
|
+
all_shards.map { |m| m.find_by(name: name) }.compact.first
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "Raise MissingPrimaryKey at #save" do
|
139
|
+
expect { model.shard_for(1).new.save }.to raise_error ActiveRecord::Sharding::MissingPrimaryKey
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
90
143
|
end
|
@@ -12,20 +12,45 @@ describe ActiveRecord::Sharding::Model do
|
|
12
12
|
|
13
13
|
describe '#current_sequence_id' do
|
14
14
|
it "returns current sequence id" do
|
15
|
-
|
15
|
+
current_id = model.current_sequence_id
|
16
|
+
expect(current_id).to be_a_kind_of Fixnum
|
17
|
+
expect(model.current_sequence_id).to eq current_id
|
18
|
+
end
|
19
|
+
|
20
|
+
it "output class name to log" do
|
21
|
+
sequencer_klass = model.sequencer_repository.fetch(:user)
|
22
|
+
expect(sequencer_klass.connection).to receive(:execute).with(anything, "User::SequencerForTestUserSequencer").and_return([[0]]).twice
|
23
|
+
model.current_sequence_id
|
16
24
|
end
|
17
25
|
end
|
18
|
-
describe '#next_sequence_id' do
|
19
|
-
let(:current_id) { model.current_sequence_id }
|
20
|
-
let(:next_id) { model.next_sequence_id }
|
21
26
|
|
27
|
+
describe '#next_sequence_id' do
|
22
28
|
it "returns next sequence id" do
|
23
|
-
|
24
|
-
expect(next_id).to
|
29
|
+
next_id = model.current_sequence_id + 1
|
30
|
+
expect(next_id).to eq model.next_sequence_id
|
31
|
+
expect(next_id).to eq model.current_sequence_id
|
25
32
|
end
|
26
33
|
|
27
34
|
it "next sequence id > current sequence id" do
|
28
|
-
expect(
|
35
|
+
expect(model.current_sequence_id).to be < model.next_sequence_id
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when offset is selected" do
|
39
|
+
let(:offset) { 10 }
|
40
|
+
|
41
|
+
it "returns current_sequence_id with offset" do
|
42
|
+
next_id = model.current_sequence_id + offset
|
43
|
+
expect(next_id).to eq model.next_sequence_id(offset)
|
44
|
+
expect(next_id).to eq model.current_sequence_id
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when negative number in offset args" do
|
48
|
+
let(:offset) { -5 }
|
49
|
+
|
50
|
+
it "raise error" do
|
51
|
+
expect { model.next_sequence_id offset }.to raise_error ActiveRecord::Sharding::Sequencer::NegativeNumberOffsetError
|
52
|
+
end
|
53
|
+
end
|
29
54
|
end
|
30
55
|
end
|
31
56
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-sharding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hirocaster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activerecord
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 4.1.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 4.1.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,16 +56,16 @@ dependencies:
|
|
70
56
|
name: mysql2
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - "
|
59
|
+
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
61
|
+
version: 0.3.18
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
68
|
+
version: 0.3.18
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: pry
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,10 +166,13 @@ files:
|
|
180
166
|
- ".rubocop.yml"
|
181
167
|
- ".ruby-version"
|
182
168
|
- ".travis.yml"
|
169
|
+
- CHANGELOG.md
|
183
170
|
- Gemfile
|
184
171
|
- README.md
|
185
172
|
- Rakefile
|
186
173
|
- activerecord-sharding.gemspec
|
174
|
+
- ar41.gemfile
|
175
|
+
- ar416.gemfile
|
187
176
|
- bin/benchmark_sequencer.rb
|
188
177
|
- bin/console
|
189
178
|
- bin/setup
|