Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/test_ruby_2_7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
strategy:
fail-fast: false
matrix:
arversion: ['5_0_0', '5_0_1', '5_0_2', '5_0_3', '5_0_4', '5_0_5', '5_0_6', '5_0_7',
'5_1_0', '5_1_1', '5_1_2', '5_1_3', '5_1_4', '5_1_5', '5_1_6', '5_1_7',
arversion: ['5_0_5', '5_0_6', '5_0_7',
'5_1_3', '5_1_4', '5_1_5', '5_1_6', '5_1_7',
'5_2_0', '5_2_1', '5_2_2', '5_2_3', '5_2_4', '5_2_5', '5_2_6', '5_2_7', '5_2_8',
'6_0_0', '6_0_1', '6_0_2', '6_0_3', '6_0_4', '6_0_5', '6_0_6']
'6_0_0', '6_0_1', '6_0_2', '6_0_3', '6_0_4', '6_0_5', '6_0_6',
'6_1_0', '6_1_1', '6_1_2', '6_1_3', '6_1_4', '6_1_5', '6_1_6', '6_1_7']
runs-on: ubuntu-22.04
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails${{ matrix.arversion }}.gemfile
Expand All @@ -22,7 +23,7 @@ jobs:
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'
bundler: ${{ contains(fromJSON('["5_0_0", "5_0_1", "5_0_2", "5_0_3", "5_0_4", "5_1_0", "5_1_1", "5_1_2"]'), matrix.arversion) && '1.17.3' || 'latest' }}
bundler: latest
bundler-cache: true
- name: Start mysql
run: sudo systemctl start mysql.service
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test_ruby_3_0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ jobs:
strategy:
fail-fast: false
matrix:
arversion: ['6_0_6']
arversion: ['6_0_6',
'6_1_0', '6_1_1', '6_1_2', '6_1_3', '6_1_4', '6_1_5', '6_1_6', '6_1_7']
runs-on: ubuntu-22.04
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails${{ matrix.arversion }}.gemfile
Expand Down
72 changes: 72 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,75 @@ appraise "rails6_0_6" do
gem "actionview", "~> 6.0.6.1"
gem "mysql2", "~> 0.5.2"
end

appraise "rails6_1_0" do
gem "rails", "~> 6.1.0.0"
gem "railties", "~> 6.1.0.0"
gem "activerecord", "~> 6.1.0.0"
gem "activesupport", "~> 6.1.0.0"
gem "actionview", "~> 6.1.0.0"
gem "mysql2", "~> 0.5.2"
end

appraise "rails6_1_1" do
gem "rails", "~> 6.1.1.0"
gem "railties", "~> 6.1.1.0"
gem "activerecord", "~> 6.1.1.0"
gem "activesupport", "~> 6.1.1.0"
gem "actionview", "~> 6.1.1.0"
gem "mysql2", "~> 0.5.2"
end

appraise "rails6_1_2" do
gem "rails", "~> 6.1.2.0"
gem "railties", "~> 6.1.2.0"
gem "activerecord", "~> 6.1.2.0"
gem "activesupport", "~> 6.1.2.0"
gem "actionview", "~> 6.1.2.0"
gem "mysql2", "~> 0.5.2"
end

appraise "rails6_1_3" do
gem "rails", "~> 6.1.3.0"
gem "railties", "~> 6.1.3.0"
gem "activerecord", "~> 6.1.3.0"
gem "activesupport", "~> 6.1.3.0"
gem "actionview", "~> 6.1.3.0"
gem "mysql2", "~> 0.5.2"
end

appraise "rails6_1_4" do
gem "rails", "~> 6.1.4.0"
gem "railties", "~> 6.1.4.0"
gem "activerecord", "~> 6.1.4.0"
gem "activesupport", "~> 6.1.4.0"
gem "actionview", "~> 6.1.4.0"
gem "mysql2", "~> 0.5.2"
end

appraise "rails6_1_5" do
gem "rails", "~> 6.1.5.0"
gem "railties", "~> 6.1.5.0"
gem "activerecord", "~> 6.1.5.0"
gem "activesupport", "~> 6.1.5.0"
gem "actionview", "~> 6.1.5.0"
gem "mysql2", "~> 0.5.2"
end

appraise "rails6_1_6" do
gem "rails", "~> 6.1.6.0"
gem "railties", "~> 6.1.6.0"
gem "activerecord", "~> 6.1.6.0"
gem "activesupport", "~> 6.1.6.0"
gem "actionview", "~> 6.1.6.0"
gem "mysql2", "~> 0.5.2"
end

