From 9ea15cae937998f6f652afdec3b02bd288785ab0 Mon Sep 17 00:00:00 2001 From: Ryan Krage Date: Mon, 25 Nov 2024 21:43:06 +0000 Subject: [PATCH] Add support for Rails 8.0 --- .github/workflows/ci.yml | 2 +- Appraisals | 5 +++++ Gemfile | 1 - gemfiles/rails_8.0.gemfile | 8 ++++++++ lib/pg_ha_migrations/allowed_versions.rb | 2 +- pg_ha_migrations.gemspec | 2 +- spec/safe_statements_spec.rb | 15 +++++++++++++-- 7 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 gemfiles/rails_8.0.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bbfaae..2edc7bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,13 +10,13 @@ jobs: - 15 - 16 ruby: - - "3.1" - "3.2" - "3.3" gemfile: - rails_7.0 - rails_7.1 - rails_7.2 + - rails_8.0 name: PostgreSQL ${{ matrix.pg }} - Ruby ${{ matrix.ruby }} - ${{ matrix.gemfile }} runs-on: ubuntu-latest env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps diff --git a/Appraisals b/Appraisals index 25e827e..71fe666 100644 --- a/Appraisals +++ b/Appraisals @@ -9,3 +9,8 @@ end appraise "rails-7.2" do gem "rails", "7.2.2" end + +appraise "rails-8.0" do + gem "rails", "8.0.0" + gem "relation_to_struct", github: "rkrage/relation_to_struct", branch: "rails-8" +end diff --git a/Gemfile b/Gemfile index 003d427..84e90a8 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,3 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in pg_ha_migrations.gemspec gemspec - diff --git a/gemfiles/rails_8.0.gemfile b/gemfiles/rails_8.0.gemfile new file mode 100644 index 0000000..cdf533b --- /dev/null +++ b/gemfiles/rails_8.0.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "8.0.0" +gem "relation_to_struct", branch: "rails-8", git: "https://github.com/rkrage/relation_to_struct" + +gemspec path: "../" diff --git a/lib/pg_ha_migrations/allowed_versions.rb b/lib/pg_ha_migrations/allowed_versions.rb index 06f194e..0e0cf17 100644 --- a/lib/pg_ha_migrations/allowed_versions.rb +++ b/lib/pg_ha_migrations/allowed_versions.rb @@ -1,7 +1,7 @@ require "active_record/migration/compatibility" module PgHaMigrations::AllowedVersions - ALLOWED_VERSIONS = [4.2, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.1, 7.2].map do |v| + ALLOWED_VERSIONS = [4.2, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.1, 7.2, 8.0].map do |v| begin ActiveRecord::Migration[v] rescue ArgumentError diff --git a/pg_ha_migrations.gemspec b/pg_ha_migrations.gemspec index 07f5ef6..540b69e 100644 --- a/pg_ha_migrations.gemspec +++ b/pg_ha_migrations.gemspec @@ -37,7 +37,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "pry-byebug" spec.add_development_dependency "appraisal", "~> 2.5" - spec.add_dependency "rails", ">= 7.0", "< 7.3" + spec.add_dependency "rails", ">= 7.0", "< 8.1" spec.add_dependency "relation_to_struct", ">= 1.5.1" spec.add_dependency "ruby2_keywords" end diff --git a/spec/safe_statements_spec.rb b/spec/safe_statements_spec.rb index 172fca7..2fc35e0 100644 --- a/spec/safe_statements_spec.rb +++ b/spec/safe_statements_spec.rb @@ -2708,7 +2708,13 @@ def up it "doesn't acquire a lock which prevents concurrent reads and writes" do alternate_connection_pool = ActiveRecord::ConnectionAdapters::ConnectionPool.new(pool_config) - alternate_connection = alternate_connection_pool.connection + + # The #connection method was deprecated in Rails 7.2 in favor of #lease_connection + alternate_connection = if alternate_connection_pool.respond_to?(:lease_connection) + alternate_connection_pool.lease_connection + else + alternate_connection_pool.connection + end alternate_connection.execute("BEGIN") alternate_connection.execute("LOCK TABLE foos") @@ -4069,7 +4075,12 @@ def up ActiveRecord::ConnectionAdapters::ConnectionPool.new(pool_config) end let(:alternate_connection) do - alternate_connection_pool.connection + # The #connection method was deprecated in Rails 7.2 in favor of #lease_connection + if alternate_connection_pool.respond_to?(:lease_connection) + alternate_connection_pool.lease_connection + else + alternate_connection_pool.connection + end end let(:migration) { Class.new(migration_klass).new }