active_record_shards 3.11.0 → 3.19.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.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'active_record'
3
4
  require 'active_record/base'
4
5
  require 'active_record_shards/configuration_parser'
@@ -7,7 +8,8 @@ require 'active_record_shards/shard_selection'
7
8
  require 'active_record_shards/connection_switcher'
8
9
  require 'active_record_shards/association_collection_connection_selection'
9
10
  require 'active_record_shards/migration'
10
- require 'active_record_shards/default_slave_patches'
11
+ require 'active_record_shards/default_replica_patches'
12
+ require 'active_record_shards/schema_dumper_extension'
11
13
 
12
14
  module ActiveRecordShards
13
15
  def self.rails_env
@@ -21,17 +23,119 @@ end
21
23
  ActiveRecord::Base.extend(ActiveRecordShards::ConfigurationParser)
22
24
  ActiveRecord::Base.extend(ActiveRecordShards::Model)
23
25
  ActiveRecord::Base.extend(ActiveRecordShards::ConnectionSwitcher)
24
- ActiveRecord::Base.extend(ActiveRecordShards::DefaultSlavePatches)
25
- ActiveRecord::Relation.include(ActiveRecordShards::DefaultSlavePatches::ActiveRelationPatches)
26
+ ActiveRecord::Base.extend(ActiveRecordShards::DefaultReplicaPatches)
27
+ ActiveRecord::Relation.include(ActiveRecordShards::DefaultReplicaPatches::ActiveRelationPatches)
26
28
  ActiveRecord::Associations::CollectionProxy.include(ActiveRecordShards::AssociationCollectionConnectionSelection)
29
+ ActiveRecord::Associations::Builder::HasAndBelongsToMany.include(ActiveRecordShards::DefaultReplicaPatches::Rails41HasAndBelongsToManyBuilderExtension)
30
+ ActiveRecord::SchemaDumper.prepend(ActiveRecordShards::SchemaDumperExtension)
27
31
 
28
32
  case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
29
- when '3.2'
30
- require 'active_record_shards/patches-3-2'
31
33
  when '4.2'
32
34
  require 'active_record_shards/patches-4-2'
33
- when '5.0', '5.1'
34
- require 'active_record_shards/patches-5-0'
35
+
36
+ # https://github.com/rails/rails/blob/v4.2.11.3/activerecord/lib/active_record/associations/association.rb#L97
37
+ ActiveRecord::Associations::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationAssociationScopePatch)
38
+
39
+ # https://github.com/rails/rails/blob/v4.2.11.3/activerecord/lib/active_record/associations/singular_association.rb#L44-L53
40
+ ActiveRecord::Associations::SingularAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationGetRecordsPatch)
41
+
42
+ # https://github.com/rails/rails/blob/v4.2.11.3/activerecord/lib/active_record/associations/collection_association.rb#L447-L456
43
+ ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationGetRecordsPatch)
44
+
45
+ # https://github.com/rails/rails/blob/v4.2.11.3/activerecord/lib/active_record/associations/preloader/association.rb#L89
46
+ ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsPreloaderAssociationAssociatedRecordsByOwnerPatch)
47
+ when '5.0'
48
+ # https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/associations/association.rb#L97
49
+ ActiveRecord::Associations::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationAssociationScopePatch)
50
+
51
+ # https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/associations/singular_association.rb#L56-L65
52
+ ActiveRecord::Associations::SingularAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationGetRecordsPatch)
53
+
54
+ # https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/associations/collection_association.rb#L442-L451
55
+ ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationGetRecordsPatch)
56
+
57
+ # https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/associations/preloader/association.rb#L120
58
+ ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsPreloaderAssociationLoadRecordsPatch)
59
+ when '5.1'
60
+ # https://github.com/rails/rails/blob/v5.1.7/activerecord/lib/active_record/associations/association.rb#L97
61
+ ActiveRecord::Associations::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationAssociationScopePatch)
62
+
63
+ # https://github.com/rails/rails/blob/v5.1.7/activerecord/lib/active_record/associations/singular_association.rb#L41
64
+ ActiveRecord::Associations::SingularAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationFindTargetPatch)
65
+
66
+ # https://github.com/rails/rails/blob/v5.1.7/activerecord/lib/active_record/associations/collection_association.rb#L305
67
+ ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationFindTargetPatch)
68
+
69
+ # https://github.com/rails/rails/blob/v5.1.7/activerecord/lib/active_record/associations/preloader/association.rb#L120
70
+ ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsPreloaderAssociationLoadRecordsPatch)
71
+ when '5.2'
72
+ # https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/relation.rb#L530
73
+ # But the #exec_queries method also calls #connection, and I don't know if we should patch that one, too...
74
+ ActiveRecord::Relation.prepend(ActiveRecordShards::DefaultReplicaPatches::Rails52RelationPatches)
75
+
76
+ # https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/associations/singular_association.rb#L42
77
+ ActiveRecord::Associations::SingularAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationFindTargetPatch)
78
+
79
+ # https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/associations/collection_association.rb#L308
80
+ ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationFindTargetPatch)
81
+
82
+ # https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/associations/preloader/association.rb#L96
83
+ ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsPreloaderAssociationLoadRecordsPatch)
84
+ when '6.0'
85
+ # https://github.com/rails/rails/blob/v6.0.4/activerecord/lib/active_record/type_caster/connection.rb#L28
86
+ ActiveRecord::TypeCaster::Connection.prepend(ActiveRecordShards::DefaultReplicaPatches::TypeCasterConnectionConnectionPatch)
87
+
88
+ # https://github.com/rails/rails/blob/v6.0.4/activerecord/lib/active_record/schema.rb#L53-L54
89
+ ActiveRecord::Schema.prepend(ActiveRecordShards::DefaultReplicaPatches::SchemaDefinePatch)
90
+
91
+ # https://github.com/rails/rails/blob/v6.0.4/activerecord/lib/active_record/relation.rb#L739
92
+ # But the #exec_queries and #compute_cache_version methods also call #connection, and I don't know if we should patch those, too...
93
+ ActiveRecord::Relation.prepend(ActiveRecordShards::DefaultReplicaPatches::Rails52RelationPatches)
94
+
95
+ # https://github.com/rails/rails/blob/v6.0.4/activerecord/lib/active_record/associations/association.rb#L213
96
+ ActiveRecord::Associations::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationFindTargetPatch)
35
97
  else
