All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning (from 3.17.0 onwards)
- Fixed
SqlComments
when using Rails 7.0.
- Use the default shard when resetting primary key
- Changes all fiber-local variables to thread-local variables. Fixes any lingering issues where a fiber change could cause the state to be lost.
- Now raises an error in Rails 7.0 when attempting to use ARS when
ActiveSupport::IsolatedExecutionState.isolation_level
is not set to:thread
-
Stays on the correct database, even when using a new Fiber. Some Ruby methods, such as
to_enum
create a new Fiber for the block.to_enum
is used by ActiveRecord when finding things in batches. This should resolve issues where ARS would connect to the unsharded database, even inside anon_shard
block. The downside is we are now violating fiber concurrency and thus this breaks multi-fiber webservers. -
Fixes an issue where ARS switches to the replica database in the middle of a transaction when it is supposed to remain on the Primary.
- Added new 'ActiveRecordShards.reset_rails_env!' method to clear the cache within a process (#315).
- Run tests against Ruby 3.2 (the gem actually already worked with Ruby 3.2, but now we promise that it does) (#309).
- Cache the results of
is_sharded?
andapp_env
, and ensure that the configuration is only validated once inshard_names
. This should be a small performance improvement (#311, #312).
Raises a new LegacyConnectionHandlingError
exception when using ActiveRecord >= 6.1 and legacy_connection_handling
is set to false
.
Make connection switching thread safe, by fixing a thread safety issue caused by using a (class) instance variable instead of a thread-local variable.
Support for Rails 7.0 when legacy_connection_handling
is set to true
. This is required to opt-out of the native Rails 6.1+ sharding support.
Rails 6.1 deprecation warnings.
Support for Rails 6.1 when legacy_connection_handling
is set to true
. This is required to opt-out of the native Rails 6.1 sharding support.
Rename ActiveRecordShards.rails_env
to ActiveRecordShards.app_env
, and include APP_ENV
and ENV['APP_ENV']
in the list of places it looks for environment information.
Removed support for Ruby 2.3, 2.4, and 2.5.
Removed support for Rails 4.2 and 5.0.
[Deprecation] Removes all deprecated methods containing master
/slave
. Use the updated primary
/replica
methods instead. The main public methods changed:
on_slave
=>on_replica
on_master
=>on_primary
other methods changed:
on_master_if
=>on_primary_if
on_slave_if
=>on_replica_if
on_master_unless
=>on_primary_unless
on_slave_unless
=>on_replica_unless
on_master_or_slave
=>on_primary_or_replica
exists_with_default_slave
=>exists_with_default_replica
from_slave
=>from_replica
initialize_shard_and_slave
=>initialize_shard_and_replica
ShardSelection#options
no longer uses:slave
, if this method was overridden ensure it returns:replica
instead of:slave
:{ shard: .., replica: ... }
Also removes the class ActiveRecordShards::Deprecation
.
Add a global setting to disable marking instances from replicas as read-only. To enable:
ActiveRecordShards.disable_replica_readonly_records = true
Converts the ActiveRecord::Base.configurations
object introduced in Rails 6 into a hash as expected.
Lots of improvements to the on_replica_by_default
logic, now covered by an improved test suite. Schema loading should now always happen on the replica databases, and non-mutating queries will should now happen on the replica except when on_replica_by_default
is not configured.
Adds deprecation warning for all methods containing master
/slave
which recommends using the updated primary
/replica
methods. The main public methods changed:
on_slave
=>on_replica
on_master
=>on_primary
other methods changed:
on_master_if
=>on_primary_if
on_slave_if
=>on_replica_if
on_master_unless
=>on_primary_unless
on_slave_unless
=>on_replica_unless
on_master_or_slave
=>on_primary_or_replica
exists_with_default_slave
=>exists_with_default_replica
from_slave
=>from_replica
initialize_shard_and_slave
=>initialize_shard_and_replica
ShardSelection#options
no longer uses:slave
, if this method was overridden ensure it returns:replica
instead of:slave
:{ shard: .., replica: ... }
SQL comments (see debugging) will now log ... /* replica */
instead of ... /* slave */