active_record_shards 3.20.0 → 3.22.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: faa823b7357f66f7de85bb3ab50b6df99beb0c2505bcbbeafac9cc1aa4581d7e
4
- data.tar.gz: 688c6ed703809a88ee86134d43021730495bcaaa8ca2132c81a0926edc2d1eca
3
+ metadata.gz: 23d9e5008110efdba7c5d366557f94ec83bbba4c655157ae6b071494fc745097
4
+ data.tar.gz: 30bd423589d89b1d268fade3127321c7a42f157571c2bf07e31137e4b96e8316
5
5
  SHA512:
6
- metadata.gz: 8e9babc77b5dffe78007005f7abec607a9e5597aafa3676082c501da68c9cce9748714db5068bdc6b7573edef1ed8ad608893820c5396fbc450fa59b5c34f9f2
7
- data.tar.gz: 72dcbaa612143fe7a3235f23982b83b4fddb86a7c39814dec128d7fc6f4a141b368de82392e2f515424055b148d11181fc3fd27e608f174879735c30d1d13ce4
6
+ metadata.gz: 9454ca6c66e3a1c4073d18b81a550c1fa9f29243198f98645d711c01db8d09dec1cbbcb6228fe0e5f1f3971fc26b040624de97c2d6f7c3d97dd7011f6a622cff
7
+ data.tar.gz: 0ad014733e6f2728303618a0845b626ff181b6768fc41bcc87ec9b31a52e919ec3c6874b755e69073b9c933af2a0a0c42b3e00a6ec8a4fe135f94a0a71b2f0aa
data/README.md CHANGED
@@ -148,12 +148,16 @@ ActiveRecord::Base.on_replica do
148
148
  end
149
149
  ```
150
150
 
151
- This will perform the query on the replica, and mark the returned instances as read only. There is also a shortcut for this:
151
+ This will perform the query on the replica, and mark the returned instances as read-only. There is also a shortcut for this:
152
152
 
153
153
  ```ruby
154
154
  Account.on_replica.find_by_big_expensive_query
155
155
  ```
156
156
 
157
+ If you do not want instances returned from replicas to be marked as read-only, this can be disabled globally:
158
+
159
+ `ActiveRecordShards.disable_replica_readonly_records = true`
160
+
157
161
  ## Debugging
158
162
 
159
163
  Show if a query went to primary or replica in the logs:
@@ -17,6 +17,9 @@ module ActiveRecordShards
17
17
 
18
18
  base.singleton_class.send(:alias_method, :table_exists_without_default_shard?, :table_exists?)
19
19
  base.singleton_class.send(:alias_method, :table_exists?, :table_exists_with_default_shard?)
20
+
21
+ base.singleton_class.send(:alias_method, :reset_primary_key_without_default_shard, :reset_primary_key)
22
+ base.singleton_class.send(:alias_method, :reset_primary_key, :reset_primary_key_with_default_shard)
20
23
  end
21
24
 
22
25
  def default_shard=(new_default_shard)
@@ -125,7 +128,7 @@ module ActiveRecordShards
125
128
 
126
129
  # we avoid_readonly_scope to prevent some stack overflow problems, like when
127
130
  # .columns calls .with_scope which calls .columns and onward, endlessly.
128
- if self == ActiveRecord::Base || !switch_to_replica || construct_ro_scope == false
131
+ if self == ActiveRecord::Base || !switch_to_replica || construct_ro_scope == false || ActiveRecordShards.disable_replica_readonly_records == true
129
132
  yield
130
133
  else
131
134
  readonly.scoping(&block)
@@ -160,6 +163,10 @@ module ActiveRecordShards
160
163
  config_for_env[SHARD_NAMES_CONFIG_KEY] || []
161
164
  end
162
165
 
166
+ def reset_primary_key_with_default_shard
167
+ with_default_shard { reset_primary_key_without_default_shard }
168
+ end
169
+
163
170
  private
164
171
 
165
172
  def config_for_env
@@ -12,6 +12,10 @@ require 'active_record_shards/default_replica_patches'
12
12
  require 'active_record_shards/schema_dumper_extension'
13
13
 
14
14
  module ActiveRecordShards
15
+ class << self
16
+ attr_accessor :disable_replica_readonly_records
17
+ end
18
+
15
19
  def self.app_env
16
20
  env = Rails.env if defined?(Rails.env)
17
21
  env ||= RAILS_ENV if Object.const_defined?(:RAILS_ENV)
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.20.0
4
+ version: 3.22.0
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: 2022-04-23 00:00:00.000000000 Z
16
+ date: 2023-08-28 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activerecord
@@ -83,20 +83,6 @@ dependencies:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
85
  version: 5.10.0
86
- - !ruby/object:Gem::Dependency
87
- name: minitest-rg
88
- requirement: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: '0'
93
- type: :development
94
- prerelease: false
95
- version_requirements: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: '0'
100
86
  - !ruby/object:Gem::Dependency
101
87
  name: mocha
102
88
  requirement: !ruby/object:Gem::Requirement
@@ -218,7 +204,7 @@ homepage: https://github.com/zendesk/active_record_shards
218
204
  licenses:
219
205
  - MIT
220
206
  metadata: {}
221
- post_install_message:
207
+ post_install_message:
222
208
  rdoc_options: []
223
209
  require_paths:
224
210
  - lib
@@ -233,8 +219,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
219
  - !ruby/object:Gem::Version
234
220
  version: '0'
235
221
  requirements: []
236
- rubygems_version: 3.3.1
237
- signing_key:
222
+ rubygems_version: 3.0.3.1
223
+ signing_key:
238
224
  specification_version: 4
239
225
  summary: Simple database switching for ActiveRecord.
240
226
  test_files: []