Skip to content

Commit

Permalink
Improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
vprigent committed Sep 24, 2024
1 parent 112cf40 commit 00a69e0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/data_migrate/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,22 @@ 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 Gem::Dependency.new("railties", ">= 6.1").match?("railties", Gem.loaded_specs["railties"].version)
File.join(File.dirname(ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(db_config, format)), schema_file_type)
else
super.gsub(/(_)?schema\.rb\z/, '\1data_schema.rb')
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 Gem::Dependency.new("railties", ">= 6.1").match?("railties", Gem.loaded_specs["railties"].version)
ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: "primary"))
else
super(file.gsub(/data_schema.rb\z/, 'schema.rb'))
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 @@ -124,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

0 comments on commit 00a69e0

Please sign in to comment.