From 78716ad1b55a363d655f5bf8376c1dcba5902111 Mon Sep 17 00:00:00 2001 From: Vincent Prigent Date: Tue, 10 Sep 2024 10:56:27 +1200 Subject: [PATCH] Fix db_config_with_versions arity change and backport --- README.md | 1 - lib/data_migrate/database_tasks.rb | 4 +++- lib/data_migrate/rails_helper.rb | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 80f566a..7ac640b 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,6 @@ 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 rails-6.1 rspec bundle exec appraisal rails-7.0 rspec bundle exec appraisal rails-7.1 rspec diff --git a/lib/data_migrate/database_tasks.rb b/lib/data_migrate/database_tasks.rb index d1ab7f3..9f92af1 100644 --- a/lib/data_migrate/database_tasks.rb +++ b/lib/data_migrate/database_tasks.rb @@ -179,7 +179,9 @@ def self.migrate_with_data ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true - schema_mapped_versions = if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_1 + # 7.2 removes the param for db_configs_with_versions in https://github.com/rails/rails/commit/9572fcb4a0bd5396436689a6a42613886871cd81 + # 7.1 stable backported the change in https://github.com/rails/rails/commit/c53ec4b60980036b43528829d4b0b7457f759224 + schema_mapped_versions = if Gem::Dependency.new("railties", ">= 7.1.4").match?("railties", Gem.loaded_specs["railties"].version, true) ActiveRecord::Tasks::DatabaseTasks.db_configs_with_versions else db_configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env) diff --git a/lib/data_migrate/rails_helper.rb b/lib/data_migrate/rails_helper.rb index d71ae44..18b12c6 100644 --- a/lib/data_migrate/rails_helper.rb +++ b/lib/data_migrate/rails_helper.rb @@ -6,6 +6,7 @@ def rails_version_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)