activerecord-turntable 3.0.0.alpha3 → 3.0.0
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/.gitmodules +3 -0
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +153 -0
- data/.travis.yml +20 -4
- data/CHANGELOG.md +32 -0
- data/Guardfile +2 -2
- data/README.md +68 -14
- data/Rakefile +42 -0
- data/activerecord-turntable.gemspec +13 -3
- data/gemfiles/rails_edge.gemfile +8 -0
- data/lib/active_record/turntable/active_record_ext/abstract_adapter.rb +3 -1
- data/lib/active_record/turntable/active_record_ext/activerecord_import_ext.rb +5 -7
- data/lib/active_record/turntable/active_record_ext/acts_as_archive_extension.rb +2 -2
- data/lib/active_record/turntable/active_record_ext/association.rb +3 -3
- data/lib/active_record/turntable/active_record_ext/clever_load.rb +2 -2
- data/lib/active_record/turntable/active_record_ext/database_tasks.rb +10 -8
- data/lib/active_record/turntable/active_record_ext/fixtures.rb +15 -13
- data/lib/active_record/turntable/active_record_ext/log_subscriber.rb +6 -0
- data/lib/active_record/turntable/active_record_ext/persistence.rb +25 -23
- data/lib/active_record/turntable/active_record_ext/schema_dumper.rb +8 -75
- data/lib/active_record/turntable/algorithm/range_algorithm.rb +6 -7
- data/lib/active_record/turntable/algorithm/range_bsearch_algorithm.rb +6 -7
- data/lib/active_record/turntable/base.rb +2 -17
- data/lib/active_record/turntable/cluster_helper_methods.rb +7 -4
- data/lib/active_record/turntable/connection_proxy.rb +4 -2
- data/lib/active_record/turntable/migration.rb +3 -5
- data/lib/active_record/turntable/mixer.rb +20 -19
- data/lib/active_record/turntable/pool_proxy.rb +20 -14
- data/lib/active_record/turntable/query_cache.rb +1 -1
- data/lib/active_record/turntable/railties/databases.rake +12 -12
- data/lib/active_record/turntable/seq_shard.rb +1 -1
- data/lib/active_record/turntable/sequencer/barrage.rb +3 -2
- data/lib/active_record/turntable/sequencer.rb +33 -29
- data/lib/active_record/turntable/shard.rb +8 -8
- data/lib/active_record/turntable/sharding_condition.rb +14 -14
- data/lib/active_record/turntable/sql_tree_patch.rb +7 -3
- data/lib/active_record/turntable/util.rb +4 -2
- data/lib/active_record/turntable/version.rb +1 -1
- data/lib/active_record/turntable.rb +6 -5
- data/lib/activerecord-turntable.rb +1 -0
- metadata +120 -101
- data/lib/active_record/turntable/helpers/test_helper.rb +0 -25
- data/lib/active_record/turntable/helpers.rb +0 -9
- data/spec/active_record/turntable/active_record_ext/association_preloader_spec.rb +0 -78
- data/spec/active_record/turntable/active_record_ext/association_spec.rb +0 -81
- data/spec/active_record/turntable/active_record_ext/clever_load_spec.rb +0 -72
- data/spec/active_record/turntable/active_record_ext/fixture_set_spec.rb +0 -27
- data/spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb +0 -28
- data/spec/active_record/turntable/active_record_ext/migration_spec.rb +0 -38
- data/spec/active_record/turntable/active_record_ext/persistence_spec.rb +0 -211
- data/spec/active_record/turntable/active_record_ext/sequencer_spec.rb +0 -22
- data/spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb +0 -34
- data/spec/active_record/turntable/algorithm/modulo_algorithm_spec.rb +0 -34
- data/spec/active_record/turntable/algorithm/range_algorithm_spec.rb +0 -34
- data/spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb +0 -34
- data/spec/active_record/turntable/algorithm_spec.rb +0 -100
- data/spec/active_record/turntable/base_spec.rb +0 -13
- data/spec/active_record/turntable/cluster_spec.rb +0 -48
- data/spec/active_record/turntable/config_spec.rb +0 -17
- data/spec/active_record/turntable/connection_proxy_spec.rb +0 -252
- data/spec/active_record/turntable/finder_spec.rb +0 -40
- data/spec/active_record/turntable/mixer/fader_spec.rb +0 -4
- data/spec/active_record/turntable/mixer_spec.rb +0 -112
- data/spec/active_record/turntable/query_cache_spec.rb +0 -28
- data/spec/active_record/turntable/sequencer/api_spec.rb +0 -38
- data/spec/active_record/turntable/sequencer/barrage_spec.rb +0 -22
- data/spec/active_record/turntable/sequencer/mysql_spec.rb +0 -22
- data/spec/active_record/turntable/shard_spec.rb +0 -21
- data/spec/active_record/turntable/sql_tree_patch_spec.rb +0 -34
- data/spec/active_record/turntable/transaction_spec.rb +0 -35
- data/spec/active_record/turntable_spec.rb +0 -30
- data/spec/config/database.yml +0 -35
- data/spec/config/turntable.yml +0 -56
- data/spec/fabricators/.gitkeep +0 -0
- data/spec/fabricators/turntable_fabricator.rb +0 -12
- data/spec/fixtures/cards.yml +0 -11
- data/spec/migrations/.gitkeep +0 -0
- data/spec/migrations/001_create_users.rb +0 -17
- data/spec/migrations/002_create_user_statuses.rb +0 -16
- data/spec/migrations/003_create_cards.rb +0 -14
- data/spec/migrations/004_create_cards_users.rb +0 -15
- data/spec/models/card.rb +0 -3
- data/spec/models/cards_user.rb +0 -10
- data/spec/models/cards_users_histories.rb +0 -7
- data/spec/models/events_users_history.rb +0 -7
- data/spec/models/user.rb +0 -7
- data/spec/models/user_status.rb +0 -6
- data/spec/spec_helper.rb +0 -38
- data/spec/support/matchers/be_saved_to.rb +0 -6
- data/spec/support/turntable_helper.rb +0 -30
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6cfc2457a7b8212bbeef4d49d4b84b8b40877396
|
|
4
|
+
data.tar.gz: ed7b1f0e36e61aa3104ec0bebd1cd4d67e31dcdb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba0296ccb842d6f10069cc875a2aacd0bd2bd7b3b3766cd7fc3701b795c16c3f05f64531b279a1cac2a13649dac832ce932c7ba3478326aaf03f1698f5757e46
|
|
7
|
+
data.tar.gz: 497202d000a232456c5c786ec1202920773069a684760d2c3bcb9eb3e6e55c761d19ff1fb64ac6f3f333401ebc31a1b527b7cb299d603ab22b52413f9376e9ba
|
data/.gitmodules
ADDED
data/.rubocop.yml
CHANGED
|
@@ -3,5 +3,23 @@ inherit_gem:
|
|
|
3
3
|
- "config/rubocop.yml"
|
|
4
4
|
- "config/rspec.yml"
|
|
5
5
|
|
|
6
|
+
inherit_from:
|
|
7
|
+
- ".rubocop_todo.yml"
|
|
8
|
+
|
|
6
9
|
AllCops:
|
|
7
10
|
TargetRubyVersion: 2.2
|
|
11
|
+
Exclude:
|
|
12
|
+
- "test/**/*"
|
|
13
|
+
- "tmp/**/*"
|
|
14
|
+
- "activerecord.rake"
|
|
15
|
+
|
|
16
|
+
RSpec/NestedGroups:
|
|
17
|
+
Max: 4
|
|
18
|
+
|
|
19
|
+
Style/ExtraSpacing:
|
|
20
|
+
Exclude:
|
|
21
|
+
- "activerecord-turntable.gemspec"
|
|
22
|
+
|
|
23
|
+
Style/SpaceAroundOperators:
|
|
24
|
+
Exclude:
|
|
25
|
+
- "activerecord-turntable.gemspec"
|
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2017-02-10 00:09:09 +0900 using RuboCop version 0.47.1.
|
|
4
|
+
# The point is for the user to remove these configuration records
|
|
5
|
+
# one by one as the offenses are removed from the code base.
|
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
+
|
|
9
|
+
# Offense count: 2
|
|
10
|
+
# Configuration parameters: AllowSafeAssignment.
|
|
11
|
+
Lint/AssignmentInCondition:
|
|
12
|
+
Exclude:
|
|
13
|
+
- 'lib/active_record/turntable/active_record_ext/connection_handler_extension.rb'
|
|
14
|
+
- 'lib/active_record/turntable/active_record_ext/schema_dumper.rb'
|
|
15
|
+
|
|
16
|
+
# Offense count: 4
|
|
17
|
+
Lint/RescueException:
|
|
18
|
+
Exclude:
|
|
19
|
+
- 'lib/active_record/turntable/connection_proxy.rb'
|
|
20
|
+
- 'lib/active_record/turntable/mixer.rb'
|
|
21
|
+
|
|
22
|
+
# Offense count: 5
|
|
23
|
+
# Cop supports --auto-correct.
|
|
24
|
+
Lint/UnneededSplatExpansion:
|
|
25
|
+
Exclude:
|
|
26
|
+
- 'Rakefile'
|
|
27
|
+
|
|
28
|
+
# Offense count: 14
|
|
29
|
+
Metrics/AbcSize:
|
|
30
|
+
Max: 106
|
|
31
|
+
|
|
32
|
+
# Offense count: 2
|
|
33
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
|
34
|
+
Metrics/BlockLength:
|
|
35
|
+
Max: 88
|
|
36
|
+
|
|
37
|
+
# Offense count: 2
|
|
38
|
+
# Configuration parameters: CountComments.
|
|
39
|
+
Metrics/ClassLength:
|
|
40
|
+
Max: 202
|
|
41
|
+
|
|
42
|
+
# Offense count: 5
|
|
43
|
+
Metrics/CyclomaticComplexity:
|
|
44
|
+
Max: 20
|
|
45
|
+
|
|
46
|
+
# Offense count: 2
|
|
47
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
|
48
|
+
# URISchemes: http, https
|
|
49
|
+
Metrics/LineLength:
|
|
50
|
+
Max: 246
|
|
51
|
+
|
|
52
|
+
# Offense count: 10
|
|
53
|
+
# Configuration parameters: CountComments.
|
|
54
|
+
Metrics/MethodLength:
|
|
55
|
+
Max: 56
|
|
56
|
+
|
|
57
|
+
# Offense count: 1
|
|
58
|
+
# Configuration parameters: CountKeywordArgs.
|
|
59
|
+
Metrics/ParameterLists:
|
|
60
|
+
Max: 6
|
|
61
|
+
|
|
62
|
+
# Offense count: 9
|
|
63
|
+
Metrics/PerceivedComplexity:
|
|
64
|
+
Max: 24
|
|
65
|
+
|
|
66
|
+
# Offense count: 3
|
|
67
|
+
# Cop supports --auto-correct.
|
|
68
|
+
Performance/TimesMap:
|
|
69
|
+
Exclude:
|
|
70
|
+
- 'script/performance/algorithm'
|
|
71
|
+
- 'spec/active_record/turntable/active_record_ext/association_preloader_spec.rb'
|
|
72
|
+
- 'spec/active_record/turntable/active_record_ext/association_spec.rb'
|
|
73
|
+
- 'spec/active_record/turntable/cluster_helper_methods_spec.rb'
|
|
74
|
+
|
|
75
|
+
# Offense count: 1
|
|
76
|
+
# Configuration parameters: CustomIncludeMethods.
|
|
77
|
+
RSpec/EmptyExampleGroup:
|
|
78
|
+
Exclude:
|
|
79
|
+
- 'spec/active_record/turntable/mixer/fader_spec.rb'
|
|
80
|
+
|
|
81
|
+
# Offense count: 3
|
|
82
|
+
# Configuration parameters: CustomTransform, IgnoreMethods.
|
|
83
|
+
RSpec/FilePath:
|
|
84
|
+
Exclude:
|
|
85
|
+
- 'spec/active_record/turntable/active_record_ext/fixture_set_spec.rb'
|
|
86
|
+
- 'spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb'
|
|
87
|
+
|
|
88
|
+
# Offense count: 21
|
|
89
|
+
# Configuration parameters: Max.
|
|
90
|
+
RSpec/NestedGroups:
|
|
91
|
+
Exclude:
|
|
92
|
+
- 'spec/active_record/turntable/active_record_ext/association_preloader_spec.rb'
|
|
93
|
+
- 'spec/active_record/turntable/active_record_ext/association_spec.rb'
|
|
94
|
+
- 'spec/active_record/turntable/active_record_ext/clever_load_spec.rb'
|
|
95
|
+
- 'spec/active_record/turntable/connection_proxy_spec.rb'
|
|
96
|
+
- 'spec/active_record/turntable/finder_spec.rb'
|
|
97
|
+
- 'spec/active_record/turntable/mixer_spec.rb'
|
|
98
|
+
|
|
99
|
+
# Offense count: 15
|
|
100
|
+
# Cop supports --auto-correct.
|
|
101
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
|
102
|
+
# SupportedStyles: line_count_based, semantic, braces_for_chaining
|
|
103
|
+
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
|
104
|
+
# FunctionalMethods: let, let!, subject, watch
|
|
105
|
+
# IgnoredMethods: lambda, proc, it
|
|
106
|
+
Style/BlockDelimiters:
|
|
107
|
+
Exclude:
|
|
108
|
+
- 'spec/**/*'
|
|
109
|
+
- 'lib/active_record/turntable/active_record_ext/acts_as_archive_extension.rb'
|
|
110
|
+
- 'lib/active_record/turntable/active_record_ext/clever_load.rb'
|
|
111
|
+
- 'lib/active_record/turntable/active_record_ext/database_tasks.rb'
|
|
112
|
+
- 'lib/active_record/turntable/active_record_ext/fixtures.rb'
|
|
113
|
+
- 'lib/active_record/turntable/algorithm/range_bsearch_algorithm.rb'
|
|
114
|
+
- 'lib/active_record/turntable/cluster_helper_methods.rb'
|
|
115
|
+
- 'lib/active_record/turntable/connection_proxy.rb'
|
|
116
|
+
- 'script/performance/algorithm'
|
|
117
|
+
|
|
118
|
+
# Offense count: 2
|
|
119
|
+
# Configuration parameters: MinBodyLength.
|
|
120
|
+
Style/GuardClause:
|
|
121
|
+
Exclude:
|
|
122
|
+
- 'lib/active_record/turntable/sql_tree_patch.rb'
|
|
123
|
+
|
|
124
|
+
# Offense count: 4
|
|
125
|
+
Style/MethodCalledOnDoEndBlock:
|
|
126
|
+
Exclude:
|
|
127
|
+
- 'lib/active_record/turntable/migration.rb'
|
|
128
|
+
- 'lib/active_record/turntable/mixer.rb'
|
|
129
|
+
- 'lib/active_record/turntable/mixer/fader/update_shards_merge_result.rb'
|
|
130
|
+
- 'lib/active_record/turntable/sql_tree_patch.rb'
|
|
131
|
+
|
|
132
|
+
# Offense count: 5
|
|
133
|
+
# Cop supports --auto-correct.
|
|
134
|
+
# Configuration parameters: PreferredDelimiters.
|
|
135
|
+
Style/PercentLiteralDelimiters:
|
|
136
|
+
Exclude:
|
|
137
|
+
- 'Rakefile'
|
|
138
|
+
|
|
139
|
+
# Offense count: 6
|
|
140
|
+
# Cop supports --auto-correct.
|
|
141
|
+
# Configuration parameters: AllowMultipleReturnValues.
|
|
142
|
+
Style/RedundantReturn:
|
|
143
|
+
Exclude:
|
|
144
|
+
- 'lib/active_record/turntable/sql_tree_patch.rb'
|
|
145
|
+
|
|
146
|
+
# Offense count: 2
|
|
147
|
+
# Cop supports --auto-correct.
|
|
148
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment.
|
|
149
|
+
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
|
|
150
|
+
Style/TernaryParentheses:
|
|
151
|
+
Exclude:
|
|
152
|
+
- 'lib/active_record/turntable/sequencer.rb'
|
|
153
|
+
- 'lib/active_record/turntable/sql_tree_patch.rb'
|
data/.travis.yml
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
language: ruby
|
|
2
|
+
sudo: false
|
|
3
|
+
|
|
4
|
+
cache:
|
|
5
|
+
bundler: true
|
|
6
|
+
|
|
2
7
|
rvm:
|
|
3
8
|
- 2.2.6
|
|
4
9
|
- 2.3.3
|
|
5
10
|
- 2.4.0
|
|
6
11
|
- ruby-head
|
|
12
|
+
|
|
7
13
|
gemfile:
|
|
8
14
|
- gemfiles/rails5_0.gemfile
|
|
15
|
+
- gemfiles/rails_edge.gemfile
|
|
16
|
+
|
|
17
|
+
env:
|
|
18
|
+
- SETUP_TASK=turntable:db:reset BUILD_TASK=spec
|
|
19
|
+
- SETUP_TASK=turntable:activerecord:setup BUILD_TASK=turntable:activerecord:test
|
|
20
|
+
|
|
21
|
+
before_install: gem update --system
|
|
22
|
+
|
|
9
23
|
before_script:
|
|
10
|
-
- bundle exec rake
|
|
11
|
-
|
|
24
|
+
- bundle exec rake $SETUP_TASK
|
|
25
|
+
|
|
26
|
+
script:
|
|
27
|
+
- bundle exec rake $BUILD_TASK
|
|
28
|
+
|
|
12
29
|
matrix:
|
|
13
30
|
allow_failures:
|
|
14
31
|
- rvm: ruby-head
|
|
15
|
-
|
|
16
|
-
cache: bundler
|
|
32
|
+
- gemfile: gemfiles/rails_edge.gemfile
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## activerecord-turntable 3.0.0 ##
|
|
2
|
+
|
|
3
|
+
### Bugfixes
|
|
4
|
+
|
|
5
|
+
* Fixes schema dumper patches that dumps tables options incorrectly.
|
|
6
|
+
* Re-enable the `AR::LogSubscriber::IGNORE_PAYLOAD_NAMES` (thx @misoobu)
|
|
7
|
+
* Make cluster transaction helpers to preserve transaction options(e.g. :requires_new)
|
|
8
|
+
* Fixes shard names are not written to logs correctly (thx @i2bskn)
|
|
9
|
+
* Fixes ConnectionNotEstablished Error with STI subclasses #48
|
|
10
|
+
|
|
11
|
+
### Improvements
|
|
12
|
+
|
|
13
|
+
* Update activerecord-import patches for performance improvements (thx @misoobu)
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
## activerecord-turntable 3.0.0.alpha3 ##
|
|
2
17
|
|
|
3
18
|
### Bugfix
|
|
@@ -18,6 +33,23 @@
|
|
|
18
33
|
* Minimum ruby requirement version is `2.2.2`
|
|
19
34
|
* Rails 4.x support has been dropped.
|
|
20
35
|
|
|
36
|
+
## activerecord-turntable 2.5.0 ##
|
|
37
|
+
|
|
38
|
+
### Improvement
|
|
39
|
+
|
|
40
|
+
* Fix to propagate shard conditions to `AssociationRelation` too
|
|
41
|
+
|
|
42
|
+
## activerecord-turntable 2.4.0 ##
|
|
43
|
+
|
|
44
|
+
### Incompatible Change
|
|
45
|
+
|
|
46
|
+
* Drop support for ruby 1.9.3
|
|
47
|
+
|
|
48
|
+
### Bugfix
|
|
49
|
+
|
|
50
|
+
* Update activerecord 4.2 patches
|
|
51
|
+
* Fixes optimistic locking with a serialized column causes JSON::Error.
|
|
52
|
+
|
|
21
53
|
## activerecord-turntable 2.3.3 ##
|
|
22
54
|
|
|
23
55
|
### Bugfix
|
data/Guardfile
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
|
3
3
|
|
|
4
4
|
guard "rspec",
|
|
5
|
-
cmd: "
|
|
5
|
+
cmd: "rspec",
|
|
6
6
|
all_after_pass: true,
|
|
7
7
|
all_on_start: true do
|
|
8
8
|
watch(%r{^spec/.+_spec\.rb$})
|
|
@@ -11,6 +11,6 @@ guard "rspec",
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
guard :rubocop do
|
|
14
|
-
watch(
|
|
14
|
+
watch(/.+\.rb$/)
|
|
15
15
|
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
|
16
16
|
end
|
data/README.md
CHANGED
|
@@ -13,8 +13,8 @@ activerecord(>=5.0.0, <6.0)
|
|
|
13
13
|
|
|
14
14
|
If you are using with older activerecord versions, use following versions.
|
|
15
15
|
|
|
16
|
-
* activerecord
|
|
17
|
-
* activerecord
|
|
16
|
+
* activerecord 4.x - use activerecord-turntable version 2.x.([stable-2-x branch](https://github.com/drecom/activerecord-turntable/tree/stable-2-x))
|
|
17
|
+
* activerecord 3.x - use activerecord-turntable version 1.x.([stable-1-x branch](https://github.com/drecom/activerecord-turntable/tree/stable-1-x))
|
|
18
18
|
|
|
19
19
|
## Supported Database
|
|
20
20
|
|
|
@@ -25,7 +25,7 @@ Currently supports mysql only.
|
|
|
25
25
|
Add to Gemfile:
|
|
26
26
|
|
|
27
27
|
```ruby
|
|
28
|
-
gem 'activerecord-turntable', '~> 3.0.0
|
|
28
|
+
gem 'activerecord-turntable', '~> 3.0.0'
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
Run a bundle install:
|
|
@@ -179,13 +179,13 @@ Those rake tasks would be executed to shards too.
|
|
|
179
179
|
Add turntable [shard_key_name] to the model class:
|
|
180
180
|
|
|
181
181
|
```ruby
|
|
182
|
-
class User <
|
|
182
|
+
class User < ApplicationRecord
|
|
183
183
|
turntable :user_cluster, :id
|
|
184
184
|
sequencer :user_seq
|
|
185
185
|
has_one :status
|
|
186
186
|
end
|
|
187
187
|
|
|
188
|
-
class Status <
|
|
188
|
+
class Status < ApplicationRecord
|
|
189
189
|
turntable :user_cluster, :user_id
|
|
190
190
|
sequencer :user_seq
|
|
191
191
|
belongs_to :user
|
|
@@ -297,7 +297,7 @@ create_sequence_for(:users) # <-- this line creates sequence table named `users_
|
|
|
297
297
|
Next, add sequencer definition to the model:
|
|
298
298
|
|
|
299
299
|
```ruby
|
|
300
|
-
class User <
|
|
300
|
+
class User < ApplicationRecord
|
|
301
301
|
turntable :id
|
|
302
302
|
sequencer :user_seq # <-- this line enables sequencer module
|
|
303
303
|
has_one :status
|
|
@@ -341,7 +341,7 @@ Then, add configuration to turntable.yml:
|
|
|
341
341
|
Next, add sequencer definition to the model:
|
|
342
342
|
|
|
343
343
|
```ruby
|
|
344
|
-
class User <
|
|
344
|
+
class User < ApplicationRecord
|
|
345
345
|
turntable :id
|
|
346
346
|
sequencer :barrage_seq # <-- this line enables sequencer module
|
|
347
347
|
has_one :status
|
|
@@ -369,7 +369,7 @@ end
|
|
|
369
369
|
|
|
370
370
|
### cluster_transaction
|
|
371
371
|
|
|
372
|
-
|
|
372
|
+
When executing transaction on all shards in the cluster, use `#{cluster_name}_transaction` method:
|
|
373
373
|
|
|
374
374
|
```ruby
|
|
375
375
|
User.user_cluster_transaction do
|
|
@@ -404,8 +404,7 @@ to specify shard:
|
|
|
404
404
|
## Limitations
|
|
405
405
|
|
|
406
406
|
* Queries includes "ORDER BY", "GROUP BY" and "LIMIT" clauses cannot be distributed.
|
|
407
|
-
* "has many through" and "habtm" relationships may
|
|
408
|
-
|
|
407
|
+
* "has many through" and "habtm" relationships may returns unexpected results. ex) `User-Friend-User` relation
|
|
409
408
|
|
|
410
409
|
## TIPS
|
|
411
410
|
|
|
@@ -414,25 +413,80 @@ to specify shard:
|
|
|
414
413
|
Use `with_shard` method:
|
|
415
414
|
|
|
416
415
|
```ruby
|
|
417
|
-
AR::Base.
|
|
416
|
+
AR::Base.with_shard(shard1) do
|
|
418
417
|
# something queries to shard1
|
|
419
418
|
end
|
|
420
419
|
```
|
|
421
420
|
|
|
421
|
+
`with_shard` method accepts following types to specify a shard:
|
|
422
|
+
|
|
423
|
+
* ActiveRecord::Turntable::Shard object
|
|
424
|
+
* AcitveRecord::Base object - `AR::Base#turntable_shard` will be used
|
|
425
|
+
* Numeric, String - a shard key value
|
|
426
|
+
* Symbol - shard name symbol
|
|
427
|
+
|
|
422
428
|
To access shard objects, use below:
|
|
423
429
|
|
|
424
430
|
* AR::Base.connection.shards # \\{shard_name => shard_obj,....}
|
|
425
431
|
* AR::Base#turntable_shard # Returns current object's shard
|
|
426
|
-
* AR::Base.connection.
|
|
432
|
+
* AR::Base.connection.shard_for(shard_key_value) #=> shard
|
|
427
433
|
|
|
428
434
|
### Send query to all shards
|
|
429
435
|
|
|
430
436
|
Use with_all method:
|
|
431
437
|
|
|
432
438
|
```ruby
|
|
433
|
-
User.
|
|
439
|
+
User.with_all do
|
|
434
440
|
User.order("created_at DESC").limit(3).all
|
|
435
|
-
end
|
|
441
|
+
end # => Returns Array of results
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### Cannot specify error is raised between associations
|
|
445
|
+
|
|
446
|
+
Normally, activerecord-turntable detects shard keys on associated models, but auto-detection will fail with following conditions:
|
|
447
|
+
|
|
448
|
+
* foreign key column != shard key column
|
|
449
|
+
* Using different shard key names
|
|
450
|
+
|
|
451
|
+
For example:
|
|
452
|
+
|
|
453
|
+
```ruby
|
|
454
|
+
class User
|
|
455
|
+
# shard key:
|
|
456
|
+
# foreign key: main_user_item_id
|
|
457
|
+
belongs_to :main_user_item, class_name: "UserItem", required: false
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
class UserItem
|
|
461
|
+
# shard key name: :user_id
|
|
462
|
+
turntable :user_cluster, :user_id
|
|
463
|
+
end
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
This example raises CannotSpecifyShardError
|
|
467
|
+
|
|
468
|
+
```ruby
|
|
469
|
+
> user.main_user_item
|
|
470
|
+
User Load [Shard: master] (0.4ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1
|
|
471
|
+
[ActiveRecord::Turntable] Error on Building Fader: SELECT `user_items`.* FROM `user_items` WHERE `user_items`.`id` = 2198059200000 LIMIT 1, on_method: select_all, err: cannot specifyshard for query: SELECT "user_items".* FROM `user_items` WHERE (`user_items`.`id` = 2198059200000) LIMIT 1
|
|
472
|
+
ActiveRecord::Turntable::CannotSpecifyShardError: cannot specify shard for query: SELECT "user_items".* FROM `user_items` WHERE (`user_items`.`id` = 2198059200000) LIMIT 1
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
Use foreign_shard_key option to pass a shard key condition:
|
|
476
|
+
|
|
477
|
+
```
|
|
478
|
+
-belongs_to :main_user_item, class_name: "UserItem"
|
|
479
|
+
+belongs_to :main_user_item, class_name: "UserItem", foreign_shard_key: :id
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
```ruby
|
|
483
|
+
> user.main_user_item
|
|
484
|
+
User Load [Shard: master] (0.2ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1
|
|
485
|
+
[ActiveRecord::Turntable] Sending method: select_all, sql: #<Arel::SelectManager:0x007f8080bd0670>, shards: ["user_shard_1"]
|
|
486
|
+
Changing UserItem's shard to user_shard_1
|
|
487
|
+
UserItem Load [Shard: user_shard_1] (0.2ms) SELECT `user_items`.* FROM `user_items` WHERE `user_items`.`user_id` = 1 AND `user_items`.`id` = 2198059200000 LIMIT 1
|
|
488
|
+
Changing UserItem's shard to master
|
|
489
|
+
=> #<UserItem id: 2198059200000, user_id: 1, item_id: 1, created_at: "2017-05-23 04:41:13", updated_at: "2017-05-23 04:41:13">
|
|
436
490
|
```
|
|
437
491
|
|
|
438
492
|
### Performance Exception
|
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
|
|
@@ -109,6 +110,7 @@ namespace :turntable do
|
|
|
109
110
|
t.belongs_to :events_user, :null => false
|
|
110
111
|
t.belongs_to :cards_user, :null => false
|
|
111
112
|
t.belongs_to :user, :null => false
|
|
113
|
+
t.string :type, :default => nil
|
|
112
114
|
t.timestamps
|
|
113
115
|
end
|
|
114
116
|
ActiveRecord::Base.connection.create_sequence_for :events_users_histories
|
|
@@ -123,4 +125,44 @@ namespace :turntable do
|
|
|
123
125
|
desc "reset turntable test databases"
|
|
124
126
|
task :reset => ["turntable:db:drop", "turntable:db:create", "turntable:db:migrate"]
|
|
125
127
|
end
|
|
128
|
+
|
|
129
|
+
namespace :activerecord do
|
|
130
|
+
task(:env) do
|
|
131
|
+
ENV["ARCONFIG"] ||= File.expand_path("spec/config/activerecord_config.yml", __dir__)
|
|
132
|
+
ENV["ARVERSION"] ||= if ActiveRecord.gem_version.prerelease?
|
|
133
|
+
"origin/master"
|
|
134
|
+
else
|
|
135
|
+
"v#{ActiveRecord.gem_version}"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
namespace :setup do
|
|
140
|
+
task :rails => :env do
|
|
141
|
+
system(*%w|git submodule update --init|)
|
|
142
|
+
system(*%w|git submodule foreach git fetch origin|)
|
|
143
|
+
Dir.chdir("tmp/rails") do
|
|
144
|
+
system(*%W|git checkout #{ENV['ARVERSION']}|)
|
|
145
|
+
end
|
|
146
|
+
FileUtils.cp_r("tmp/rails/activerecord/test", ".")
|
|
147
|
+
FileUtils.cp_r("tmp/rails/activerecord/Rakefile", "activerecord.rake")
|
|
148
|
+
File.open("test/cases/helper.rb", "a") do |f|
|
|
149
|
+
f << "require '#{File.expand_path("spec/activerecord_helper", __dir__)}'"
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
task :db => :rails do
|
|
154
|
+
system(*%w|bundle exec rake -f activerecord.rake db:mysql:rebuild|)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
desc "setup activerecord test"
|
|
159
|
+
task :setup => ["setup:rails", "setup:db"]
|
|
160
|
+
|
|
161
|
+
desc "run unit tests on activerecord"
|
|
162
|
+
task :test => :env do
|
|
163
|
+
unless system(*%w|bundle exec rake -f activerecord.rake test:mysql2|)
|
|
164
|
+
exit(1)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
126
168
|
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
|
2
2
|
require "active_record/turntable/version"
|
|
3
|
-
|
|
4
3
|
Gem::Specification.new do |spec|
|
|
5
4
|
spec.name = "activerecord-turntable"
|
|
6
5
|
spec.version = ActiveRecord::Turntable::VERSION
|
|
@@ -17,9 +16,10 @@ Gem::Specification.new do |spec|
|
|
|
17
16
|
"CHANGELOG.md",
|
|
18
17
|
]
|
|
19
18
|
|
|
20
|
-
spec.files = `git ls-files`.split(
|
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
20
|
+
f.match(%r{^(test|spec|features|tmp)/})
|
|
21
|
+
end
|
|
21
22
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
22
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
23
23
|
spec.require_paths = ["lib"]
|
|
24
24
|
spec.required_ruby_version = ">= 2.2.2"
|
|
25
25
|
|
|
@@ -42,12 +42,22 @@ Gem::Specification.new do |spec|
|
|
|
42
42
|
spec.add_development_dependency "pry"
|
|
43
43
|
spec.add_development_dependency "pry-byebug"
|
|
44
44
|
spec.add_development_dependency "rack"
|
|
45
|
+
spec.add_development_dependency "rails"
|
|
45
46
|
spec.add_development_dependency "rake"
|
|
46
47
|
spec.add_development_dependency "rspec", "~> 3.5.0"
|
|
47
48
|
spec.add_development_dependency "rspec-collection_matchers"
|
|
48
49
|
spec.add_development_dependency "rspec-its"
|
|
50
|
+
spec.add_development_dependency "rspec-parameterized"
|
|
51
|
+
spec.add_development_dependency "rspec-rails"
|
|
49
52
|
spec.add_development_dependency "rubocop"
|
|
50
53
|
spec.add_development_dependency "rubocop-rspec"
|
|
51
54
|
spec.add_development_dependency "timecop"
|
|
52
55
|
spec.add_development_dependency "webmock"
|
|
56
|
+
|
|
57
|
+
# activerecord testing dependencies
|
|
58
|
+
spec.add_development_dependency "actionview"
|
|
59
|
+
spec.add_development_dependency "bcrypt", "~> 3.1.11"
|
|
60
|
+
spec.add_development_dependency "minitest", "< 5.3.4"
|
|
61
|
+
spec.add_development_dependency "mocha", "~> 0.14"
|
|
62
|
+
spec.add_development_dependency "sqlite3", "~> 1.3.6"
|
|
53
63
|
end
|
|
@@ -14,6 +14,7 @@ module ActiveRecord::Turntable
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
# @note override for append current shard name
|
|
17
|
+
# rubocop:disable Style/HashSyntax, Style/MultilineMethodCallBraceLayout
|
|
17
18
|
def log(sql, name = "SQL", binds = [], statement_name = nil)
|
|
18
19
|
@instrumenter.instrument(
|
|
19
20
|
"sql.active_record",
|
|
@@ -26,6 +27,7 @@ module ActiveRecord::Turntable
|
|
|
26
27
|
rescue => e
|
|
27
28
|
raise translate_exception_class(e, sql)
|
|
28
29
|
end
|
|
30
|
+
# rubocop:enable Style/HashSyntax, Style/MultilineMethodCallBraceLayout
|
|
29
31
|
|
|
30
32
|
protected :translate_exception_class, :log
|
|
31
33
|
|
|
@@ -34,7 +36,7 @@ module ActiveRecord::Turntable
|
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
def turntable_shard_name
|
|
37
|
-
@turntable_shard_name
|
|
39
|
+
instance_variable_defined?(:@turntable_shard_name) ? @turntable_shard_name : nil
|
|
38
40
|
end
|
|
39
41
|
end
|
|
40
42
|
end
|
|
@@ -3,9 +3,11 @@ module ActiveRecord::Turntable
|
|
|
3
3
|
# activerecord-import extension
|
|
4
4
|
module ActiverecordImportExt
|
|
5
5
|
# @note override for sequencer injection
|
|
6
|
-
# @see https://github.com/zdennis/activerecord-import/blob/
|
|
6
|
+
# @see https://github.com/zdennis/activerecord-import/blob/b325ebb644160a09db6e269e414f33561cb21272/lib/activerecord-import/import.rb#L661-L689
|
|
7
7
|
private def values_sql_for_columns_and_attributes(columns, array_of_attributes)
|
|
8
8
|
connection_memo = connection
|
|
9
|
+
type_caster_memo = type_caster if respond_to?(:type_caster)
|
|
10
|
+
|
|
9
11
|
array_of_attributes.map do |arr|
|
|
10
12
|
my_values = arr.each_with_index.map do |val, j|
|
|
11
13
|
column = columns[j]
|
|
@@ -18,11 +20,7 @@ module ActiveRecord::Turntable
|
|
|
18
20
|
connection_memo.next_value_for_sequence(sequence_name)
|
|
19
21
|
end
|
|
20
22
|
elsif column
|
|
21
|
-
|
|
22
|
-
connection_memo.quote(type_caster.type_cast_for_database(column.name, val))
|
|
23
|
-
else # Rails 4.2 and higher
|
|
24
|
-
connection_memo.quote(column.type_cast_from_user(val), column)
|
|
25
|
-
end
|
|
23
|
+
connection_memo.quote(type_caster_memo.type_cast_for_database(column.name, val))
|
|
26
24
|
end
|
|
27
25
|
end
|
|
28
26
|
"(#{my_values.join(',')})"
|
|
@@ -34,7 +32,7 @@ module ActiveRecord::Turntable
|
|
|
34
32
|
require "activerecord-import"
|
|
35
33
|
require "activerecord-import/base"
|
|
36
34
|
(class << ActiveRecord::Base; self; end).prepend(ActiverecordImportExt)
|
|
37
|
-
rescue LoadError
|
|
35
|
+
rescue LoadError # rubocop:disable Lint/HandleExceptions
|
|
38
36
|
end
|
|
39
37
|
end
|
|
40
38
|
end
|
|
@@ -16,9 +16,9 @@ module ActiveRecord::Turntable
|
|
|
16
16
|
return super unless should_use_shard_key?
|
|
17
17
|
|
|
18
18
|
scope = klass.where(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
klass.turntable_shard_key =>
|
|
20
|
+
owner.send(foreign_shard_key)
|
|
21
|
+
)
|
|
22
22
|
super.merge!(scope)
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -30,11 +30,11 @@ module ActiveRecord::Turntable
|
|
|
30
30
|
self.each do |obj|
|
|
31
31
|
matched_object = case reflection.macro
|
|
32
32
|
when :has_one
|
|
33
|
-
foreign_objects.find {|fo|
|
|
33
|
+
foreign_objects.find { |fo|
|
|
34
34
|
obj.send(reflection.association_primary_key) == fo.send(reflection.foreign_key)
|
|
35
35
|
}
|
|
36
36
|
when :belongs_to
|
|
37
|
-
foreign_objects.find {|fo|
|
|
37
|
+
foreign_objects.find { |fo|
|
|
38
38
|
obj.send(reflection.foreign_key) == fo.send(reflection.association_primary_key)
|
|
39
39
|
}
|
|
40
40
|
end
|