36
98
  raise "ActiveRecordShards is not compatible with #{ActiveRecord::VERSION::STRING}"
37
99
  end
100
+
101
+ require 'active_record_shards/deprecation'
102
+
103
+ ActiveRecordShards::Deprecation.deprecate_methods(
104
+ ActiveRecordShards::AssociationCollectionConnectionSelection,
105
+ on_slave_if: :on_replica_if,
106
+ on_slave_unless: :on_replica_unless,
107
+ on_slave: :on_replica,
108
+ on_master: :on_primary,
109
+ on_master_if: :on_primary_if,
110
+ on_master_unless: :on_primary_unless
111
+ )
112
+
113
+ ActiveRecordShards::Deprecation.deprecate_methods(
114
+ ActiveRecordShards::ConnectionSwitcher,
115
+ on_slave_if: :on_replica_if,
116
+ on_slave_unless: :on_replica_unless,
117
+ on_master_or_slave: :on_primary_or_replica,
118
+ on_slave: :on_replica,
119
+ on_master: :on_primary,
120
+ on_master_if: :on_primary_if,
121
+ on_master_unless: :on_primary_unless,
122
+ on_slave?: :on_replica?
123
+ )
124
+
125
+ ActiveRecordShards::Deprecation.deprecate_methods(
126
+ ActiveRecordShards::DefaultReplicaPatches,
127
+ transaction_with_slave_off: :transaction_with_replica_off,
128
+ on_slave_unless_tx: :on_replica_unless_tx
129
+ )
130
+
131
+ ActiveRecordShards::Deprecation.deprecate_methods(
132
+ ActiveRecordShards::Model,
133
+ on_slave_by_default?: :on_replica_by_default?,
134
+ :on_slave_by_default= => :on_replica_by_default=
135
+ )
136
+
137
+ ActiveRecordShards::Deprecation.deprecate_methods(
138
+ ActiveRecordShards::ShardSelection,
139
+ on_slave?: :on_replica?,
140
+ :on_slave= => :on_replica=
141
+ )
metadata CHANGED
@@ -1,16 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_shards
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.11.0
4
+ version: 3.19.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Benjamin Quorning
8
+ - Gabe Martin-Dempesy
9
+ - Pierre Schambacher
7
10
  - Mick Staugaard
8
11
  - Eric Chapweske
9
12
  - Ben Osheroff
10
- autorequire:
13
+ autorequire:
11
14
  bindir: bin
12
15
  cert_chain: []
