Skip to content

Commit

Permalink
fix: db:schema:load for rails 6.0.x versions (#342)
Browse files Browse the repository at this point in the history
* fix: db:schema:load for rails 6.0.x versions

* Update version

* fix spec for rails 7.0.x

* Improve readability
  • Loading branch information
vprigent authored Sep 24, 2024
1 parent f092853 commit c20e031
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "http://rubygems.org"

gem "sqlite3", "~> 1.4"
gem "rails", "~> 7.0"
gem "rails", "~> 7.0.0"

gemspec path: "../"
12 changes: 12 additions & 0 deletions lib/data_migrate/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@ 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

# Override this method from `ActiveRecord::Tasks::DatabaseTasks`
# 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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/data_migrate/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DataMigrate
VERSION = "9.1.1".freeze
VERSION = "9.1.2".freeze
end

0 comments on commit c20e031

Please sign in to comment.