From 1f15cc91afb66862df7feef20c213d451384b41e Mon Sep 17 00:00:00 2001 From: Leo Arnold Date: Wed, 14 Aug 2024 11:16:15 +0200 Subject: [PATCH] Add support for activerecord v7.2 Closes #124 --- .github/workflows/workflow.yml | 4 +- Appraisals | 10 ++- gemfiles/activerecord_7.1.gemfile | 2 +- gemfiles/activerecord_7.1.gemfile.lock | 32 ++++++--- gemfiles/activerecord_7.2.gemfile | 21 ++++++ gemfiles/activerecord_7.2.gemfile.lock | 92 ++++++++++++++++++++++++++ lib/hair_trigger.rb | 7 +- spec/spec_helper.rb | 9 ++- 8 files changed, 161 insertions(+), 16 deletions(-) create mode 100644 gemfiles/activerecord_7.2.gemfile create mode 100644 gemfiles/activerecord_7.2.gemfile.lock diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4073a11..3ecc38b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -34,8 +34,8 @@ jobs: --health-retries 3 strategy: matrix: - ruby: ["3.0", "3.1", "3.2", "3.3"] - gemfile: ["activerecord_6.1", "activerecord_7.0", "activerecord_7.1"] + ruby: ["3.1", "3.2", "3.3"] + gemfile: ["activerecord_6.1", "activerecord_7.0", "activerecord_7.1", "activerecord_7.2"] env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile steps: diff --git a/Appraisals b/Appraisals index 23c303c..eef42ba 100644 --- a/Appraisals +++ b/Appraisals @@ -16,7 +16,15 @@ appraise "activerecord-7.0" do end appraise "activerecord-7.1" do - gem "activerecord", "~> 7.0.0" + gem "activerecord", "~> 7.1.0" + gem "mysql2", "~> 0.5" + gem "pg", ">= 0.18", "< 2.0" + gem "sqlite3", "~> 1.4.0" + gem "racc", '~> 1.7.3', platforms: [:ruby_33] +end + +appraise "activerecord-7.2" do + gem "activerecord", "~> 7.2.0" gem "mysql2", "~> 0.5" gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.4.0" diff --git a/gemfiles/activerecord_7.1.gemfile b/gemfiles/activerecord_7.1.gemfile index d386057..dcd84a6 100644 --- a/gemfiles/activerecord_7.1.gemfile +++ b/gemfiles/activerecord_7.1.gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gem "racc", "~> 1.7.3", platforms: [:ruby_33] -gem "activerecord", "~> 7.0.0" +gem "activerecord", "~> 7.1.0" gem "mysql2", "~> 0.5" gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.4.0" diff --git a/gemfiles/activerecord_7.1.gemfile.lock b/gemfiles/activerecord_7.1.gemfile.lock index 18c32bf..be123f2 100644 --- a/gemfiles/activerecord_7.1.gemfile.lock +++ b/gemfiles/activerecord_7.1.gemfile.lock @@ -9,26 +9,37 @@ PATH GEM remote: https://rubygems.org/ specs: - activemodel (7.0.8) - activesupport (= 7.0.8) - activerecord (7.0.8) - activemodel (= 7.0.8) - activesupport (= 7.0.8) - activesupport (7.0.8) + activemodel (7.1.3.4) + activesupport (= 7.1.3.4) + activerecord (7.1.3.4) + activemodel (= 7.1.3.4) + activesupport (= 7.1.3.4) + timeout (>= 0.4.0) + activesupport (7.1.3.4) + 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) + base64 (0.2.0) + bigdecimal (3.1.8) byebug (11.1.3) - concurrent-ruby (1.2.2) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) diff-lcs (1.5.0) - i18n (1.14.1) + drb (2.2.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) - minitest (5.20.0) + minitest (5.25.0) + mutex_m (0.2.0) mysql2 (0.5.5) pg (1.5.4) racc (1.7.3) @@ -54,6 +65,7 @@ GEM sexp_processor (4.17.0) sqlite3 (1.4.4) thor (1.3.0) + timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) @@ -62,7 +74,7 @@ PLATFORMS ruby DEPENDENCIES - activerecord (~> 7.0.0) + activerecord (~> 7.1.0) appraisal byebug hairtrigger! diff --git a/gemfiles/activerecord_7.2.gemfile b/gemfiles/activerecord_7.2.gemfile new file mode 100644 index 0000000..2728e3a --- /dev/null +++ b/gemfiles/activerecord_7.2.gemfile @@ -0,0 +1,21 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "racc", "~> 1.7.3", platforms: [:ruby_33] +gem "activerecord", "~> 7.2.0" +gem "mysql2", "~> 0.5" +gem "pg", ">= 0.18", "< 2.0" +gem "sqlite3", "~> 1.4.0" + +group :development do + gem "appraisal" + gem "byebug" +end + +group :test do + gem "rake", "~> 13.0.6" + gem "rspec", "~> 3.12.0" +end + +gemspec path: "../" diff --git a/gemfiles/activerecord_7.2.gemfile.lock b/gemfiles/activerecord_7.2.gemfile.lock new file mode 100644 index 0000000..3984018 --- /dev/null +++ b/gemfiles/activerecord_7.2.gemfile.lock @@ -0,0 +1,92 @@ +PATH + remote: .. + specs: + hairtrigger (1.1.1) + activerecord (>= 6.0, < 8) + ruby2ruby (~> 2.4) + ruby_parser (~> 3.10) + +GEM + remote: https://rubygems.org/ + specs: + activemodel (7.2.0) + activesupport (= 7.2.0) + activerecord (7.2.0) + activemodel (= 7.2.0) + activesupport (= 7.2.0) + timeout (>= 0.4.0) + activesupport (7.2.0) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + base64 (0.2.0) + bigdecimal (3.1.8) + byebug (11.1.3) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + diff-lcs (1.5.1) + drb (2.2.1) + i18n (1.14.5) + concurrent-ruby (~> 1.0) + logger (1.6.0) + minitest (5.25.0) + mysql2 (0.5.5) + pg (1.5.4) + racc (1.7.3) + rake (13.0.6) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.3) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.4) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.7) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.2) + ruby2ruby (2.5.1) + ruby_parser (~> 3.1) + sexp_processor (~> 4.6) + ruby_parser (3.21.1) + racc (~> 1.5) + sexp_processor (~> 4.16) + securerandom (0.3.1) + sexp_processor (4.17.2) + sqlite3 (1.4.4) + thor (1.3.1) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + +PLATFORMS + ruby + x86_64-linux + +DEPENDENCIES + activerecord (~> 7.2.0) + appraisal + byebug + hairtrigger! + mysql2 (~> 0.5) + pg (>= 0.18, < 2.0) + racc (~> 1.7.3) + rake (~> 13.0.6) + rspec (~> 3.12.0) + sqlite3 (~> 1.4.0) + +BUNDLED WITH + 2.5.11 diff --git a/lib/hair_trigger.rb b/lib/hair_trigger.rb index fe423b4..73d10e5 100644 --- a/lib/hair_trigger.rb +++ b/lib/hair_trigger.rb @@ -39,7 +39,12 @@ def models end def migrator - if ActiveRecord::VERSION::STRING >= "7.1." + if Gem::Version.new("7.2.0") <= ActiveRecord.gem_version + connection = ActiveRecord::Tasks::DatabaseTasks.migration_connection_pool + schema_migration = connection.schema_migration + migrations = ActiveRecord::MigrationContext.new(migration_path, schema_migration).migrations + ActiveRecord::Migrator.new(:up, migrations, schema_migration, ActiveRecord::InternalMetadata.new(connection)) + elsif Gem::Version.new("7.1.0") <= ActiveRecord.gem_version connection = ActiveRecord::Tasks::DatabaseTasks.migration_connection schema_migration = connection.schema_migration migrations = ActiveRecord::MigrationContext.new(migration_path, schema_migration).migrations diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 65951d3..4bf9cc7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -94,7 +94,14 @@ def migrate_db def dump_schema io = StringIO.new - ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, io) + connection = if Gem::Version.new("7.2.0") <= ActiveRecord.gem_version + ActiveRecord::Base.connection_pool + else + ActiveRecord::Base.connection + end + + ActiveRecord::SchemaDumper.dump(connection, io) + io.rewind io.read end