13
- date: 2017-09-05 00:00:00.000000000 Z
16
+ date: 2021-07-09 00:00:00.000000000 Z
14
17
  dependencies:
15
18
  - !ruby/object:Gem::Dependency
16
19
  name: activerecord
@@ -18,42 +21,42 @@ dependencies:
18
21
  requirements:
19
22
  - - ">="
20
23
  - !ruby/object:Gem::Version
21
- version: 3.2.16
24
+ version: '4.2'
22
25
  - - "<"
23
26
  - !ruby/object:Gem::Version
24
- version: '5.2'
27
+ version: '6.1'
25
28
  type: :runtime
26
29
  prerelease: false
27
30
  version_requirements: !ruby/object:Gem::Requirement
28
31
  requirements:
29
32
  - - ">="
30
33
  - !ruby/object:Gem::Version
31
- version: 3.2.16
34
+ version: '4.2'
32
35
  - - "<"
33
36
  - !ruby/object:Gem::Version
34
- version: '5.2'
37
+ version: '6.1'
35
38
  - !ruby/object:Gem::Dependency
36
39
  name: activesupport
37
40
  requirement: !ruby/object:Gem::Requirement
38
41
  requirements:
39
42
  - - ">="
40
43
  - !ruby/object:Gem::Version
41
- version: 3.2.16
44
+ version: '4.2'
42
45
  - - "<"
43
46
  - !ruby/object:Gem::Version
44
- version: '5.2'
47
+ version: '6.1'
45
48
  type: :runtime
46
49
  prerelease: false
47
50
  version_requirements: !ruby/object:Gem::Requirement
48
51
  requirements:
49
52
  - - ">="
50
53
  - !ruby/object:Gem::Version
51
- version: 3.2.16
54
+ version: '4.2'
52
55
  - - "<"
53
56
  - !ruby/object:Gem::Version
54
- version: '5.2'
57
+ version: '6.1'
55
58
  - !ruby/object:Gem::Dependency
56
- name: wwtd
59
+ name: bump
57
60
  requirement: !ruby/object:Gem::Requirement
58
61
  requirements:
59
62
  - - ">="
@@ -67,21 +70,21 @@ dependencies:
67
70
  - !ruby/object:Gem::Version
68
71
  version: '0'
69
72
  - !ruby/object:Gem::Dependency
70
- name: rake
73
+ name: minitest
71
74
  requirement: !ruby/object:Gem::Requirement
72
75
  requirements:
73
- - - "~>"
76
+ - - ">="
74
77
  - !ruby/object:Gem::Version
75
- version: '12.0'
78
+ version: 5.10.0
76
79
  type: :development
77
80
  prerelease: false
78
81
  version_requirements: !ruby/object:Gem::Requirement
79
82
  requirements:
80
- - - "~>"
83
+ - - ">="
81
84
  - !ruby/object:Gem::Version
82
- version: '12.0'
85
+ version: 5.10.0
83
86
  - !ruby/object:Gem::Dependency
84
- name: mysql2
87
+ name: minitest-rg
85
88
  requirement: !ruby/object:Gem::Requirement
86
89
  requirements:
87
90
  - - ">="
@@ -95,94 +98,95 @@ dependencies:
95
98
  - !ruby/object:Gem::Version
96
99
  version: '0'
97
100
  - !ruby/object:Gem::Dependency
98
- name: bump
101
+ name: mocha
99
102
  requirement: !ruby/object:Gem::Requirement
100
103
  requirements:
101
104
  - - ">="
102
105
  - !ruby/object:Gem::Version
103
- version: '0'
106
+ version: 1.4.0
104
107
  type: :development
105
108
  prerelease: false
106
109
  version_requirements: !ruby/object:Gem::Requirement
107
110
  requirements:
108
111
  - - ">="
109
112
  - !ruby/object:Gem::Version
110
- version: '0'
113
+ version: 1.4.0
111
114
  - !ruby/object:Gem::Dependency
112
- name: rubocop
115
+ name: mysql2
113
116
  requirement: !ruby/object:Gem::Requirement
114
117
  requirements:
115
- - - '='
118
+ - - ">="
116
119
  - !ruby/object:Gem::Version
117
- version: 0.49.1
120
+ version: '0'
118
121
  type: :development
119
122
  prerelease: false
120
123
  version_requirements: !ruby/object:Gem::Requirement
121
124
  requirements:
122
- - - '='
125
+ - - ">="
123
126
  - !ruby/object:Gem::Version