appraise "rails6_1_7" do
gem "rails", "~> 6.1.7.0"
gem "railties", "~> 6.1.7.0"
gem "activerecord", "~> 6.1.7.0"
gem "activesupport", "~> 6.1.7.0"
gem "actionview", "~> 6.1.7.0"
gem "mysql2", "~> 0.5.2"
end
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ source "https://rubygems.org"

gemspec

gem "rails", "6.0.6.1"
gem "rails", "6.1.7.7"

gem "actionview", "6.0.6.1"
gem "activerecord", "6.0.6.1"
gem "activesupport", "6.0.6.1"
gem "actionview", "6.1.7.7"
gem "activerecord", "6.1.7.7"
gem "activesupport", "6.1.7.7"
5 changes: 3 additions & 2 deletions activerecord-turntable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "activesupport", ">= 5.0", "< 7.0"
spec.add_runtime_dependency "bsearch", "~> 1.5"
spec.add_runtime_dependency "sql_tree", "= 0.2.0"
spec.add_runtime_dependency "thread_safe"

# optional dependencies
spec.add_development_dependency "activerecord-import"
Expand All @@ -49,7 +50,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec-collection_matchers"
spec.add_development_dependency "rspec-its"
spec.add_development_dependency "rspec-parameterized"
spec.add_development_dependency "rspec-rails"
spec.add_development_dependency "rspec-rails", "~> 4.1.0"
spec.add_development_dependency "rubocop"
spec.add_development_dependency "rubocop-rspec"
spec.add_development_dependency "timecop"
Expand All @@ -60,6 +61,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bcrypt", "~> 3.1.11"
spec.add_development_dependency "minitest"
spec.add_development_dependency "mocha"
spec.add_development_dependency "sqlite3", "~> 1.3.6"
spec.add_development_dependency "sqlite3", ">= 1.4.2"
spec.add_development_dependency "appraisal", "~> 2.5.0"
end
12 changes: 12 additions & 0 deletions gemfiles/rails6_1_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.1.0.0"
gem "actionview", "~> 6.1.0.0"
gem "activerecord", "~> 6.1.0.0"
gem "activesupport", "~> 6.1.0.0"
gem "railties", "~> 6.1.0.0"
gem "mysql2", "~> 0.5.2"

gemspec path: "../"
12 changes: 12 additions & 0 deletions gemfiles/rails6_1_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.1.1.0"
gem "actionview", "~> 6.1.1.0"
gem "activerecord", "~> 6.1.1.0"
gem "activesupport", "~> 6.1.1.0"
gem "railties", "~> 6.1.1.0"
gem "mysql2", "~> 0.5.2"

gemspec path: "../"
12 changes: 12 additions & 0 deletions gemfiles/rails6_1_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.1.2.0"
gem "actionview", "~> 6.1.2.0"
gem "activerecord", "~> 6.1.2.0"
gem "activesupport", "~> 6.1.2.0"
gem "railties", "~> 6.1.2.0"
gem "mysql2", "~> 0.5.2"

gemspec path: "../"
12 changes: 12 additions & 0 deletions gemfiles/rails6_1_3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.1.3.0"
gem "actionview", "~> 6.1.3.0"
gem "activerecord", "~> 6.1.3.0"
gem "activesupport", "~> 6.1.3.0"
gem "railties", "~> 6.1.3.0"
gem "mysql2", "~> 0.5.2"

gemspec path: "../"
12 changes: 12 additions & 0 deletions gemfiles/rails6_1_4.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.1.4.0"
gem "actionview", "~> 6.1.4.0"
gem "activerecord", "~> 6.1.4.0"
gem "activesupport", "~> 6.1.4.0"
gem "railties", "~> 6.1.4.0"
gem "mysql2", "~> 0.5.2"

gemspec path: "../"
12 changes: 12 additions & 0 deletions gemfiles/rails6_1_5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.1.5.0"
gem "actionview", "~> 6.1.5.0"
gem "activerecord", "~> 6.1.5.0"
gem "activesupport", "~> 6.1.5.0"
gem "railties", "~> 6.1.5.0"
gem "mysql2", "~> 0.5.2"

gemspec path: "../"
12 changes: 12 additions & 0 deletions gemfiles/rails6_1_6.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.1.6.0"
gem "actionview", "~> 6.1.6.0"
gem "activerecord", "~> 6.1.6.0"
gem "activesupport", "~> 6.1.6.0"
gem "railties", "~> 6.1.6.0"
gem "mysql2", "~> 0.5.2"

