active_record_shards 3.16.0 → 3.19.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'active_record_shards'
3
4
 
4
5
  %w[db:drop db:create db:abort_if_pending_migrations db:reset db:test:purge].each do |name|
@@ -9,14 +10,15 @@ namespace :db do
9
10
  desc 'Drops the database for the current RAILS_ENV including shards'
10
11
  task drop: :load_config do
11
12
  ActiveRecord::Base.configurations.to_h.each do |key, conf|
12
- next if !key.starts_with?(ActiveRecordShards.rails_env) || key.ends_with?("_slave")
13
+ next if !key.start_with?(ActiveRecordShards.rails_env) || key.end_with?("_replica", "_slave")
14
+
13
15
  begin
14
16
  ActiveRecordShards::Tasks.root_connection(conf).drop_database(conf['database'])
15
17
  # rescue ActiveRecord::NoDatabaseError # TODO: exists in AR but never is raised here ...
16
18
  # $stderr.puts "Database '#{conf['database']}' does not exist"
17
- rescue StandardError => error
18
- $stderr.puts error, *error.backtrace
19
- $stderr.puts "Couldn't drop #{conf['database']}"
19
+ rescue StandardError => e
20
+ warn e, *e.backtrace
21
+ warn "Couldn't drop #{conf['database']}"
20
22
  end
21
23
  end
22
24
  end
@@ -29,7 +31,8 @@ namespace :db do
29
31
  desc "Create the database defined in config/database.yml for the current RAILS_ENV including shards"
30
32
  task create: :load_config do
31
33
  ActiveRecord::Base.configurations.to_h.each do |key, conf|
32
- next if !key.starts_with?(ActiveRecordShards.rails_env) || key.ends_with?("_slave")
34
+ next if !key.start_with?(ActiveRecordShards.rails_env) || key.end_with?("_replica", "_slave")
35
+
33
36
  begin
34
37
  # MysqlAdapter takes charset instead of encoding in Rails 4.2 or greater
35
38
  # https://github.com/rails/rails/blob/4-2-stable/activerecord/lib/active_record/tasks/mysql_database_tasks.rb#L85-L96
@@ -37,11 +40,11 @@ namespace :db do
37
40
  symbolized_configuration[:charset] = symbolized_configuration[:encoding]
38
41
 
39
42
  ActiveRecordShards::Tasks.root_connection(conf).create_database(conf['database'], symbolized_configuration)
40
- rescue ActiveRecord::StatementInvalid => ex
41
- if ex.message.include?('database exists')
43
+ rescue ActiveRecord::StatementInvalid => e
44
+ if e.message.include?('database exists')
42
45
  puts "#{conf['database']} already exists"
43
46
  else
44
- raise ex
47
+ raise e
45
48
  end
46
49
  end
47
50
  end
@@ -63,9 +66,9 @@ namespace :db do
63
66
  end
64
67
 
65
68
  if pending_migrations.any?
66
- $stderr.puts "You have #{pending_migrations.size} pending migrations:"
69
+ warn "You have #{pending_migrations.size} pending migrations:"
67
70
  pending_migrations.each do |pending_migration|
68
- $stderr.puts ' %4d %s' % [pending_migration.version, pending_migration.name]
71
+ warn ' %4d %s' % [pending_migration.version, pending_migration.name]
69
72
  end
70
73
  abort %(Run "rake db:migrate" to update your database then try again.)
71
74
  end
@@ -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,7 @@ 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'
11
12
  require 'active_record_shards/schema_dumper_extension'
12
13
 
13
14
  module ActiveRecordShards
@@ -22,17 +23,119 @@ end
22
23
  ActiveRecord::Base.extend(ActiveRecordShards::ConfigurationParser)
23
24
  ActiveRecord::Base.extend(ActiveRecordShards::Model)
24
25
  ActiveRecord::Base.extend(ActiveRecordShards::ConnectionSwitcher)
25
- ActiveRecord::Base.extend(ActiveRecordShards::DefaultSlavePatches)
26
- ActiveRecord::Relation.include(ActiveRecordShards::DefaultSlavePatches::ActiveRelationPatches)
26
+ ActiveRecord::Base.extend(ActiveRecordShards::DefaultReplicaPatches)
27
+ ActiveRecord::Relation.include(ActiveRecordShards::DefaultReplicaPatches::ActiveRelationPatches)
27
28
  ActiveRecord::Associations::CollectionProxy.include(ActiveRecordShards::AssociationCollectionConnectionSelection)
28
- ActiveRecord::Associations::Builder::HasAndBelongsToMany.include(ActiveRecordShards::DefaultSlavePatches::Rails41HasAndBelongsToManyBuilderExtension)
29
+ ActiveRecord::Associations::Builder::HasAndBelongsToMany.include(ActiveRecordShards::DefaultReplicaPatches::Rails41HasAndBelongsToManyBuilderExtension)
29
30
  ActiveRecord::SchemaDumper.prepend(ActiveRecordShards::SchemaDumperExtension)
30
31
 
31
32
  case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
32
33
  when '4.2'
33
34
  require 'active_record_shards/patches-4-2'
34
- when '5.0', '5.1', '5.2', '6.0'
35
- :ok
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)
36
97
  else
37
98
  raise "ActiveRecordShards is not compatible with #{ActiveRecord::VERSION::STRING}"
38
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_shards
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.16.0
4
+ version: 3.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Quorning
@@ -10,10 +10,10 @@ authors:
10
10
  - Mick Staugaard
11
11
  - Eric Chapweske
