Skip to content

Commit

Permalink
Fix schema dump on multiple databases setup with ActiveRecord > 7.2.0 (
Browse files Browse the repository at this point in the history
…#131)

Closes #130
  • Loading branch information
remoteweb authored Nov 25, 2024
1 parent 13eceb9 commit c1390d8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/tasks/hair_trigger.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,28 @@ namespace :db do

ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
db_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: name)
connection_pool = ActiveRecord::Base.establish_connection(db_config)
connection = get_connection(ActiveRecord::Base.establish_connection(db_config))

filename = dump_filename(db_config.name)
ActiveRecord::SchemaDumper.previous_schema = File.exist?(filename) ? File.read(filename) : nil

File.open(filename, "w") do |file|
ActiveRecord::SchemaDumper.dump(connection_pool.connection, file)

ActiveRecord::SchemaDumper.dump(connection, file)
end
end

Rake::Task["db:schema:dump"].reenable
end

def get_connection(connection_pool)
if Gem::Version.new("7.2.0") <= ActiveRecord.gem_version
connection_pool
else
connection_pool.connection
end
end

def schema_file_type(format)
case format
when :ruby
Expand Down

0 comments on commit c1390d8

Please sign in to comment.