gemspec path: "../"
12 changes: 12 additions & 0 deletions gemfiles/rails6_1_7.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.1.7.0"
gem "actionview", "~> 6.1.7.0"
gem "activerecord", "~> 6.1.7.0"
gem "activesupport", "~> 6.1.7.0"
gem "railties", "~> 6.1.7.0"
gem "mysql2", "~> 0.5.2"

gemspec path: "../"
1 change: 1 addition & 0 deletions lib/active_record/turntable/active_record_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module ActiveRecordExt
ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(ConnectionHandlerExtension)
ActiveRecord::Associations::Preloader::Association.prepend(AssociationPreloader)
ActiveRecord::Associations::Association.prepend(Association)
ActiveRecord::Associations::Builder::Association.singleton_class.prepend(Builder::Association)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

ActiveRecord::QueryCache.prepend(QueryCache)
require "active_record/turntable/active_record_ext/fixtures"
require "active_record/turntable/active_record_ext/migration_proxy"
Expand Down
12 changes: 8 additions & 4 deletions lib/active_record/turntable/active_record_ext/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

module ActiveRecord::Turntable
module ActiveRecordExt
module Builder
module Association
def valid_options(options)
super + [:foreign_shard_key]
end
end
end

module Association
include ShardingCondition

def self.prepended(mod)
ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :foreign_shard_key
end

protected

# @note Override to pass shard key conditions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ def owner_to_turntable_pool
@owner_to_turntable_pool ||= Concurrent::Map.new(initial_capacity: 2)
end

# @note Override not to establish_connection destroy existing connection pool proxy object
def retrieve_connection_pool(spec_name)
owner_to_turntable_pool.fetch(spec_name) do
super
if Util.ar_version_equals_or_later?("6.1.0")
def retrieve_connection_pool(spec_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard)
owner_to_turntable_pool.fetch(spec_name) do
super
end
end
else
# @note Override not to establish_connection destroy existing connection pool proxy object
def retrieve_connection_pool(spec_name)
owner_to_turntable_pool.fetch(spec_name) do
super
end
end
end
end
Expand Down
15 changes: 13 additions & 2 deletions lib/active_record/turntable/active_record_ext/database_tasks.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "active_record/tasks/database_tasks"
require "active_record/turntable/util"

module ActiveRecord
module Tasks
Expand Down Expand Up @@ -45,7 +46,12 @@ def each_current_turntable_cluster_connected(environment)
yield(name, configuration)
end
ActiveRecord::Base.clear_active_connections!
ActiveRecord::Base.establish_connection old_connection_pool.spec.config
config = if old_connection_pool.respond_to?(:db_config)
old_connection_pool.db_config.configuration_hash
else
old_connection_pool.spec.config
end
ActiveRecord::Base.establish_connection config
end

def each_current_turntable_cluster_configuration(environment)
Expand Down Expand Up @@ -74,7 +80,12 @@ def each_local_turntable_cluster_configuration
def current_turntable_cluster_configurations(*environments)
configurations = []
environments.each do |environ|
config = ActiveRecord::Base.configurations[environ]
config = if ActiveRecord::Turntable::Util.ar61_or_later?
configs = ActiveRecord::Base.configurations.configs_for(env_name: environ.to_s).map(&:configuration_hash)
configs&.find { |conf| conf.key?("shards") || conf.key?(:shards) }&.stringify_keys
else
ActiveRecord::Base.configurations[environ]
end
next unless config
%w(shards seq).each do |name|
configurations += config[name].to_a if config.has_key?(name)
Expand Down
9 changes: 2 additions & 7 deletions lib/active_record/turntable/active_record_ext/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,11 @@ def setup_fixtures(config = ActiveRecord::Base)
@fixture_connections = []
@@already_loaded_fixtures ||= {}
@connection_subscriber = nil
@legacy_saved_pool_configs = Hash.new { |hash, key| hash[key] = {} }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legacyって何に使うっけ

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この辺りは ActiveRecord::TestFixtures で定義されてるやつを真似しただけ
rails/rails#40384

@saved_pool_configs = Hash.new { |hash, key| hash[key] = {} }

# Load fixtures once and begin transaction.
if run_in_transaction?

# # Support AciveRecrd version 6.0.4
# # https://github.com/rails/rails/blame/v6.0.4/activerecord/lib/active_record/test_fixtures.rb#L115
if ActiveRecord::Turntable::Util.ar_version_equals_or_later?("6.0.4")
@saved_pool_configs = Hash.new { |hash, key| hash[key] = {} }
end

if @@already_loaded_fixtures[self.class]
@loaded_fixtures = @@already_loaded_fixtures[self.class]
else
Expand Down
Loading