diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fdbc541..c31c416 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,6 +18,7 @@ jobs: - gemfiles/rails_6.1.gemfile - gemfiles/rails_7.0.gemfile - gemfiles/rails_7.1.gemfile + - gemfiles/rails_7.2.gemfile runs-on: ubuntu-latest env: BUNDLE_GEMFILE: ${{ matrix.gemfile }} diff --git a/Appraisals b/Appraisals index 7eec0af..ded82fb 100644 --- a/Appraisals +++ b/Appraisals @@ -9,3 +9,8 @@ end appraise 'rails-7.1' do gem 'rails', '7.1.0' end + + +appraise 'rails-7.2' do + gem 'rails', '7.2.0.beta1' +end diff --git a/Changelog.md b/Changelog.md index 2dd7b7d..d535045 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,7 @@ # Unreleased - Remove Ruby 3.0 from build matrix +- Support Rails 7.2 https://github.com/ilyakatz/data-migrate/pull/312 ## 9.4.2 - Fix db:prepare:with_data task diff --git a/Gemfile.lock b/Gemfile.lock index facbf74..6930de5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,9 +71,11 @@ GEM method_source (1.0.0) minitest (5.23.1) mutex_m (0.2.0) - nokogiri (1.16.5-arm64-darwin) + nokogiri (1.16.2-aarch64-linux) racc (~> 1.4) - nokogiri (1.16.5-x86_64-linux) + nokogiri (1.16.2-arm64-darwin) + racc (~> 1.4) + nokogiri (1.16.2-x86_64-linux) racc (~> 1.4) overcommit (0.63.0) childprocess (>= 0.6.3, < 6) @@ -149,6 +151,8 @@ GEM rubocop-ast (1.30.0) parser (>= 3.2.1.0) ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + sqlite3 (1.7.2-aarch64-linux) sqlite3 (1.7.2-arm64-darwin) sqlite3 (1.7.2-x86_64-linux) stringio (3.1.0) @@ -163,6 +167,7 @@ GEM zeitwerk (2.6.13) PLATFORMS + aarch64-linux arm64-darwin-22 arm64-darwin-23 x86_64-linux diff --git a/README.md b/README.md index 4e93fd5..19f2280 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ table to track all migrations. ## Rails Support -Support Rails 6.1 through 7.1 +Support Rails 6.1 through 7.2 #### v1 @@ -163,10 +163,11 @@ Then, in the Engine's `db/data` folder, you can add data migrations and run them Run tests for a specific version of Rails ``` -bundle exec appraisal install + bundle exec appraisal rails-6.1 rspec bundle exec appraisal rails-7.0 rspec bundle exec appraisal rails-7.1 rspec +bundle exec appraisal rails-7.2 rspec ``` ## Releasing new version diff --git a/gemfiles/rails_6.1.gemfile.lock b/gemfiles/rails_6.1.gemfile.lock index 54d78e8..fdd6a65 100644 --- a/gemfiles/rails_6.1.gemfile.lock +++ b/gemfiles/rails_6.1.gemfile.lock @@ -108,6 +108,8 @@ GEM net-smtp (0.4.0.1) net-protocol nio4r (2.7.0) + nokogiri (1.16.2-aarch64-linux) + racc (~> 1.4) nokogiri (1.16.2-arm64-darwin) racc (~> 1.4) nokogiri (1.16.2-x86_64-linux) @@ -193,6 +195,7 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + sqlite3 (1.7.2-aarch64-linux) sqlite3 (1.7.2-arm64-darwin) sqlite3 (1.7.2-x86_64-linux) thor (1.3.1) @@ -207,6 +210,7 @@ GEM zeitwerk (2.6.13) PLATFORMS + aarch64-linux arm64-darwin-22 arm64-darwin-23 x86_64-linux diff --git a/gemfiles/rails_7.0.gemfile.lock b/gemfiles/rails_7.0.gemfile.lock index 9d99b69..cf45d9c 100644 --- a/gemfiles/rails_7.0.gemfile.lock +++ b/gemfiles/rails_7.0.gemfile.lock @@ -115,6 +115,8 @@ GEM net-smtp (0.4.0.1) net-protocol nio4r (2.7.0) + nokogiri (1.16.2-aarch64-linux) + racc (~> 1.4) nokogiri (1.16.2-arm64-darwin) racc (~> 1.4) nokogiri (1.16.2-x86_64-linux) @@ -194,6 +196,7 @@ GEM rubocop-ast (1.29.0) parser (>= 3.2.1.0) ruby-progressbar (1.13.0) + sqlite3 (1.7.2-aarch64-linux) sqlite3 (1.7.2-arm64-darwin) sqlite3 (1.7.2-x86_64-linux) thor (1.3.1) @@ -208,6 +211,7 @@ GEM zeitwerk (2.6.13) PLATFORMS + aarch64-linux arm64-darwin-22 arm64-darwin-23 x86_64-linux diff --git a/gemfiles/rails_7.1.gemfile.lock b/gemfiles/rails_7.1.gemfile.lock index b1066e6..f78e9d2 100644 --- a/gemfiles/rails_7.1.gemfile.lock +++ b/gemfiles/rails_7.1.gemfile.lock @@ -133,6 +133,8 @@ GEM net-smtp (0.4.0.1) net-protocol nio4r (2.7.0) + nokogiri (1.16.2-aarch64-linux) + racc (~> 1.4) nokogiri (1.16.2-arm64-darwin) racc (~> 1.4) nokogiri (1.16.2-x86_64-linux) @@ -225,6 +227,7 @@ GEM parser (>= 3.2.1.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) + sqlite3 (1.7.2-aarch64-linux) sqlite3 (1.7.2-arm64-darwin) sqlite3 (1.7.2-x86_64-linux) stringio (3.1.0) @@ -241,6 +244,7 @@ GEM zeitwerk (2.6.13) PLATFORMS + aarch64-linux arm64-darwin-22 arm64-darwin-23 x86_64-linux diff --git a/gemfiles/rails_7.2.gemfile b/gemfiles/rails_7.2.gemfile new file mode 100644 index 0000000..6730ca8 --- /dev/null +++ b/gemfiles/rails_7.2.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "rails", "7.2.0.beta1" + +gemspec path: "../" diff --git a/gemfiles/rails_7.2.gemfile.lock b/gemfiles/rails_7.2.gemfile.lock new file mode 100644 index 0000000..751f9e1 --- /dev/null +++ b/gemfiles/rails_7.2.gemfile.lock @@ -0,0 +1,261 @@ +PATH + remote: .. + specs: + data_migrate (9.4.2) + activerecord (>= 6.1) + railties (>= 6.1) + +GEM + remote: http://rubygems.org/ + specs: + actioncable (7.2.0.beta1) + actionpack (= 7.2.0.beta1) + activesupport (= 7.2.0.beta1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (7.2.0.beta1) + actionpack (= 7.2.0.beta1) + activejob (= 7.2.0.beta1) + activerecord (= 7.2.0.beta1) + activestorage (= 7.2.0.beta1) + activesupport (= 7.2.0.beta1) + mail (>= 2.8.0) + actionmailer (7.2.0.beta1) + actionpack (= 7.2.0.beta1) + actionview (= 7.2.0.beta1) + activejob (= 7.2.0.beta1) + activesupport (= 7.2.0.beta1) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (7.2.0.beta1) + actionview (= 7.2.0.beta1) + activesupport (= 7.2.0.beta1) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (7.2.0.beta1) + actionpack (= 7.2.0.beta1) + activerecord (= 7.2.0.beta1) + activestorage (= 7.2.0.beta1) + activesupport (= 7.2.0.beta1) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.2.0.beta1) + activesupport (= 7.2.0.beta1) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.2.0.beta1) + activesupport (= 7.2.0.beta1) + globalid (>= 0.3.6) + activemodel (7.2.0.beta1) + activesupport (= 7.2.0.beta1) + activerecord (7.2.0.beta1) + activemodel (= 7.2.0.beta1) + activesupport (= 7.2.0.beta1) + timeout (>= 0.4.0) + activestorage (7.2.0.beta1) + actionpack (= 7.2.0.beta1) + activejob (= 7.2.0.beta1) + activerecord (= 7.2.0.beta1) + activesupport (= 7.2.0.beta1) + marcel (~> 1.0) + activesupport (7.2.0.beta1) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0, >= 2.0.5) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.8) + builder (3.2.4) + childprocess (5.0.0) + coderay (1.1.3) + concurrent-ruby (1.3.1) + connection_pool (2.4.1) + crass (1.0.6) + date (3.3.4) + diff-lcs (1.5.1) + drb (2.2.1) + erubi (1.12.0) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.5) + concurrent-ruby (~> 1.0) + iniparse (1.5.0) + io-console (0.7.2) + irb (1.13.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + json (2.7.2) + language_server-protocol (3.17.0.3) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + method_source (1.1.0) + mini_mime (1.1.5) + minitest (5.23.1) + net-imap (0.4.11) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.3) + nokogiri (1.16.5-aarch64-linux) + racc (~> 1.4) + nokogiri (1.16.5-arm64-darwin) + racc (~> 1.4) + nokogiri (1.16.5-x86_64-linux) + racc (~> 1.4) + overcommit (0.63.0) + childprocess (>= 0.6.3, < 6) + iniparse (~> 1.4) + rexml (~> 3.2) + parallel (1.24.0) + parser (3.3.1.0) + ast (~> 2.4.1) + racc + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + psych (5.1.2) + stringio + racc (1.8.0) + rack (3.0.11) + 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 (7.2.0.beta1) + actioncable (= 7.2.0.beta1) + actionmailbox (= 7.2.0.beta1) + actionmailer (= 7.2.0.beta1) + actionpack (= 7.2.0.beta1) + actiontext (= 7.2.0.beta1) + actionview (= 7.2.0.beta1) + activejob (= 7.2.0.beta1) + activemodel (= 7.2.0.beta1) + activerecord (= 7.2.0.beta1) + activestorage (= 7.2.0.beta1) + activesupport (= 7.2.0.beta1) + bundler (>= 1.15.0) + railties (= 7.2.0.beta1) + 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.2.0.beta1) + actionpack (= 7.2.0.beta1) + activesupport (= 7.2.0.beta1) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.2.1) + rb-readline (0.5.5) + rdoc (6.7.0) + psych (>= 4.0.0) + regexp_parser (2.9.2) + reline (0.5.8) + io-console (~> 0.5) + rexml (3.2.8) + strscan (>= 3.0.9) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.64.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + ruby-progressbar (1.13.0) + sqlite3 (2.0.2-aarch64-linux-gnu) + sqlite3 (2.0.2-arm64-darwin) + sqlite3 (2.0.2-x86_64-linux-gnu) + stringio (3.1.0) + strscan (3.1.0) + thor (1.3.1) + timecop (0.9.8) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + useragent (0.16.10) + webrick (1.8.1) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.6.15) + +PLATFORMS + aarch64-linux + arm64-darwin-23 + x86_64-linux + +DEPENDENCIES + appraisal + data_migrate! + overcommit + pry + rails (= 7.2.0.beta1) + rake + rb-readline + rspec + rspec-core + rubocop + sqlite3 + timecop + +BUNDLED WITH + 2.4.17 diff --git a/lib/data_migrate/rails_helper.rb b/lib/data_migrate/rails_helper.rb index 9f94e73..d71ae44 100644 --- a/lib/data_migrate/rails_helper.rb +++ b/lib/data_migrate/rails_helper.rb @@ -1,6 +1,11 @@ module DataMigrate class RailsHelper class << self + def rails_version_equal_to_or_higher_than_7_2 + return @equal_to_or_higher_than_7_2 if defined?(@equal_to_or_higher_than_7_2) + + @equal_to_or_higher_than_7_2 = Gem::Dependency.new("railties", ">= 7.2.0.alpha").match?("railties", Gem.loaded_specs["railties"].version, true) + end def rails_version_equal_to_or_higher_than_7_1 return @equal_to_or_higher_than_7_1 if defined?(@equal_to_or_higher_than_7_1) @@ -14,7 +19,9 @@ def rails_version_equal_to_or_higher_than_7_0 end def internal_metadata - if rails_version_equal_to_or_higher_than_7_1 + if rails_version_equal_to_or_higher_than_7_2 + ActiveRecord::Base.connection_pool.internal_metadata + elsif rails_version_equal_to_or_higher_than_7_1 ActiveRecord::Base.connection.internal_metadata else ActiveRecord::InternalMetadata @@ -22,7 +29,9 @@ def internal_metadata end def schema_migration - if rails_version_equal_to_or_higher_than_7_1 + if rails_version_equal_to_or_higher_than_7_2 + ActiveRecord::Base.connection_pool.schema_migration + elsif rails_version_equal_to_or_higher_than_7_1 ActiveRecord::Base.connection.schema_migration else ActiveRecord::SchemaMigration @@ -54,7 +63,9 @@ def data_schema_delete_version(version) end def data_schema_migration - if rails_version_equal_to_or_higher_than_7_1 + if rails_version_equal_to_or_higher_than_7_2 + DataMigrate::DataSchemaMigration.new(ActiveRecord::Tasks::DatabaseTasks.migration_connection_pool) + elsif rails_version_equal_to_or_higher_than_7_1 DataMigrate::DataSchemaMigration.new(ActiveRecord::Tasks::DatabaseTasks.migration_connection) else DataMigrate::DataSchemaMigration diff --git a/spec/data_migrate/migration_context_spec.rb b/spec/data_migrate/migration_context_spec.rb index c80155d..d995137 100644 --- a/spec/data_migrate/migration_context_spec.rb +++ b/spec/data_migrate/migration_context_spec.rb @@ -4,7 +4,7 @@ describe DataMigrate::DataMigrator do let(:context) { DataMigrate::MigrationContext.new("spec/db/data") } - let(:schema_context) { ActiveRecord::MigrationContext.new("spec/db/migrate", ActiveRecord::Base.connection.schema_migration) } + let(:schema_context) { ActiveRecord::MigrationContext.new("spec/db/migrate", ar_schema_migration) } let(:db_config) do { adapter: "sqlite3", @@ -105,4 +105,13 @@ expect(versions.count).to eq(0) end end + + # schema migration changed in Rails 7.2, from the connection to the pool object. + def ar_schema_migration + if ActiveRecord::Base.connection_pool.respond_to?(:schema_migration) + ActiveRecord::Base.connection_pool.schema_migration + else + ActiveRecord::Base.connection.schema_migration + end + end end