Skip to content

Commit

Permalink
Make sure we are using the correct connection pool when dumping the s…
Browse files Browse the repository at this point in the history
…chema (rails#52777)

* Add test to make sure the schemas are different

Related to rails#52776.

Those two schemas files should be different,
as they are generated from different migrations.

* Make sure we are using the correct connection pool when dumping the schema

This was broken by 175bf82.

Before we were switching the connection pool to use the one for the
correspondent db config, but since we moved the `dump_schema` call to
outside of the `with_temporary_pool` block, we were using the default
connection pool.

Fixes rails#52776.
  • Loading branch information
rafaelfranca authored Sep 2, 2024
1 parent 08ee615 commit 01a5efc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion activerecord/lib/active_record/tasks/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ def prepare_all
# Dump schema for databases that were migrated.
if ActiveRecord.dump_schema_after_migration
dump_db_configs.each do |db_config|
dump_schema(db_config)
with_temporary_pool(db_config) do
dump_schema(db_config)
end
end
end

Expand Down
8 changes: 8 additions & 0 deletions railties/test/application/rake/multi_dbs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,17 @@ class ThreeMigration < ActiveRecord::Migration::Current
require "#{app_path}/config/environment"
app_file "db/migrate/01_one_migration.rb", <<-MIGRATION
class OneMigration < ActiveRecord::Migration::Current
def change
create_table :posts
end
end
MIGRATION

app_file "db/animals_migrate/02_two_migration.rb", <<-MIGRATION
class TwoMigration < ActiveRecord::Migration::Current
def change
create_table :dogs
end
end
MIGRATION

Expand All @@ -616,6 +622,8 @@ class TwoMigration < ActiveRecord::Migration::Current
assert File.exist?("db/schema.rb")
assert File.exist?("db/animals_schema.rb")

assert_not_equal File.read("db/schema.rb"), File.read("db/animals_schema.rb")

primary_mtime = File.mtime("db/schema.rb")
animals_mtime = File.mtime("db/animals_schema.rb")
end
Expand Down

0 comments on commit 01a5efc

Please sign in to comment.