Skip to content

Commit 01a5efc

Browse files
authored
Make sure we are using the correct connection pool when dumping the schema (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.
1 parent 08ee615 commit 01a5efc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

activerecord/lib/active_record/tasks/database_tasks.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ def prepare_all
211211
# Dump schema for databases that were migrated.
212212
if ActiveRecord.dump_schema_after_migration
213213
dump_db_configs.each do |db_config|
214-
dump_schema(db_config)
214+
with_temporary_pool(db_config) do
215+
dump_schema(db_config)
216+
end
215217
end
216218
end
217219

railties/test/application/rake/multi_dbs_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,17 @@ class ThreeMigration < ActiveRecord::Migration::Current
598598
require "#{app_path}/config/environment"
599599
app_file "db/migrate/01_one_migration.rb", <<-MIGRATION
600600
class OneMigration < ActiveRecord::Migration::Current
601+
def change
602+
create_table :posts
603+
end
601604
end
602605
MIGRATION
603606

604607
app_file "db/animals_migrate/02_two_migration.rb", <<-MIGRATION
605608
class TwoMigration < ActiveRecord::Migration::Current
609+
def change
610+
create_table :dogs
611+
end
606612
end
607613
MIGRATION
608614

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

625+
assert_not_equal File.read("db/schema.rb"), File.read("db/animals_schema.rb")
626+
619627
primary_mtime = File.mtime("db/schema.rb")
620628
animals_mtime = File.mtime("db/animals_schema.rb")
621629
end

0 commit comments

Comments
 (0)