Skip to content

Commit

Permalink
Merge pull request #13 from aktsk/support-rails72
Browse files Browse the repository at this point in the history
Support rails 7.2 and Drop EOL versions(ruby 2.7, 3.0 and rails 6.1)
  • Loading branch information
fumihumi authored Oct 10, 2024
2 parents 016bdc8 + 0aee586 commit 6791444
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
5 changes: 0 additions & 5 deletions .github/Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
source 'https://rubygems.org'

if RUBY_VERSION < '3.0'
gem 'activerecord', '~> 7.1.1'
gem 'activesupport', '~> 7.1.1'
end

gemspec :path => '../'
4 changes: 2 additions & 2 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
strategy:
fail-fast: true
matrix:
ruby: ["2.7","3.0","3.1","3.2"]
ruby: ["3.1","3.2","3.3"]
env:
BUNDLE_GEMFILE: .github/Gemfile
MYSQL_HOST: 127.0.0.1
RAILS_ENV: test
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ 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 = ActiveRecord::Base.connection.schema_migration
schema_migration = if ActiveRecord.gem_version >= Gem::Version.new(7.2)
ActiveRecord::Base.connection.pool.schema_migration
else
ActiveRecord::Base.connection.schema_migration
end
ActiveRecord::MigrationContext.new("spec/migration", schema_migration)
.migrate(config.database == 'octoball_shard_5' ? 2 : 1)
end
Expand Down
35 changes: 35 additions & 0 deletions lib/octoball/connection_adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,41 @@ 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
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
end

::ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(ConnectionPoolSetCurrentShard)
end

::ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(ConnectionHandlerSetCurrentShard)
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ConnectionHasCurrentShard)
end
8 changes: 4 additions & 4 deletions octoball.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Gem::Specification.new do |s|
s.homepage = 'https://github.com/aktsk/octoball'
s.require_paths = ['lib']

s.required_ruby_version = '>= 2.7.0'
s.required_ruby_version = '>= 3.1.0'

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

s.add_development_dependency 'mysql2'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '>= 3'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'byebug'
s.add_development_dependency 'debug'
end

0 comments on commit 6791444

Please sign in to comment.