Skip to content
Merged
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
6 changes: 0 additions & 6 deletions .github/gemfiles/rails_7.1.gemfile

This file was deleted.

6 changes: 6 additions & 0 deletions .github/gemfiles/rails_8.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

gemspec :path => '../../'

gem 'activerecord', '~> 8.1.0'
gem 'activesupport', '~> 8.1.0'
4 changes: 2 additions & 2 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
strategy:
fail-fast: true
matrix:
ruby: ["3.2","3.3", "3.4"]
rails: ["7.1", "7.2", "8.0"]
ruby: ["3.2", "3.3", "3.4"]
rails: ["7.2", "8.0", "8.1"]
env:
BUNDLE_GEMFILE: .github/gemfiles/rails_${{ matrix.rails }}.gemfile
MYSQL_HOST: 127.0.0.1
Expand Down
6 changes: 1 addition & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ namespace :db do
require './spec/models/application_record'
ActiveRecord::Base.configurations.configs_for(env_name: "test").each do |config|
ActiveRecord::Base.establish_connection(config)
schema_migration = if ActiveRecord.gem_version >= Gem::Version.new(7.2)
ActiveRecord::Base.connection.pool.schema_migration
else
ActiveRecord::Base.connection.schema_migration
end
schema_migration = ActiveRecord::Base.connection.pool.schema_migration
ActiveRecord::MigrationContext.new("spec/migration", schema_migration)
.migrate(config.database == 'octoball_shard_5' ? 2 : 1)
end
Expand Down
1 change: 0 additions & 1 deletion lib/octoball.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
ActiveSupport.on_load(:active_record) do
require 'octoball/relation_proxy'
require 'octoball/connection_adapters'
require 'octoball/connection_handling'
require 'octoball/current_shard_tracker'
require 'octoball/association_shard_check'
require 'octoball/persistence'
Expand Down
51 changes: 24 additions & 27 deletions lib/octoball/connection_adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,38 @@ module ConnectionHasCurrentShard
attr_accessor :current_shard
end

if ActiveRecord.gem_version >= Gem::Version.new('7.2.0')
module ConnectionPoolSetCurrentShard
def with_connection(prevent_permanent_checkout: false)
lease = connection_lease
if lease.connection
lease.connection.current_shard = lease.connection.shard
end

super
module ConnectionPoolSetCurrentShard
def with_connection(prevent_permanent_checkout: false)
lease = connection_lease
if lease.connection
lease.connection.current_shard = lease.connection.shard
end

def active_connection?
conn = connection_lease.connection
conn.current_shard = conn.shard if conn
conn
end
super
end

def active_connection
conn = connection_lease.connection
conn.current_shard = conn.shard if conn
conn
end
def active_connection?
conn = connection_lease.connection
conn.current_shard = conn.shard if conn
conn
end

def lease_connection
lease = connection_lease
lease.sticky = true
lease.connection ||= checkout
lease.connection.current_shard = lease.connection.shard
lease.connection
end
def active_connection
conn = connection_lease.connection
conn.current_shard = conn.shard if conn
conn
end

::ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(ConnectionPoolSetCurrentShard)
def lease_connection
lease = connection_lease
lease.sticky = true
lease.connection ||= checkout
lease.connection.current_shard = lease.connection.shard
lease.connection
end
end

::ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(ConnectionPoolSetCurrentShard)
::ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(ConnectionHandlerSetCurrentShard)
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ConnectionHasCurrentShard)
end
20 changes: 0 additions & 20 deletions lib/octoball/connection_handling.rb

This file was deleted.

6 changes: 1 addition & 5 deletions lib/octoball/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ def sql(event)
private

def debug(progname = nil, &block)
if ActiveRecord.gem_version >= Gem::Version.new('7.1.0')
conn = current_shard ? color("[Shard: #{current_shard}]", ActiveSupport::LogSubscriber::GREEN, bold: true) : ''
else
conn = current_shard ? color("[Shard: #{current_shard}]", ActiveSupport::LogSubscriber::GREEN, true) : ''
end
conn = current_shard ? color("[Shard: #{current_shard}]", ActiveSupport::LogSubscriber::GREEN, bold: true) : ''
super(conn + progname.to_s, &block)
end
end
Expand Down
4 changes: 2 additions & 2 deletions octoball.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Gem::Specification.new do |s|

s.required_ruby_version = '>= 3.2.0'

s.add_dependency 'activerecord', '>= 7.0'
s.add_dependency 'activesupport', '>= 7.0'
s.add_dependency 'activerecord', '>= 7.2'
s.add_dependency 'activesupport', '>= 7.2'

s.add_development_dependency 'trilogy'
s.add_development_dependency 'rake'
Expand Down