activerecord-turntable 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +20 -11
- data/CHANGELOG.md +12 -0
- data/Gemfile +2 -4
- data/README.md +1 -1
- data/gemfiles/rails5_0_6.gemfile +8 -0
- data/gemfiles/rails5_0_7.gemfile +6 -0
- data/gemfiles/rails5_1_6.gemfile +7 -0
- data/lib/active_record/turntable/active_record_ext.rb +1 -1
- data/lib/active_record/turntable/active_record_ext/fixtures.rb +0 -5
- data/lib/active_record/turntable/active_record_ext/locking_optimistic.rb +41 -1
- data/lib/active_record/turntable/active_record_ext/log_subscriber.rb +1 -1
- data/lib/active_record/turntable/active_record_ext/persistence.rb +75 -59
- data/lib/active_record/turntable/active_record_ext/query_cache.rb +4 -4
- data/lib/active_record/turntable/base.rb +9 -6
- data/lib/active_record/turntable/cluster_helper_methods.rb +4 -13
- data/lib/active_record/turntable/connection_proxy.rb +6 -7
- data/lib/active_record/turntable/seq_shard.rb +9 -4
- data/lib/active_record/turntable/shard.rb +2 -9
- data/lib/active_record/turntable/util.rb +8 -0
- data/lib/active_record/turntable/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 31aa02feae321af087a80d9a1f9177c0ff7c139a
|
4
|
+
data.tar.gz: dbb3b7404067e3a2b756b96eaa5f76a51e27450d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bb4919921852779beb4b1d31f67f524e5985921c5d00d613799417a769c80eeaf3eec5cd51deaa5ea061cdc0869b8295b785806a5febb2ca7979924482ac79b
|
7
|
+
data.tar.gz: e5f313cc055e68af9520db17c29edcb717b8459b3ccb65819fe9d17e08010937a938277fc2baafa469b4fb8555a7f8f88a1344cf89064eff3a6d259e2cd6fe12
|
data/.travis.yml
CHANGED
@@ -5,10 +5,10 @@ cache:
|
|
5
5
|
bundler: true
|
6
6
|
|
7
7
|
rvm:
|
8
|
-
- 2.2.
|
9
|
-
- 2.3.
|
10
|
-
- 2.4.
|
11
|
-
- 2.5.
|
8
|
+
- 2.2.10
|
9
|
+
- 2.3.7
|
10
|
+
- 2.4.4
|
11
|
+
- 2.5.1
|
12
12
|
- ruby-head
|
13
13
|
|
14
14
|
gemfile:
|
@@ -18,12 +18,15 @@ gemfile:
|
|
18
18
|
- gemfiles/rails5_0_3.gemfile
|
19
19
|
- gemfiles/rails5_0_4.gemfile
|
20
20
|
- gemfiles/rails5_0_5.gemfile
|
21
|
+
- gemfiles/rails5_0_6.gemfile
|
22
|
+
- gemfiles/rails5_0_7.gemfile
|
21
23
|
- gemfiles/rails5_1_0.gemfile
|
22
24
|
- gemfiles/rails5_1_1.gemfile
|
23
25
|
- gemfiles/rails5_1_2.gemfile
|
24
26
|
- gemfiles/rails5_1_3.gemfile
|
25
27
|
- gemfiles/rails5_1_4.gemfile
|
26
28
|
- gemfiles/rails5_1_5.gemfile
|
29
|
+
- gemfiles/rails5_1_6.gemfile
|
27
30
|
- gemfiles/rails_edge.gemfile
|
28
31
|
|
29
32
|
env:
|
@@ -37,6 +40,7 @@ services:
|
|
37
40
|
before_install:
|
38
41
|
- docker run -d --name turntable-katsubushi -p 11212:11212 katsubushi/katsubushi:latest -worker-id 1
|
39
42
|
- gem update --system
|
43
|
+
- gem install bundler --no-doc
|
40
44
|
|
41
45
|
before_script:
|
42
46
|
- bundle exec rake $SETUP_TASK
|
@@ -48,14 +52,19 @@ matrix:
|
|
48
52
|
exclude:
|
49
53
|
- rvm: ruby-head
|
50
54
|
- gemfile: gemfiles/rails_edge.gemfile
|
51
|
-
- rvm: 2.
|
52
|
-
- rvm: 2.
|
55
|
+
- rvm: 2.2.10
|
56
|
+
- rvm: 2.3.7
|
57
|
+
- rvm: 2.4.4
|
53
58
|
include:
|
54
|
-
- rvm: 2.
|
55
|
-
gemfile: gemfiles/
|
56
|
-
- rvm: 2.
|
57
|
-
gemfile: gemfiles/
|
58
|
-
- rvm: 2.
|
59
|
+
- rvm: 2.2.10
|
60
|
+
gemfile: gemfiles/rails5_0_7.gemfile
|
61
|
+
- rvm: 2.2.10
|
62
|
+
gemfile: gemfiles/rails5_1_6.gemfile
|
63
|
+
- rvm: 2.3.7
|
64
|
+
gemfile: gemfiles/rails5_1_6.gemfile
|
65
|
+
- rvm: 2.4.4
|
66
|
+
gemfile: gemfiles/rails5_1_6.gemfile
|
67
|
+
- rvm: 2.5.1
|
59
68
|
gemfile: gemfiles/rails_edge.gemfile
|
60
69
|
- rvm: ruby-head
|
61
70
|
gemfile: gemfiles/rails_edge.gemfile
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## activerecord-turntable 4.1.0 ##
|
2
|
+
|
3
|
+
### Major Changes
|
4
|
+
|
5
|
+
* Support activerecord versions v5.0.6, v5.0.7 and v5.1.6
|
6
|
+
* Remove unneeded monkey patches
|
7
|
+
* Add `ActiveRecord::Base.turntable_pool_list` instead of `ActiveRecord::Base.turntable_connections`
|
8
|
+
|
9
|
+
### BugFixes
|
10
|
+
|
11
|
+
* Fix connection leaks on fork
|
12
|
+
|
1
13
|
## activerecord-turntable 4.0.0 ##
|
2
14
|
|
3
15
|
### Major Changes
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -27,7 +27,7 @@ module ActiveRecord::Turntable
|
|
27
27
|
ActiveRecord::Persistence.include(Persistence)
|
28
28
|
ActiveRecord::Locking::Optimistic.include(LockingOptimistic)
|
29
29
|
ActiveRecord::Relation.include(CleverLoad)
|
30
|
-
ActiveRecord::Relation.prepend(Relation)
|
30
|
+
ActiveRecord::Relation.prepend(Relation) unless Util.ar_version_equals_or_later?("5.1.6")
|
31
31
|
ActiveRecord::Migration.include(ActiveRecord::Turntable::Migration)
|
32
32
|
ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(ConnectionHandlerExtension)
|
33
33
|
ActiveRecord::Associations::Preloader::Association.prepend(AssociationPreloader)
|
@@ -133,10 +133,5 @@ module ActiveRecord
|
|
133
133
|
instantiate_fixtures if use_instantiated_fixtures
|
134
134
|
end
|
135
135
|
# rubocop:enable Style/ClassVars, Style/RedundantException
|
136
|
-
|
137
|
-
def enlist_fixture_connections
|
138
|
-
ActiveRecord::Base.connection_handler.connection_pool_list.map(&:connection) +
|
139
|
-
ActiveRecord::Base.turntable_connections.values.map(&:connection)
|
140
|
-
end
|
141
136
|
end
|
142
137
|
end
|
@@ -1,7 +1,47 @@
|
|
1
1
|
module ActiveRecord::Turntable
|
2
2
|
module ActiveRecordExt
|
3
3
|
module LockingOptimistic
|
4
|
-
if Util.
|
4
|
+
if Util.ar_version_equals_or_later?("5.1.6")
|
5
|
+
::ActiveRecord::Locking::Optimistic.class_eval <<-EOD
|
6
|
+
private
|
7
|
+
def _update_row(attribute_names, attempted_action = "update")
|
8
|
+
return super unless locking_enabled?
|
9
|
+
|
10
|
+
begin
|
11
|
+
locking_column = self.class.locking_column
|
12
|
+
previous_lock_value = read_attribute_before_type_cast(locking_column)
|
13
|
+
attribute_names << locking_column
|
14
|
+
|
15
|
+
self[locking_column] += 1
|
16
|
+
|
17
|
+
constraints = {
|
18
|
+
self.class.primary_key => id_in_database,
|
19
|
+
locking_column => previous_lock_value
|
20
|
+
}
|
21
|
+
if self.class.sharding_condition_needed?
|
22
|
+
constraints[self.class.turntable_shard_key] = self[self.class.turntable_shard_key]
|
23
|
+
end
|
24
|
+
|
25
|
+
affected_rows = self.class.unscoped._update_record(
|
26
|
+
arel_attributes_with_values(attribute_names),
|
27
|
+
constraints,
|
28
|
+
)
|
29
|
+
|
30
|
+
if affected_rows != 1
|
31
|
+
raise ActiveRecord::StaleObjectError.new(self, attempted_action)
|
32
|
+
end
|
33
|
+
|
34
|
+
affected_rows
|
35
|
+
|
36
|
+
# If something went wrong, revert the locking_column value.
|
37
|
+
rescue Exception
|
38
|
+
self[locking_column] = previous_lock_value.to_i
|
39
|
+
raise
|
40
|
+
end
|
41
|
+
end
|
42
|
+
EOD
|
43
|
+
|
44
|
+
elsif Util.ar51_or_later?
|
5
45
|
::ActiveRecord::Locking::Optimistic.class_eval <<-EOD
|
6
46
|
private
|
7
47
|
# @note Override to add sharding condition on optimistic locking
|
@@ -20,7 +20,7 @@ module ActiveRecord::Turntable
|
|
20
20
|
|
21
21
|
unless (payload[:binds] || []).empty?
|
22
22
|
if Util.ar_version_equals_or_later?("5.0.3")
|
23
|
-
casted_params = if Util.
|
23
|
+
casted_params = if Util.ar_version_satisfy?(">= 5.1.5") || Util.ar_version_satisfy?([">= 5.0.7", "< 5.1"])
|
24
24
|
type_casted_binds(payload[:type_casted_binds])
|
25
25
|
else
|
26
26
|
type_casted_binds(payload[:binds], payload[:type_casted_binds])
|
@@ -26,54 +26,56 @@ module ActiveRecord::Turntable
|
|
26
26
|
self
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
unless Util.ar_version_equals_or_later?("5.1.6")
|
30
|
+
# @note Override to add sharding scope on `touch`
|
31
|
+
# rubocop:disable Style/UnlessElse
|
32
|
+
def touch(*names, time: nil)
|
33
|
+
unless persisted?
|
34
|
+
raise ActiveRecord::ActiveRecordError, <<-MSG.squish
|
35
|
+
cannot touch on a new or destroyed record object. Consider using
|
36
|
+
persisted?, new_record?, or destroyed? before touching
|
37
|
+
MSG
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
time ||= current_time_from_proper_timezone
|
41
|
+
attributes = timestamp_attributes_for_update_in_model
|
42
|
+
attributes.concat(names)
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
unless attributes.empty?
|
45
|
+
changes = {}
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
attributes.each do |column|
|
48
|
+
column = column.to_s
|
49
|
+
changes[column] = write_attribute(column, time)
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
if locking_enabled?
|
61
|
-
locking_column = self.class.locking_column
|
62
|
-
scope = scope.where(locking_column => _read_attribute(locking_column))
|
63
|
-
changes[locking_column] = increment_lock
|
64
|
-
end
|
52
|
+
clear_attribute_changes(changes.keys) unless Util.ar51_or_later?
|
53
|
+
primary_key = self.class.primary_key
|
54
|
+
scope = if turntable_enabled? && primary_key != self.class.turntable_shard_key.to_s
|
55
|
+
self.class.unscoped.where(self.class.turntable_shard_key => _read_attribute(turntable_shard_key))
|
56
|
+
else
|
57
|
+
self.class.unscoped
|
58
|
+
end
|
59
|
+
scope = scope.where(primary_key => _read_attribute(primary_key))
|
65
60
|
|
66
|
-
|
67
|
-
|
61
|
+
if locking_enabled?
|
62
|
+
locking_column = self.class.locking_column
|
63
|
+
scope = scope.where(locking_column => _read_attribute(locking_column))
|
64
|
+
changes[locking_column] = increment_lock
|
65
|
+
end
|
68
66
|
|
69
|
-
|
70
|
-
|
71
|
-
end
|
67
|
+
clear_attribute_changes(changes.keys) if Util.ar51_or_later?
|
68
|
+
result = scope.update_all(changes) == 1
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
if !result && locking_enabled?
|
71
|
+
raise ActiveRecord::StaleObjectError.new(self, "touch")
|
72
|
+
end
|
73
|
+
|
74
|
+
@_trigger_update_callback = result
|
75
|
+
result
|
76
|
+
else
|
77
|
+
true
|
78
|
+
end
|
77
79
|
end
|
78
80
|
end
|
79
81
|
# rubocop:enable Style/UnlessElse
|
@@ -115,25 +117,39 @@ module ActiveRecord::Turntable
|
|
115
117
|
relation
|
116
118
|
end
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
120
|
+
if Util.ar_version_equals_or_later?("5.1.6")
|
121
|
+
def _update_row(attribute_names, attempted_action = "update")
|
122
|
+
constraints = { self.class.primary_key => id_in_database }
|
123
|
+
if self.class.sharding_condition_needed?
|
124
|
+
constraints[self.class.turntable_shard_key] = self[self.class.turntable_shard_key]
|
125
|
+
end
|
126
|
+
|
127
|
+
self.class.unscoped._update_record(
|
128
|
+
arel_attributes_with_values(attribute_names),
|
129
|
+
constraints,
|
130
|
+
)
|
131
|
+
end
|
132
|
+
else
|
133
|
+
# @note Override to add sharding scope on updating
|
134
|
+
def _update_record(attribute_names = self.attribute_names)
|
135
|
+
klass = self.class
|
136
|
+
attributes_values = arel_attributes_with_values_for_update(attribute_names)
|
137
|
+
if attributes_values.empty?
|
138
|
+
rows_affected = 0
|
139
|
+
@_trigger_update_callback = true
|
140
|
+
else
|
141
|
+
scope = if klass.turntable_enabled? && (klass.primary_key != klass.turntable_shard_key.to_s)
|
142
|
+
klass.unscoped.where(klass.turntable_shard_key => self.send(turntable_shard_key))
|
143
|
+
end
|
144
|
+
previous_id = Util.ar51_or_later? ? id_in_database : id_was
|
145
|
+
rows_affected = klass.unscoped._update_record attributes_values, id, previous_id, scope
|
146
|
+
@_trigger_update_callback = rows_affected > 0
|
147
|
+
end
|
148
|
+
|
149
|
+
yield(self) if block_given?
|
150
|
+
|
151
|
+
rows_affected
|
132
152
|
end
|
133
|
-
|
134
|
-
yield(self) if block_given?
|
135
|
-
|
136
|
-
rows_affected
|
137
153
|
end
|
138
154
|
end
|
139
155
|
end
|
@@ -14,7 +14,7 @@ module ActiveRecord::Turntable
|
|
14
14
|
def run
|
15
15
|
result = super
|
16
16
|
|
17
|
-
pools = ActiveRecord::Base.
|
17
|
+
pools = ActiveRecord::Base.turntable_pool_list
|
18
18
|
pools.each do |pool|
|
19
19
|
pool.enable_query_cache!
|
20
20
|
end
|
@@ -36,7 +36,7 @@ module ActiveRecord::Turntable
|
|
36
36
|
def run
|
37
37
|
result = super
|
38
38
|
|
39
|
-
pools = ActiveRecord::Base.
|
39
|
+
pools = ActiveRecord::Base.turntable_pool_list
|
40
40
|
pools.each do |pool|
|
41
41
|
pool.enable_query_cache!
|
42
42
|
end
|
@@ -58,7 +58,7 @@ module ActiveRecord::Turntable
|
|
58
58
|
def run
|
59
59
|
result = super
|
60
60
|
|
61
|
-
pools = ActiveRecord::Base.
|
61
|
+
pools = ActiveRecord::Base.turntable_pool_list
|
62
62
|
pools.each do |k|
|
63
63
|
k.connection.enable_query_cache!
|
64
64
|
end
|
@@ -70,7 +70,7 @@ module ActiveRecord::Turntable
|
|
70
70
|
enabled, _connection_id = state
|
71
71
|
super
|
72
72
|
|
73
|
-
klasses = ActiveRecord::Base.
|
73
|
+
klasses = ActiveRecord::Base.turntable_pool_list
|
74
74
|
klasses.each do |k|
|
75
75
|
k.connection.clear_query_cache
|
76
76
|
k.connection.disable_query_cache! unless enabled
|
@@ -5,10 +5,9 @@ module ActiveRecord::Turntable
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
class_attribute :
|
8
|
+
class_attribute :turntable_clusters, :turntable_sequencers,
|
9
9
|
:turntable_enabled, :turntable_sequencer_enabled, :turntable_configuration
|
10
10
|
|
11
|
-
self.turntable_connections = {}
|
12
11
|
self.turntable_clusters = {}.with_indifferent_access
|
13
12
|
self.turntable_sequencers = {}.with_indifferent_access
|
14
13
|
self.turntable_enabled = false
|
@@ -52,6 +51,10 @@ module ActiveRecord::Turntable
|
|
52
51
|
turntable_clusters[turntable_cluster_name]
|
53
52
|
end
|
54
53
|
|
54
|
+
def turntable_pool_list
|
55
|
+
turntable_clusters.values.map { |cluster| cluster.shards.map(&:connection_pool) }.flatten.uniq
|
56
|
+
end
|
57
|
+
|
55
58
|
def turntable_replace_connection_pool
|
56
59
|
ch = connection_handler
|
57
60
|
cp = ConnectionProxy.new(self, turntable_cluster)
|
@@ -61,10 +64,6 @@ module ActiveRecord::Turntable
|
|
61
64
|
ch.send(:owner_to_pool)[connection_specification_name] = pp
|
62
65
|
end
|
63
66
|
|
64
|
-
def clear_all_connections!
|
65
|
-
turntable_connections.values.each(&:disconnect!)
|
66
|
-
end
|
67
|
-
|
68
67
|
def sequencer(sequencer_name, *args)
|
69
68
|
class_attribute :turntable_sequencer_name
|
70
69
|
class << self
|
@@ -83,6 +82,10 @@ module ActiveRecord::Turntable
|
|
83
82
|
turntable_enabled
|
84
83
|
end
|
85
84
|
|
85
|
+
def sharding_condition_needed?
|
86
|
+
turntable_enabled? && primary_key != turntable_shard_key.to_s
|
87
|
+
end
|
88
|
+
|
86
89
|
def sequencer_enabled?
|
87
90
|
turntable_sequencer_enabled
|
88
91
|
end
|
@@ -13,9 +13,9 @@ module ActiveRecord::Turntable
|
|
13
13
|
module ClassMethods
|
14
14
|
def force_transaction_all_shards!(options = {}, &block)
|
15
15
|
force_connect_all_shards!
|
16
|
-
|
17
|
-
|
18
|
-
recursive_transaction(
|
16
|
+
pools = turntable_pool_list
|
17
|
+
pools += [ActiveRecord::Base.connection_pool]
|
18
|
+
recursive_transaction(pools, options, &block)
|
19
19
|
end
|
20
20
|
|
21
21
|
def recursive_transaction(pools, options, &block)
|
@@ -30,16 +30,7 @@ module ActiveRecord::Turntable
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def force_connect_all_shards!
|
33
|
-
|
34
|
-
return unless conf
|
35
|
-
|
36
|
-
shards = HashWithIndifferentAccess.new
|
37
|
-
shards = shards.merge(conf[:shards]) if conf[:shards]
|
38
|
-
shards = shards.merge(conf[:seq]) if conf[:seq]
|
39
|
-
shards.each do |name, config|
|
40
|
-
turntable_connections[name] ||=
|
41
|
-
ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec_for(config))
|
42
|
-
end
|
33
|
+
turntable_pool_list.each(&:connection)
|
43
34
|
end
|
44
35
|
|
45
36
|
def spec_for(config)
|
@@ -59,16 +59,16 @@ module ActiveRecord::Turntable
|
|
59
59
|
def enable_query_cache!
|
60
60
|
default_connection.enable_query_cache!
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
cluster.shards.each do |shard|
|
63
|
+
shard.connection.enable_query_cache!
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
def disable_query_cache!
|
68
68
|
default_connection.disable_query_cache!
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
cluster.shards.each do |shard|
|
71
|
+
shard.connection.disable_query_cache!
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -79,12 +79,11 @@ module ActiveRecord::Turntable
|
|
79
79
|
def clear_query_cache
|
80
80
|
default_connection.clear_query_cache
|
81
81
|
|
82
|
-
|
83
|
-
|
82
|
+
cluster.shards.each do |shard|
|
83
|
+
shard.connection.clear_query_cache
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
|
88
87
|
# rubocop:disable Style/MethodMissing
|
89
88
|
def method_missing(method, *args, &block)
|
90
89
|
clear_query_cache_if_needed(method)
|
@@ -10,10 +10,15 @@ module ActiveRecord::Turntable
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def connection_class_instance
|
14
|
+
if Connections.const_defined?(name.classify)
|
15
|
+
klass = Connections.const_get(name.classify)
|
16
|
+
else
|
17
|
+
klass = Class.new(ActiveRecord::Base)
|
18
|
+
Connections.const_set(name.classify, klass)
|
19
|
+
klass.abstract_class = true
|
20
|
+
klass.establish_connection ActiveRecord::Base.connection_pool.spec.config[:seq][name].with_indifferent_access
|
21
|
+
end
|
17
22
|
klass
|
18
23
|
end
|
19
24
|
end
|
@@ -11,7 +11,6 @@ module ActiveRecord::Turntable
|
|
11
11
|
@cluster = cluster
|
12
12
|
@name = name
|
13
13
|
@slaves = slaves.map { |s| SlaveShard.new(cluster, s) }
|
14
|
-
ActiveRecord::Base.turntable_connections[name] = connection_pool
|
15
14
|
end
|
16
15
|
|
17
16
|
def connection_pool
|
@@ -43,14 +42,7 @@ module ActiveRecord::Turntable
|
|
43
42
|
private
|
44
43
|
|
45
44
|
def connection_klass
|
46
|
-
@connection_klass ||=
|
47
|
-
end
|
48
|
-
|
49
|
-
def create_connection_class
|
50
|
-
klass = connection_class_instance
|
51
|
-
klass.remove_connection
|
52
|
-
klass.establish_connection ActiveRecord::Base.connection_pool.spec.config[:shards][name].with_indifferent_access
|
53
|
-
klass
|
45
|
+
@connection_klass ||= connection_class_instance
|
54
46
|
end
|
55
47
|
|
56
48
|
def connection_class_instance
|
@@ -60,6 +52,7 @@ module ActiveRecord::Turntable
|
|
60
52
|
klass = Class.new(ActiveRecord::Base)
|
61
53
|
Connections.const_set(name.classify, klass)
|
62
54
|
klass.abstract_class = true
|
55
|
+
klass.establish_connection ActiveRecord::Base.connection_pool.spec.config[:shards][name].with_indifferent_access
|
63
56
|
end
|
64
57
|
klass
|
65
58
|
end
|
@@ -12,6 +12,13 @@ module ActiveRecord::Turntable
|
|
12
12
|
ActiveRecord.gem_version.release
|
13
13
|
end
|
14
14
|
|
15
|
+
def ar_version_satisfy?(requirement)
|
16
|
+
unless requirement.is_a?(Gem::Requirement)
|
17
|
+
requirement = Gem::Requirement.new(requirement)
|
18
|
+
end
|
19
|
+
requirement.satisfied_by?(ar_version)
|
20
|
+
end
|
21
|
+
|
15
22
|
def ar51_or_later?
|
16
23
|
ar_version_equals_or_later?("5.1")
|
17
24
|
end
|
@@ -19,6 +26,7 @@ module ActiveRecord::Turntable
|
|
19
26
|
module_function :ar_version_equals_or_later?,
|
20
27
|
:ar_version_earlier_than?,
|
21
28
|
:ar_version,
|
29
|
+
:ar_version_satisfy?,
|
22
30
|
:ar51_or_later?
|
23
31
|
end
|
24
32
|
end
|
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: 4.
|
4
|
+
version: 4.1.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: 2018-04-
|
12
|
+
date: 2018-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -529,12 +529,15 @@ files:
|
|
529
529
|
- gemfiles/rails5_0_3.gemfile
|
530
530
|
- gemfiles/rails5_0_4.gemfile
|
531
531
|
- gemfiles/rails5_0_5.gemfile
|
532
|
+
- gemfiles/rails5_0_6.gemfile
|
533
|
+
- gemfiles/rails5_0_7.gemfile
|
532
534
|
- gemfiles/rails5_1_0.gemfile
|
533
535
|
- gemfiles/rails5_1_1.gemfile
|
534
536
|
- gemfiles/rails5_1_2.gemfile
|
535
537
|
- gemfiles/rails5_1_3.gemfile
|
536
538
|
- gemfiles/rails5_1_4.gemfile
|
537
539
|
- gemfiles/rails5_1_5.gemfile
|
540
|
+
- gemfiles/rails5_1_6.gemfile
|
538
541
|
- gemfiles/rails_edge.gemfile
|
539
542
|
- lib/active_record/turntable.rb
|
540
543
|
- lib/active_record/turntable/active_record_ext.rb
|
@@ -632,7 +635,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
632
635
|
version: '0'
|
633
636
|
requirements: []
|
634
637
|
rubyforge_project: activerecord-turntable
|
635
|
-
rubygems_version: 2.
|
638
|
+
rubygems_version: 2.6.14
|
636
639
|
signing_key:
|
637
640
|
specification_version: 4
|
638
641
|
summary: ActiveRecord sharding extension
|