124
- version: 0.49.1
127
+ version: '0'
125
128
  - !ruby/object:Gem::Dependency
126
- name: minitest
129
+ name: rake
127
130
  requirement: !ruby/object:Gem::Requirement
128
131
  requirements:
129
- - - ">="
132
+ - - "~>"
130
133
  - !ruby/object:Gem::Version
131
- version: '0'
134
+ version: '12.0'
132
135
  type: :development
133
136
  prerelease: false
134
137
  version_requirements: !ruby/object:Gem::Requirement
135
138
  requirements:
136
- - - ">="
139
+ - - "~>"
137
140
  - !ruby/object:Gem::Version
138
- version: '0'
141
+ version: '12.0'
139
142
  - !ruby/object:Gem::Dependency
140
- name: minitest-rg
143
+ name: rubocop
141
144
  requirement: !ruby/object:Gem::Requirement
142
145
  requirements:
143
- - - ">="
146
+ - - "~>"
144
147
  - !ruby/object:Gem::Version
145
- version: '0'
148
+ version: 0.77.0
146
149
  type: :development
147
150
  prerelease: false
148
151
  version_requirements: !ruby/object:Gem::Requirement
149
152
  requirements:
150
- - - ">="
153
+ - - "~>"
151
154
  - !ruby/object:Gem::Version
152
- version: '0'
155
+ version: 0.77.0
153
156
  - !ruby/object:Gem::Dependency
154
- name: mocha
157
+ name: rubocop-minitest
155
158
  requirement: !ruby/object:Gem::Requirement
156
159
  requirements:
157
- - - ">="
160
+ - - "~>"
158
161
  - !ruby/object:Gem::Version
159
- version: '0'
162
+ version: 0.5.0
160
163
  type: :development
161
164
  prerelease: false
162
165
  version_requirements: !ruby/object:Gem::Requirement
163
166
  requirements:
164
- - - ">="
167
+ - - "~>"
165
168
  - !ruby/object:Gem::Version
166
- version: '0'
169
+ version: 0.5.0
167
170
  - !ruby/object:Gem::Dependency
168
- name: phenix
171
+ name: rubocop-performance
169
172
  requirement: !ruby/object:Gem::Requirement
170
173
  requirements:
171
- - - ">="
174
+ - - "~>"
172
175
  - !ruby/object:Gem::Version
173
- version: 0.2.0
176
+ version: 1.5.1
174
177
  type: :development
175
178
  prerelease: false
176
179
  version_requirements: !ruby/object:Gem::Requirement
177
180
  requirements:
178
- - - ">="
181
+ - - "~>"
179
182
  - !ruby/object:Gem::Version
180
- version: 0.2.0
181
- description: Easily run queries on shard and slave databases.
183
+ version: 1.5.1
184
+ description: Easily run queries on shard and replica databases.
182
185
  email:
186
+ - bquorning@zendesk.com
187
+ - gabe@zendesk.com
188
+ - pschambacher@zendesk.com
183
189
  - mick@staugaard.com
184
- - eac@zendesk.com
185
- - ben@gimbo.net
186
190
  executables: []
187
191
  extensions: []
188
192
  extra_rdoc_files: []
@@ -194,16 +198,16 @@ files:
194
198
  - lib/active_record_shards/connection_handler.rb
195
199
  - lib/active_record_shards/connection_pool.rb
196
200
  - lib/active_record_shards/connection_specification.rb
197
- - lib/active_record_shards/connection_switcher-4-0.rb
201
+ - lib/active_record_shards/connection_switcher-4-2.rb
198
202
  - lib/active_record_shards/connection_switcher-5-0.rb
199
203
  - lib/active_record_shards/connection_switcher-5-1.rb
200
204
  - lib/active_record_shards/connection_switcher.rb
205
+ - lib/active_record_shards/default_replica_patches.rb
201
206
  - lib/active_record_shards/default_slave_patches.rb
207
+ - lib/active_record_shards/deprecation.rb
202
208
  - lib/active_record_shards/migration.rb
203
209
  - lib/active_record_shards/model.rb
204
- - lib/active_record_shards/patches-3-2.rb
205
210
  - lib/active_record_shards/patches-4-2.rb
206
- - lib/active_record_shards/patches-5-0.rb
207
211
  - lib/active_record_shards/schema_dumper_extension.rb
208
212
  - lib/active_record_shards/shard_selection.rb
209
213
  - lib/active_record_shards/shard_support.rb
@@ -213,24 +217,23 @@ homepage: https://github.com/zendesk/active_record_shards
213
217
  licenses:
