From adabebeacdb8955add9cf493c783700cc1858336 Mon Sep 17 00:00:00 2001 From: Jacob Burroughs Date: Thu, 5 Oct 2023 13:52:16 -0500 Subject: [PATCH] Support rails 7.1 (#19) --- .github/workflows/push.yml | 2 +- .gitignore | 1 + .rubocop.yml | 3 + Gemfile | 6 + Gemfile.lock | 6 +- Gemfile.rails-7.0.lock | 7 +- Gemfile.rails-7.1.lock | 196 ++++++++++++++++++ activerecord-pg-extensions.gemspec | 4 +- .../pg_extensions/transaction.rb | 3 + lib/active_record/pg_extensions/version.rb | 2 +- spec/spec_helper.rb | 13 +- 11 files changed, 229 insertions(+), 14 deletions(-) create mode 100644 Gemfile.rails-7.1.lock diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 777d48c..ff43da7 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: ruby-version: [2.7, "3.0", 3.1, 3.2] - lockfile: ['Gemfile.rails-7.0.lock'] + lockfile: ['Gemfile.rails-7.0.lock', 'Gemfile.rails-7.1.lock'] services: postgres: diff --git a/.gitignore b/.gitignore index c666a5a..ee1d7bd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /pkg/ /workflow/ /vendor/ +/tmp/ diff --git a/.rubocop.yml b/.rubocop.yml index ffe8157..814bb15 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -15,6 +15,9 @@ AllCops: Exclude: - 'gemfiles/*' +Bundler/DuplicatedGem: + Enabled: false + Style/DocumentDynamicEvalDefinition: Enabled: false diff --git a/Gemfile b/Gemfile index d9704aa..551918c 100644 --- a/Gemfile +++ b/Gemfile @@ -11,4 +11,10 @@ gemspec lockfile "rails-7.0", default: true do gem "activerecord", "~> 7.0.0" + gem "railties", "~> 7.0.0" +end + +lockfile "rails-7.1" do + gem "activerecord", "~> 7.1.0.rc2" + gem "railties", "~> 7.1.0.rc2" end diff --git a/Gemfile.lock b/Gemfile.lock index dca4ddb..b602777 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ PATH remote: . specs: - activerecord-pg-extensions (0.5.3) - activerecord (~> 7.0.0) - railties (~> 7.0.0) + activerecord-pg-extensions (0.5.4) + activerecord (>= 7.0, < 7.2) + railties (>= 7.0, < 7.2) GEM remote: https://rubygems.org/ diff --git a/Gemfile.rails-7.0.lock b/Gemfile.rails-7.0.lock index 8018a1f..7e0f088 100644 --- a/Gemfile.rails-7.0.lock +++ b/Gemfile.rails-7.0.lock @@ -1,9 +1,9 @@ PATH remote: . specs: - activerecord-pg-extensions (0.5.3) - activerecord (~> 7.0.0) - railties (~> 7.0.0) + activerecord-pg-extensions (0.5.4) + activerecord (>= 7.0, < 7.2) + railties (>= 7.0, < 7.2) GEM remote: https://rubygems.org/ @@ -164,6 +164,7 @@ DEPENDENCIES appraisal (~> 2.4) debug (~> 1.8) pg (~> 1.2) + railties (~> 7.0.0) rake (~> 13.0) rspec (~> 3.0) rubocop-inst (~> 1) diff --git a/Gemfile.rails-7.1.lock b/Gemfile.rails-7.1.lock new file mode 100644 index 0000000..72ad261 --- /dev/null +++ b/Gemfile.rails-7.1.lock @@ -0,0 +1,196 @@ +PATH + remote: . + specs: + activerecord-pg-extensions (0.5.4) + activerecord (>= 7.0, < 7.2) + railties (>= 7.0, < 7.2) + +GEM + remote: https://rubygems.org/ + specs: + actionpack (7.1.0) + actionview (= 7.1.0) + activesupport (= 7.1.0) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actionview (7.1.0) + activesupport (= 7.1.0) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activemodel (7.1.0) + activesupport (= 7.1.0) + activerecord (7.1.0) + activemodel (= 7.1.0) + activesupport (= 7.1.0) + timeout (>= 0.4.0) + activesupport (7.1.0) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + ast (2.4.2) + base64 (0.1.1) + bigdecimal (3.1.4) + builder (3.2.4) + concurrent-ruby (1.2.2) + connection_pool (2.4.1) + crass (1.0.6) + debug (1.8.0) + irb (>= 1.5.0) + reline (>= 0.3.1) + diff-lcs (1.5.0) + drb (2.1.1) + ruby2_keywords + erubi (1.12.0) + i18n (1.14.1) + concurrent-ruby (~> 1.0) + io-console (0.6.0) + irb (1.8.1) + rdoc + reline (>= 0.3.8) + json (2.6.3) + language_server-protocol (3.17.0.3) + loofah (2.21.3) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mini_portile2 (2.8.4) + minitest (5.20.0) + mutex_m (0.1.2) + nokogiri (1.15.4) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) + nokogiri (1.15.4-arm64-darwin) + racc (~> 1.4) + nokogiri (1.15.4-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.15.4-x86_64-linux) + racc (~> 1.4) + parallel (1.23.0) + parser (3.2.2.3) + ast (~> 2.4.1) + racc + pg (1.5.4) + psych (5.1.0) + stringio + racc (1.7.1) + rack (3.0.8) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.1.0) + actionpack (= 7.1.0) + activesupport (= 7.1.0) + irb + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.0.6) + rdoc (6.5.0) + psych (>= 4.0.0) + regexp_parser (2.8.1) + reline (0.3.9) + io-console (~> 0.5) + rexml (3.2.6) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.1) + rubocop (1.56.4) + base64 (~> 0.1.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.2.2.3) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.29.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.19.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.24.0) + rubocop (~> 1.33) + rubocop-inst (1.0.2) + rubocop (~> 1.50) + rubocop-performance (~> 1.17) + rubocop-performance (1.19.1) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.24.1) + rubocop (~> 1.33) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + stringio (3.0.8) + thor (1.2.2) + timeout (0.4.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + webrick (1.8.1) + zeitwerk (2.6.12) + +PLATFORMS + arm64-darwin + ruby + x86_64-darwin + x86_64-linux + +DEPENDENCIES + activerecord (~> 7.1.0.rc2) + activerecord-pg-extensions! + appraisal (~> 2.4) + debug (~> 1.8) + pg (~> 1.2) + railties (~> 7.1.0.rc2) + rake (~> 13.0) + rspec (~> 3.0) + rubocop-inst (~> 1) + rubocop-rake (~> 0.5) + rubocop-rspec (~> 2.3) + +BUNDLED WITH + 2.4.20 diff --git a/activerecord-pg-extensions.gemspec b/activerecord-pg-extensions.gemspec index b280201..a9745ec 100644 --- a/activerecord-pg-extensions.gemspec +++ b/activerecord-pg-extensions.gemspec @@ -20,8 +20,8 @@ Gem::Specification.new do |spec| spec.files = Dir["lib/**/*"] + ["LICENSE.txt", "README.md", "CHANGELOG.md"] spec.require_paths = ["lib"] - spec.add_dependency "activerecord", "~> 7.0.0" - spec.add_dependency "railties", "~> 7.0.0" + spec.add_dependency "activerecord", ">= 7.0", "< 7.2" + spec.add_dependency "railties", ">= 7.0", "< 7.2" spec.add_development_dependency "appraisal", "~> 2.4" spec.add_development_dependency "debug", "~> 1.8" diff --git a/lib/active_record/pg_extensions/transaction.rb b/lib/active_record/pg_extensions/transaction.rb index b74e3e6..aac3d02 100644 --- a/lib/active_record/pg_extensions/transaction.rb +++ b/lib/active_record/pg_extensions/transaction.rb @@ -15,6 +15,9 @@ def #{kind}(local: false) return if @#{kind} == timeout @#{kind} = timeout + # If we have set an explicit timeout, the transaction has state that must be materialized + # separately from any other transaction, so it cannot be `restartable` + dirty! unless ::Rails.version < '7.1' return unless materialized? connection.set(#{kind.inspect}, "\#{(timeout * 1000).to_i}ms", local: true) end diff --git a/lib/active_record/pg_extensions/version.rb b/lib/active_record/pg_extensions/version.rb index 5c46ac2..9e598f6 100644 --- a/lib/active_record/pg_extensions/version.rb +++ b/lib/active_record/pg_extensions/version.rb @@ -2,6 +2,6 @@ module ActiveRecord module PGExtensions - VERSION = "0.5.3" + VERSION = "0.5.4" end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cbd413c..f71dcf0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,11 +10,10 @@ class Application < Rails::Application config.eager_load = false - config.active_record.legacy_connection_handling = false end Application.initialize! -ActiveRecord::Tasks::DatabaseTasks.create_all +ActiveRecord::Tasks::DatabaseTasks.create_current module StatementCaptureConnection def dont_execute @@ -28,7 +27,12 @@ def executed_statements @executed_statements ||= [] end - %w[execute exec_no_cache exec_cache].each do |method| + methods = if Rails.version < "7.1" + %w[execute exec_no_cache exec_cache] + else + %w[internal_execute exec_no_cache exec_cache] + end + methods.each do |method| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{method}(statement, *, **) materialize_transactions # this still needs to get called, even if we skip actually executing @@ -43,7 +47,8 @@ def #{method}(statement, *, **) # we can't actually generate a dummy one of these, so we just query the db with something # that won't return anything def empty_pg_result - @connection.async_exec("SELECT 0 WHERE FALSE") + conn = (::Rails.version < "7.1") ? @connection : @raw_connection + conn.async_exec("SELECT 0 WHERE FALSE") end end ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(StatementCaptureConnection)