diff --git a/Changelog.md b/Changelog.md index 2a0093ee..675574b9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,13 @@ # Changelog +## 9.1.2 + +- Fix #281 to maintain rails 6.0 support. (#342) + +## 9.1.1 + +- Backport Fix data:schema:load for structure.sql (#281) + ## 9.1.0 - Fix a bug that caused `schema_sha1` in `ar_internal_metadata` to be reset to the `data_schema.rb` file. (#272) diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index 88cdc430..3f5a75ba 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -3,6 +3,6 @@ source "http://rubygems.org" gem "sqlite3", "~> 1.4" -gem "rails", "~> 7.0" +gem "rails", "~> 7.0.0" gemspec path: "../" diff --git a/lib/data_migrate/database_tasks.rb b/lib/data_migrate/database_tasks.rb index 5c525ae8..2f69442a 100644 --- a/lib/data_migrate/database_tasks.rb +++ b/lib/data_migrate/database_tasks.rb @@ -74,6 +74,10 @@ def schema_dump_path(db_config, format = ActiveRecord.schema_format) # We only require a schema.rb file for the primary database return unless db_config.primary? + if rails_version_lower_than_6_1? + return super.gsub(/(_)?schema\.rb\z/, '\1data_schema.rb') + end + File.join(File.dirname(ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(db_config, format)), schema_file_type) end @@ -81,6 +85,10 @@ def schema_dump_path(db_config, format = ActiveRecord.schema_format) # to ensure that the sha saved in ar_internal_metadata table # is from the original schema.rb file def schema_sha1(file) + if rails_version_lower_than_6_1? + return super(file.gsub(/data_schema.rb\z/, 'schema.rb')) + end + ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: "primary")) end end @@ -116,5 +124,9 @@ def self.past_migrations(sort = nil) sort&.downcase == "asc" ? sort_migrations(migrations) : sort_migrations(migrations).reverse end + + def self.rails_version_lower_than_6_1? + Gem::Dependency.new("railties", "< 6.1").match?("railties", Gem.loaded_specs["railties"].version) + end end end diff --git a/lib/data_migrate/version.rb b/lib/data_migrate/version.rb index 38d2d3a3..fc027fdd 100644 --- a/lib/data_migrate/version.rb +++ b/lib/data_migrate/version.rb @@ -1,3 +1,3 @@ module DataMigrate - VERSION = "9.1.1".freeze + VERSION = "9.1.2".freeze end