12
12
  - Ben Osheroff
13
- autorequire:
13
+ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2019-12-10 00:00:00.000000000 Z
16
+ date: 2021-09-23 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activerecord
@@ -56,35 +56,35 @@ dependencies:
56
56
  - !ruby/object:Gem::Version
57
57
  version: '6.1'
58
58
  - !ruby/object:Gem::Dependency
59
- name: rake
59
+ name: bump
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - "~>"
62
+ - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: '12.0'
64
+ version: '0'
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - "~>"
69
+ - - ">="
70
70
  - !ruby/object:Gem::Version
71
- version: '12.0'
71
+ version: '0'
72
72
  - !ruby/object:Gem::Dependency
73
- name: mysql2
73
+ name: minitest
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: '0'
78
+ version: 5.10.0
79
79
  type: :development
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: '0'
85
+ version: 5.10.0
86
86
  - !ruby/object:Gem::Dependency
87
- name: bump
87
+ name: minitest-rg
88
88
  requirement: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="
@@ -98,76 +98,90 @@ dependencies:
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  - !ruby/object:Gem::Dependency
101
- name: rubocop
101
+ name: mocha
102
102
  requirement: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - '='
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: 0.50.0
106
+ version: 1.4.0
107
107
  type: :development
108
108
  prerelease: false
109
109
  version_requirements: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - '='
111
+ - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: 0.50.0
113
+ version: 1.4.0
114
114
  - !ruby/object:Gem::Dependency
115
- name: minitest
115
+ name: mysql2
116
116
  requirement: !ruby/object:Gem::Requirement
117
117
  requirements:
118
118
  - - ">="
119
119
  - !ruby/object:Gem::Version
120
- version: 5.10.0
120
+ version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
123
  version_requirements: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
- version: 5.10.0
127
+ version: '0'
128
128
  - !ruby/object:Gem::Dependency
129
- name: minitest-rg
129
+ name: rake
130
130
  requirement: !ruby/object:Gem::Requirement
131
131
  requirements:
132
- - - ">="
132
+ - - "~>"
133
133
  - !ruby/object:Gem::Version
134
- version: '0'
134
+ version: '12.0'
135
135
  type: :development
136
136
  prerelease: false
137
137
  version_requirements: !ruby/object:Gem::Requirement
138
138
  requirements:
139
- - - ">="
139
+ - - "~>"
140
140
  - !ruby/object:Gem::Version
141
- version: '0'
141
+ version: '12.0'
142
142
  - !ruby/object:Gem::Dependency
143
- name: mocha
143
+ name: rubocop
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  requirements:
146
- - - ">="
146
+ - - "~>"
147
147
  - !ruby/object:Gem::Version
148
- version: 1.4.0
148
+ version: 0.77.0
149
149
  type: :development
150
150
  prerelease: false
151
151
  version_requirements: !ruby/object:Gem::Requirement
152
152
  requirements:
153
- - - ">="
153
+ - - "~>"
154
154
  - !ruby/object:Gem::Version
155
- version: 1.4.0
155
+ version: 0.77.0
156
156
  - !ruby/object:Gem::Dependency
157
- name: phenix
157
+ name: rubocop-minitest
158
158
  requirement: !ruby/object:Gem::Requirement
159
159
  requirements:
160
- - - ">="
160
+ - - "~>"
161
161
  - !ruby/object:Gem::Version
162
- version: 0.6.0
162
+ version: 0.5.0
163
163
  type: :development
164
164
  prerelease: false
165
165
  version_requirements: !ruby/object:Gem::Requirement
166
166
  requirements:
167
- - - ">="
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: 0.5.0
170
+ - !ruby/object:Gem::Dependency
171
+ name: rubocop-performance
172
+ requirement: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - "~>"
175
+ - !ruby/object:Gem::Version
176
+ version: 1.5.1
177
+ type: :development
178
+ prerelease: false
179
+ version_requirements: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - "~>"
168
182
  - !ruby/object:Gem::Version
169
- version: 0.6.0
170
- description: Easily run queries on shard and slave databases.
183
+ version: 1.5.1
184
+ description: Easily run queries on shard and replica databases.
171
185
  email:
172
186
  - bquorning@zendesk.com
173
187
  - gabe@zendesk.com
@@ -188,7 +202,9 @@ files:
188
202
  - lib/active_record_shards/connection_switcher-5-0.rb
189
203
  - lib/active_record_shards/connection_switcher-5-1.rb
190
204
  - lib/active_record_shards/connection_switcher.rb
205
+ - lib/active_record_shards/default_replica_patches.rb
191
206
  - lib/active_record_shards/default_slave_patches.rb
207
+ - lib/active_record_shards/deprecation.rb
192
208
  - lib/active_record_shards/migration.rb
193
209
  - lib/active_record_shards/model.rb
194
210
  - lib/active_record_shards/patches-4-2.rb
@@ -201,7 +217,7 @@ homepage: https://github.com/zendesk/active_record_shards
201
217
  licenses:
202
218
  - MIT
203
219
  metadata: {}
204
- post_install_message:
220
+ post_install_message:
205
221
  rdoc_options: []
206
222
  require_paths:
207
223
  - lib
@@ -216,8 +232,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
232
  - !ruby/object:Gem::Version
217
233
  version: '0'
218
234
  requirements: []
219
- rubygems_version: 3.0.3
220
- signing_key:
235
+ rubygems_version: 3.2.16
236
+ signing_key:
221
237
  specification_version: 4
222
238
  summary: Simple database switching for ActiveRecord.
223
239
  test_files: []