214
218
  - MIT
215
219
  metadata: {}
216
- post_install_message:
220
+ post_install_message:
217
221
  rdoc_options: []
218
222
  require_paths:
219
223
  - lib
220
224
  required_ruby_version: !ruby/object:Gem::Requirement
221
225
  requirements:
222
- - - "~>"
226
+ - - ">="
223
227
  - !ruby/object:Gem::Version
224
- version: '2.0'
228
+ version: '2.3'
225
229
  required_rubygems_version: !ruby/object:Gem::Requirement
226
230
  requirements:
227
231
  - - ">="
228
232
  - !ruby/object:Gem::Version
229
233
  version: '0'
230
234
  requirements: []
231
- rubyforge_project:
232
- rubygems_version: 2.5.1
233
- signing_key:
235
+ rubygems_version: 3.2.16
236
+ signing_key:
234
237
  specification_version: 4
235
238
  summary: Simple database switching for ActiveRecord.
236
239
  test_files: []
@@ -1,68 +0,0 @@
1
- module ActiveRecordShards
2
- module ConnectionSwitcher
3
- # Name of the connection pool. Used by ConnectionHandler to retrieve the current connection pool.
4
- def connection_pool_name # :nodoc:
5
- name = current_shard_selection.shard_name(self)
6
-
7
- if configurations[name].nil? && on_slave?
8
- current_shard_selection.shard_name(self, false)
9
- else
10
- name
11
- end
12
- end
13
-
14
- private
15
-
16
- def ensure_shard_connection
17
- establish_shard_connection unless connected_to_shard?
18
- end
19
-
20
- def establish_shard_connection
21
- name = connection_pool_name
22
- spec = configurations[name]
23
-
24
- if spec.nil?
25
- raise ActiveRecord::AdapterNotSpecified, "No database defined by #{name} in database.yml"
26
- end
27
-
28
- # in 3.2 rails is asking for a connection pool in a map of these ConnectionSpecifications. If we want to re-use connections,
29
- # we need to re-use specs.
30
-
31
- # note that since we're subverting the standard establish_connection path, we have to handle the funky autoloading of the
32
- # connection adapter ourselves.
33
- if ActiveRecord::VERSION::MAJOR >= 4
34
- specification_cache[name] ||= begin
35
- resolver = ActiveRecordShards::ConnectionSpecification::Resolver.new configurations
36
- resolver.spec(spec)
37
- end
38
-
39
- connection_handler.establish_connection(self, specification_cache[name])
40
- else
41
- specification_cache[name] ||= begin
42
- resolver = ActiveRecordShards::ConnectionSpecification::Resolver.new spec, configurations
43
- resolver.spec
44
- end
45
-
46
- connection_handler.establish_connection(connection_pool_name, specification_cache[name])
47
- end
48
- end
49
-
50
- def specification_cache
51
- @@specification_cache ||= {}
52
- end
53
-
54
- def connection_pool_key
55
- specification_cache[connection_pool_name]
56
- end
57
-
58
- def connected_to_shard?
59
- if ActiveRecord::VERSION::MAJOR >= 4
60
- specs_to_pools = Hash[connection_handler.connection_pool_list.map { |pool| [pool.spec, pool] }]
61
- else
62
- specs_to_pools = connection_handler.connection_pools
63
- end
64
-
65
- specs_to_pools.key?(connection_pool_key)
66
- end
67
- end
68
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'active_record_shards/connection_pool'
3
- require 'active_record_shards/connection_handler'
4
- require 'active_record_shards/connection_specification'
5
-
6
-
7
- ActiveRecordShards::ConnectionSpecification = ActiveRecord::Base::ConnectionSpecification
8
- methods_to_override = [:remove_connection]
9
- ActiveRecordShards.override_connection_handler_methods(methods_to_override)
10
-
11
- ActiveRecord::Associations::Preloader::HasAndBelongsToMany.include(ActiveRecordShards::DefaultSlavePatches::HasAndBelongsToManyPreloaderPatches)
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
-
4
-
5
- require 'active_record_shards/schema_dumper_extension'
6
-
7
-
8
-
9
-
10
-
11
- ActiveRecord::Associations::Builder::HasAndBelongsToMany.include(ActiveRecordShards::DefaultSlavePatches::Rails41HasAndBelongsToManyBuilderExtension)
12
-
13
- ActiveRecord::SchemaDumper.prepend(ActiveRecordShards::SchemaDumperExtension)