activerecord-turntable 3.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +25 -9
- data/CHANGELOG.md +25 -0
- data/Gemfile +2 -0
- data/Guardfile +1 -1
- data/README.md +202 -8
- data/Rakefile +42 -67
- data/activerecord-turntable.gemspec +3 -2
- data/gemfiles/rails5_0_0.gemfile +2 -0
- data/gemfiles/rails5_0_1.gemfile +2 -0
- data/gemfiles/rails5_0_2.gemfile +2 -0
- data/gemfiles/rails5_0_3.gemfile +2 -0
- data/gemfiles/rails5_0_4.gemfile +8 -0
- data/gemfiles/rails5_0_5.gemfile +8 -0
- data/gemfiles/rails5_1_0.gemfile +2 -0
- data/gemfiles/rails5_1_1.gemfile +2 -0
- data/gemfiles/rails5_1_2.gemfile +9 -0
- data/gemfiles/rails5_1_3.gemfile +9 -0
- data/gemfiles/rails5_1_4.gemfile +9 -0
- data/gemfiles/rails5_1_5.gemfile +9 -0
- data/lib/active_record/turntable.rb +10 -20
- data/lib/active_record/turntable/active_record_ext.rb +1 -1
- data/lib/active_record/turntable/active_record_ext/log_subscriber.rb +5 -1
- data/lib/active_record/turntable/active_record_ext/sequencer.rb +11 -11
- data/lib/active_record/turntable/active_record_ext/transactions.rb +5 -4
- data/lib/active_record/turntable/algorithm.rb +12 -0
- data/lib/active_record/turntable/algorithm/base.rb +6 -2
- data/lib/active_record/turntable/algorithm/hash_slot_algorithm.rb +35 -0
- data/lib/active_record/turntable/algorithm/modulo_algorithm.rb +3 -7
- data/lib/active_record/turntable/algorithm/range_algorithm.rb +3 -34
- data/lib/active_record/turntable/algorithm/range_bsearch_algorithm.rb +16 -28
- data/lib/active_record/turntable/base.rb +43 -39
- data/lib/active_record/turntable/cluster.rb +31 -29
- data/lib/active_record/turntable/cluster_helper_methods.rb +12 -2
- data/lib/active_record/turntable/cluster_registry.rb +7 -0
- data/lib/active_record/turntable/configuration.rb +50 -0
- data/lib/active_record/turntable/configuration/dsl.rb +79 -0
- data/lib/active_record/turntable/configuration/loader.rb +10 -0
- data/lib/active_record/turntable/configuration/loader/dsl.rb +23 -0
- data/lib/active_record/turntable/configuration/loader/yaml.rb +62 -0
- data/lib/active_record/turntable/configuration_methods.rb +26 -0
- data/lib/active_record/turntable/connection_proxy.rb +51 -40
- data/lib/active_record/turntable/{master_shard.rb → default_shard.rb} +6 -2
- data/lib/active_record/turntable/deprecation.rb +8 -0
- data/lib/active_record/turntable/error.rb +2 -1
- data/lib/active_record/turntable/migration.rb +3 -7
- data/lib/active_record/turntable/mixer.rb +10 -10
- data/lib/active_record/turntable/mixer/fader.rb +1 -1
- data/lib/active_record/turntable/pool_proxy.rb +5 -3
- data/lib/active_record/turntable/railtie.rb +11 -4
- data/lib/active_record/turntable/seq_shard.rb +8 -9
- data/lib/active_record/turntable/sequencer.rb +18 -43
- data/lib/active_record/turntable/sequencer/api.rb +3 -5
- data/lib/active_record/turntable/sequencer/barrage.rb +1 -2
- data/lib/active_record/turntable/sequencer/katsubushi.rb +27 -0
- data/lib/active_record/turntable/sequencer/mysql.rb +14 -6
- data/lib/active_record/turntable/sequencer_registry.rb +30 -0
- data/lib/active_record/turntable/shard.rb +31 -10
- data/lib/active_record/turntable/shard_registry.rb +36 -0
- data/lib/active_record/turntable/slave_registry.rb +21 -0
- data/lib/active_record/turntable/slave_shard.rb +9 -0
- data/lib/active_record/turntable/version.rb +1 -1
- data/lib/generators/templates/turntable.rb +50 -0
- data/lib/generators/templates/turntable.yml +18 -0
- metadata +54 -20
- data/lib/active_record/turntable/config.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5bd7f48754157e32eaaf254a518645b9d1cde4e31840dba63b927886bedb74ee
|
4
|
+
data.tar.gz: 529f08173f847218298a34ed9832163e1d129b003e8ba0ef201ca63d8333b029
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 515cc5103600046d62ea3b91a5695787a2f34d423da084e15aa3dbef8accdba238abd4bb4fb4c4e2659cdbe9ac965f020afb2d6f75a84c4e097cff28e2f1d6cb
|
7
|
+
data.tar.gz: '0578e2aff069a944a6b512b04ae19d47fe2591813f9666f7324cb7d592a4febaa61b457dd71b75dfe8b592f1666bdf57880a3f552da0702c1362b64126db401c'
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -5,9 +5,10 @@ cache:
|
|
5
5
|
bundler: true
|
6
6
|
|
7
7
|
rvm:
|
8
|
-
- 2.2.
|
9
|
-
- 2.3.
|
10
|
-
- 2.4.
|
8
|
+
- 2.2.9
|
9
|
+
- 2.3.6
|
10
|
+
- 2.4.3
|
11
|
+
- 2.5.0
|
11
12
|
- ruby-head
|
12
13
|
|
13
14
|
gemfile:
|
@@ -15,15 +16,27 @@ gemfile:
|
|
15
16
|
- gemfiles/rails5_0_1.gemfile
|
16
17
|
- gemfiles/rails5_0_2.gemfile
|
17
18
|
- gemfiles/rails5_0_3.gemfile
|
19
|
+
- gemfiles/rails5_0_4.gemfile
|
20
|
+
- gemfiles/rails5_0_5.gemfile
|
18
21
|
- gemfiles/rails5_1_0.gemfile
|
19
22
|
- gemfiles/rails5_1_1.gemfile
|
23
|
+
- gemfiles/rails5_1_2.gemfile
|
24
|
+
- gemfiles/rails5_1_3.gemfile
|
25
|
+
- gemfiles/rails5_1_4.gemfile
|
26
|
+
- gemfiles/rails5_1_5.gemfile
|
20
27
|
- gemfiles/rails_edge.gemfile
|
21
28
|
|
22
29
|
env:
|
23
30
|
- SETUP_TASK=turntable:db:reset BUILD_TASK=spec
|
31
|
+
- SETUP_TASK=turntable:db:reset BUILD_TASK=spec SPEC_OPTS="--tag with_katsubushi"
|
24
32
|
- SETUP_TASK=turntable:activerecord:setup BUILD_TASK=turntable:activerecord:test
|
25
33
|
|
26
|
-
|
34
|
+
services:
|
35
|
+
- docker
|
36
|
+
|
37
|
+
before_install:
|
38
|
+
- docker run -d --name turntable-katsubushi -p 11212:11212 katsubushi/katsubushi:latest -worker-id 1
|
39
|
+
- gem update --system
|
27
40
|
|
28
41
|
before_script:
|
29
42
|
- bundle exec rake $SETUP_TASK
|
@@ -35,14 +48,17 @@ matrix:
|
|
35
48
|
exclude:
|
36
49
|
- rvm: ruby-head
|
37
50
|
- gemfile: gemfiles/rails_edge.gemfile
|
38
|
-
- rvm: 2.3.
|
51
|
+
- rvm: 2.3.6
|
52
|
+
- rvm: 2.4.3
|
39
53
|
include:
|
40
|
-
- rvm:
|
54
|
+
- rvm: 2.3.6
|
55
|
+
gemfile: gemfiles/rails5_1_5.gemfile
|
56
|
+
- rvm: 2.4.3
|
57
|
+
gemfile: gemfiles/rails5_1_5.gemfile
|
58
|
+
- rvm: 2.5.0
|
41
59
|
gemfile: gemfiles/rails_edge.gemfile
|
42
|
-
- rvm:
|
60
|
+
- rvm: ruby-head
|
43
61
|
gemfile: gemfiles/rails_edge.gemfile
|
44
|
-
- rvm: 2.3.4
|
45
|
-
gemfile: gemfiles/rails5_1_1.gemfile
|
46
62
|
allow_failures:
|
47
63
|
- rvm: ruby-head
|
48
64
|
- gemfile: gemfiles/rails_edge.gemfile
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
## activerecord-turntable 4.0.0 ##
|
2
|
+
|
3
|
+
### Major Changes
|
4
|
+
|
5
|
+
* Supported rails versions are
|
6
|
+
* 5.0.0 to 5.0.5
|
7
|
+
* 5.1.0 to 5.1.5
|
8
|
+
* Configuration
|
9
|
+
* Added DSL configuration file: config/turntable.rb
|
10
|
+
* Added a new algorithm: `hash_slot`
|
11
|
+
* distributes like redis cluster.
|
12
|
+
* Added a new sequencer: `katsubushi`
|
13
|
+
* Support [katsubushi](https://github.com/kayac/go-katsubushi) as a sequencer backend.
|
14
|
+
* Support slave(read replica) connection. (Experimental feature)
|
15
|
+
|
16
|
+
### Incompatible changes
|
17
|
+
|
18
|
+
* `RangeAlgorithm` is integrated to `RangeBsearchAlgorithm`.
|
19
|
+
* Changed `ConnectionProxy#with_master` behavior to `Fix connection to primary master database`.
|
20
|
+
* Old `ConnectionProxy#with_master` behavior(default model connection) is renamed to `ConnectionProxy#with_default_shard`
|
21
|
+
|
22
|
+
### Internal Change
|
23
|
+
|
24
|
+
* Changed `AR::Base.turntable_configuration` to use `ActiveRecord::Turntable::Configuration` class instead of Hash.
|
25
|
+
|
1
26
|
## activerecord-turntable 3.1.0 ##
|
2
27
|
|
3
28
|
### Major Changes
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/activerecord-turntable.svg)](http://badge.fury.io/rb/activerecord-turntable)
|
4
4
|
[![Build Status](https://travis-ci.org/drecom/activerecord-turntable.svg?branch=master)](https://travis-ci.org/drecom/activerecord-turntable)
|
5
|
-
[![
|
6
|
-
[![
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/github/drecom/activerecord-turntable/badge.svg)](https://coveralls.io/github/drecom/activerecord-turntable)
|
6
|
+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/drecom/activerecord-turntable/blob/master/LICENSE.txt)
|
7
7
|
|
8
8
|
ActiveRecord::Turntable is a database sharding extension for ActiveRecord.
|
9
9
|
|
@@ -11,21 +11,23 @@ ActiveRecord::Turntable is a database sharding extension for ActiveRecord.
|
|
11
11
|
|
12
12
|
activerecord(>=5.0.0, <6.0)
|
13
13
|
|
14
|
+
* Current latest stable branch is [stable branch](https://github.com/drecom/activerecord-turntable/tree/stable).
|
15
|
+
|
14
16
|
If you are using with older activerecord versions, use following versions.
|
15
17
|
|
16
18
|
* activerecord 4.x - use activerecord-turntable version 2.x.([stable-2-x branch](https://github.com/drecom/activerecord-turntable/tree/stable-2-x))
|
17
19
|
* activerecord 3.x - use activerecord-turntable version 1.x.([stable-1-x branch](https://github.com/drecom/activerecord-turntable/tree/stable-1-x))
|
18
20
|
|
19
|
-
## Supported
|
21
|
+
## Supported DBMS
|
20
22
|
|
21
|
-
|
23
|
+
MySQL only.
|
22
24
|
|
23
25
|
## Installation
|
24
26
|
|
25
27
|
Add to Gemfile:
|
26
28
|
|
27
29
|
```ruby
|
28
|
-
gem 'activerecord-turntable', '~>
|
30
|
+
gem 'activerecord-turntable', '~> 4.0.0'
|
29
31
|
```
|
30
32
|
|
31
33
|
Run a bundle install:
|
@@ -85,7 +87,33 @@ three user databases sharded by user_id.
|
|
85
87
|
|
86
88
|
### Example Configuration
|
87
89
|
|
88
|
-
Edit
|
90
|
+
Edit DSL type configuration file(config/turntable.rb) or YAML configuration file(turntable.yml).
|
91
|
+
And add database connection settings to database.yml.
|
92
|
+
|
93
|
+
See below example config.
|
94
|
+
|
95
|
+
* example turntable.rb
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
cluster :user_cluster do
|
99
|
+
# algorithm [algorithm name symbol(range|range_bsearch|modulo)]
|
100
|
+
algorithm :range_bsearch
|
101
|
+
|
102
|
+
# sequencer [sequence name] [sequence type] [*options hash]
|
103
|
+
sequencer :user_seq, :mysql, connection: :user_seq
|
104
|
+
|
105
|
+
# shard [range], to: [connection names in database.yml]
|
106
|
+
shard 1...100, to: :user_shard_1
|
107
|
+
shard 100...200, to: :user_shard_2
|
108
|
+
shard 200...2000000000, to: :user_shard_3
|
109
|
+
|
110
|
+
# If you are using modulo algorithm, pass integer sequence start with zero.
|
111
|
+
#
|
112
|
+
# shard 0, to: :user_shard_1
|
113
|
+
# shard 1, to: :user_shard_2
|
114
|
+
# shard 2, to: :user_shard_3
|
115
|
+
end
|
116
|
+
```
|
89
117
|
|
90
118
|
* example turntable.yml
|
91
119
|
|
@@ -139,6 +167,124 @@ Edit turntable.yml and database.yml. See below example config.
|
|
139
167
|
database: sample_app_user3_development
|
140
168
|
```
|
141
169
|
|
170
|
+
#### About algorithms
|
171
|
+
|
172
|
+
* range, range_bsearch - distribute records by key range
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
algorithm :range_bsearch
|
176
|
+
|
177
|
+
shard 1...20_000, to: :user_shard_1
|
178
|
+
shard 20_000...40_000, to: :user_shard_2
|
179
|
+
shard 40_000...60_000, to: :user_shard_1
|
180
|
+
shard 60_000...80_000, to: :user_shard_2
|
181
|
+
shard 80_000...10_000_000, to: :user_shard_3
|
182
|
+
```
|
183
|
+
|
184
|
+
* modulo - distribute records by key modulo
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
algorithm :modulo
|
188
|
+
|
189
|
+
shard 0, to: :user_shard_1
|
190
|
+
shard 1, to: :user_shard_2
|
191
|
+
shard 2, to: :user_shard_3
|
192
|
+
```
|
193
|
+
|
194
|
+
* hash_slot - distribute records by key hashes
|
195
|
+
|
196
|
+
default hash function is `Zlib.crc32(key.to_s)`
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
algorithm :hash_slot
|
200
|
+
# Or specify hash function
|
201
|
+
# algorithm :hash_slot, hash_func: ->(key) { Zlib.adler32(key.to_s) }
|
202
|
+
|
203
|
+
shard 0...4096, to: :user_shard_1
|
204
|
+
shard 4096...8192, to: :user_shard_2
|
205
|
+
shard 8192...12288, to: :user_shard_3
|
206
|
+
shard 12288...16384, to: :user_shard_4
|
207
|
+
```
|
208
|
+
|
209
|
+
### Slave support (experimental)
|
210
|
+
|
211
|
+
Slave enabled configuration examples:
|
212
|
+
|
213
|
+
* config/turntable.rb
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
cluster :user_cluster do
|
217
|
+
...
|
218
|
+
|
219
|
+
# shard [range], to: [connection names in database.yml]
|
220
|
+
shard 1...100, to: :user_shard_1, slaves: [:user_shard_1_1]
|
221
|
+
shard 100...200, to: :user_shard_2, slaves: [:user_shard_2_1]
|
222
|
+
shard 200...2000000000, to: :user_shard_3, slaves: [:user_shard_3_1]
|
223
|
+
end
|
224
|
+
```
|
225
|
+
|
226
|
+
* config/turntable.yml
|
227
|
+
|
228
|
+
```yaml
|
229
|
+
development:
|
230
|
+
clusters:
|
231
|
+
user_cluster: # <-- cluster name
|
232
|
+
...
|
233
|
+
shards:
|
234
|
+
- connection: user_shard_1
|
235
|
+
less_than: 100
|
236
|
+
slaves:
|
237
|
+
- user_shard_1_1
|
238
|
+
- connection: user_shard_2
|
239
|
+
less_than: 200
|
240
|
+
slaves:
|
241
|
+
- user_shard_2_1
|
242
|
+
- connection: user_shard_3
|
243
|
+
less_than: 2000000000
|
244
|
+
slaves:
|
245
|
+
- user_shard_3_1
|
246
|
+
```
|
247
|
+
|
248
|
+
* config/database.yml
|
249
|
+
|
250
|
+
Add slave connection settings under `shards`.
|
251
|
+
|
252
|
+
```yaml
|
253
|
+
...
|
254
|
+
shards:
|
255
|
+
user_shard_1:
|
256
|
+
<<: *default
|
257
|
+
database: turntable_user_shard_1_test
|
258
|
+
user_shard_1_1:
|
259
|
+
<<: *default
|
260
|
+
database: turntable_user_shard_1_1_test
|
261
|
+
user_shard_2:
|
262
|
+
<<: *default
|
263
|
+
database: turntable_user_shard_2_test
|
264
|
+
user_shard_2_1:
|
265
|
+
<<: *default
|
266
|
+
database: turntable_user_shard_2_1_test
|
267
|
+
user_shard_3:
|
268
|
+
<<: *default
|
269
|
+
database: turntable_user_shard_3_test
|
270
|
+
user_shard_3_1:
|
271
|
+
<<: *default
|
272
|
+
database: turntable_user_shard_3_1_test
|
273
|
+
```
|
274
|
+
|
275
|
+
Slave usage:
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
User.with_slave {
|
279
|
+
# `User` model will use slave databases within this block.
|
280
|
+
}
|
281
|
+
|
282
|
+
User.with_master {
|
283
|
+
# `User` model will use master database within this block.
|
284
|
+
}
|
285
|
+
```
|
286
|
+
|
287
|
+
|
142
288
|
### Example Migration
|
143
289
|
|
144
290
|
Generate a model:
|
@@ -255,10 +401,11 @@ end
|
|
255
401
|
|
256
402
|
Sequencer provides generating global IDs.
|
257
403
|
|
258
|
-
Turntable has follow
|
404
|
+
Turntable has follow 3 sequencers currently:
|
259
405
|
|
260
406
|
* :mysql - Use database table to generate ids.
|
261
407
|
* :barrage - Use [barrage](https://github.com/drecom/barrage) gem to generate ids
|
408
|
+
* :katsubushi - [katsubushi](https://github.com/kayac/go-katsubushi) sequencer backend
|
262
409
|
|
263
410
|
### Mysql example
|
264
411
|
|
@@ -348,6 +495,47 @@ Next, add sequencer definition to the model:
|
|
348
495
|
end
|
349
496
|
```
|
350
497
|
|
498
|
+
### Katsubushi example
|
499
|
+
|
500
|
+
[katsubushi](https://github.com/kayac/go-katsubushi) is available as a sequence server.
|
501
|
+
ActiveRecord::Turntable accesses katsubushi via Dalli.
|
502
|
+
|
503
|
+
First, add dalli gem to your Gemfile:
|
504
|
+
|
505
|
+
```ruby
|
506
|
+
gem 'dalli'
|
507
|
+
```
|
508
|
+
|
509
|
+
Then, add configuration to turntable.yml:
|
510
|
+
|
511
|
+
* turntable.yml
|
512
|
+
|
513
|
+
```yaml
|
514
|
+
development:
|
515
|
+
clusters:
|
516
|
+
user_cluster: # <-- cluster name
|
517
|
+
....
|
518
|
+
seq:
|
519
|
+
katsubushi_seq: # <-- sequencer name
|
520
|
+
seq_type: katsubushi # <-- sequencer type
|
521
|
+
options: # <-- options passed to dalli
|
522
|
+
servers:
|
523
|
+
- host: localhost
|
524
|
+
port: 11212
|
525
|
+
- host: localhost
|
526
|
+
port: 11213
|
527
|
+
```
|
528
|
+
|
529
|
+
Next, add sequencer definition to the model:
|
530
|
+
|
531
|
+
```ruby
|
532
|
+
class User < ApplicationRecord
|
533
|
+
turntable :id
|
534
|
+
sequencer :katsubushi_seq # <-- this line enables sequencer module
|
535
|
+
has_one :status
|
536
|
+
end
|
537
|
+
```
|
538
|
+
|
351
539
|
## Transactions
|
352
540
|
Turntable has some transaction support methods.
|
353
541
|
|
@@ -497,7 +685,7 @@ To notice queries causing performance problem, Turntable has follow options.
|
|
497
685
|
* raise\_on\_not\_specified\_shard\_update - raises on updates executed on all shards
|
498
686
|
|
499
687
|
|
500
|
-
Add to turntable.yml:
|
688
|
+
Add to turntable.yml or turntable.rb:
|
501
689
|
|
502
690
|
```yaml
|
503
691
|
development:
|
@@ -506,6 +694,12 @@ development:
|
|
506
694
|
raise_on_not_specified_shard_update: true
|
507
695
|
```
|
508
696
|
|
697
|
+
```ruby
|
698
|
+
# Write on top level
|
699
|
+
raise_on_not_specified_shard_query true
|
700
|
+
raise_on_not_specified_shard_update true
|
701
|
+
```
|
702
|
+
|
509
703
|
## Thanks
|
510
704
|
|
511
705
|
ConnectionProxy, Distributed Migration implementation is inspired by Octopus and DataFabric.
|
data/Rakefile
CHANGED
@@ -47,73 +47,7 @@ namespace :turntable do
|
|
47
47
|
|
48
48
|
configurations.each do |configuration|
|
49
49
|
ActiveRecord::Base.establish_connection configuration
|
50
|
-
|
51
|
-
ActiveRecord::Base.connection.create_table :users, comment: "comment" do |t|
|
52
|
-
t.string :nickname
|
53
|
-
t.string :thumbnail_url
|
54
|
-
t.binary :blob
|
55
|
-
t.datetime :joined_at
|
56
|
-
t.datetime :deleted_at
|
57
|
-
t.timestamps
|
58
|
-
end
|
59
|
-
ActiveRecord::Base.connection.create_sequence_for :users, comment: "comment"
|
60
|
-
|
61
|
-
ActiveRecord::Base.connection.create_table :user_statuses do |t|
|
62
|
-
t.belongs_to :user, :null => false
|
63
|
-
t.integer :hp, :null => false, :default => 0
|
64
|
-
t.integer :mp, :null => false, :default => 0
|
65
|
-
t.text :data
|
66
|
-
t.integer :lock_version, :null => false, :default => 0
|
67
|
-
t.datetime :deleted_at, :default => nil
|
68
|
-
t.timestamps
|
69
|
-
end
|
70
|
-
ActiveRecord::Base.connection.create_sequence_for :user_statuses
|
71
|
-
|
72
|
-
ActiveRecord::Base.connection.create_table :cards do |t|
|
73
|
-
t.string :name, :null => false
|
74
|
-
t.integer :hp, :null => false, :default => 0
|
75
|
-
t.integer :mp, :null => false, :default => 0
|
76
|
-
t.timestamps
|
77
|
-
end
|
78
|
-
ActiveRecord::Base.connection.create_table :archived_cards do |t|
|
79
|
-
t.string :name, :null => false
|
80
|
-
t.integer :hp, :null => false, :default => 0
|
81
|
-
t.integer :mp, :null => false, :default => 0
|
82
|
-
t.timestamps
|
83
|
-
t.datetime :deleted_at, :default => nil
|
84
|
-
end
|
85
|
-
|
86
|
-
ActiveRecord::Base.connection.create_table :cards_users do |t|
|
87
|
-
t.belongs_to :card, :null => false
|
88
|
-
t.belongs_to :user, :null => false
|
89
|
-
t.integer :num, :default => 1, :null => false
|
90
|
-
t.timestamps
|
91
|
-
end
|
92
|
-
ActiveRecord::Base.connection.create_sequence_for :cards_users
|
93
|
-
|
94
|
-
ActiveRecord::Base.connection.create_table :archived_cards_users do |t|
|
95
|
-
t.belongs_to :card, :null => false
|
96
|
-
t.belongs_to :user, :null => false
|
97
|
-
t.timestamps
|
98
|
-
t.datetime :deleted_at, :default => nil
|
99
|
-
end
|
100
|
-
ActiveRecord::Base.connection.create_sequence_for :archived_cards_users
|
101
|
-
|
102
|
-
ActiveRecord::Base.connection.create_table :cards_users_histories do |t|
|
103
|
-
t.belongs_to :cards_user, :null => false
|
104
|
-
t.belongs_to :user, :null => false
|
105
|
-
t.timestamps
|
106
|
-
end
|
107
|
-
ActiveRecord::Base.connection.create_sequence_for :cards_users_histories
|
108
|
-
|
109
|
-
ActiveRecord::Base.connection.create_table :events_users_histories do |t|
|
110
|
-
t.belongs_to :events_user, :null => false
|
111
|
-
t.belongs_to :cards_user, :null => false
|
112
|
-
t.belongs_to :user, :null => false
|
113
|
-
t.string :type, :default => nil
|
114
|
-
t.timestamps
|
115
|
-
end
|
116
|
-
ActiveRecord::Base.connection.create_sequence_for :events_users_histories
|
50
|
+
load File.expand_path("spec/migrations/schema.rb", __dir__)
|
117
51
|
end
|
118
52
|
end
|
119
53
|
|
@@ -170,6 +104,47 @@ namespace :turntable do
|
|
170
104
|
EOS
|
171
105
|
end
|
172
106
|
end
|
107
|
+
|
108
|
+
# Ignore failing migrator test
|
109
|
+
if ActiveRecord.gem_version.release <= Gem::Version.new("5.1.5")
|
110
|
+
File.open("test/cases/migrator_test.rb", "a") do |f|
|
111
|
+
f << <<-EOS.strip_heredoc
|
112
|
+
class MigratorTest
|
113
|
+
undef_method :test_migrator_verbosity if method_defined?(:test_migrator_verbosity)
|
114
|
+
end
|
115
|
+
EOS
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Ignore some failing tests with ruby 2.5
|
120
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5") &&
|
121
|
+
ActiveRecord.gem_version.release <= Gem::Version.new("5.1.4")
|
122
|
+
ignores = [
|
123
|
+
["aggregations_test.rb", "AggregationsTest", ["test_immutable_value_objects"]],
|
124
|
+
["query_cache_test.rb", "QueryCacheTest", ["test_query_cache_does_not_allow_sql_key_mutation"]],
|
125
|
+
["transactions_test.rb", "TransactionTest", ["test_rollback_when_saving_a_frozen_record"]],
|
126
|
+
["log_subscriber_test.rb", "LogSubscriberTest",
|
127
|
+
%w[test_basic_payload_name_logging_coloration_generic_sql
|
128
|
+
test_basic_payload_name_logging_coloration_named_sql
|
129
|
+
test_query_logging_coloration_with_nested_select
|
130
|
+
test_query_logging_coloration_with_multi_line_nested_select
|
131
|
+
test_query_logging_coloration_with_lock]],
|
132
|
+
]
|
133
|
+
|
134
|
+
ignores.each do |file_name, class_name, method_names|
|
135
|
+
path = File.join("test/cases", file_name)
|
136
|
+
next unless File.exist?(path)
|
137
|
+
|
138
|
+
File.open(File.join("test/cases", file_name), "a") do |f|
|
139
|
+
f << <<-EOS.strip_heredoc
|
140
|
+
class #{class_name}
|
141
|
+
#{method_names.map { |method_name| "undef_method :#{method_name} if method_defined?(:#{method_name})" }.join("\n") }
|
142
|
+
|
143
|
+
end
|
144
|
+
EOS
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
173
148
|
end
|
174
149
|
|
175
150
|
task :db => :rails do
|