aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-02-23 08:12:54 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-02-23 08:13:09 -0800
commit79887593c18919fed49f441d64236362cb755872 (patch)
treeac79183e1bf9d6ec978ced78f25bc38702a46bbd
parentb2c2d32908beed678b087ec4ed735cc9ff87ad7a (diff)
downloadrails-79887593c18919fed49f441d64236362cb755872.tar.gz
rails-79887593c18919fed49f441d64236362cb755872.tar.bz2
rails-79887593c18919fed49f441d64236362cb755872.zip
reestablish previous connection after creating all databases
creating all databases mutates the connection pool. This patch restores the connection pool to the connection spec established before creating all databases. Fixes #23279
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb4
-rw-r--r--railties/test/application/test_runner_test.rb13
2 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index 8f52e9068a..7dc41fa98c 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -116,7 +116,11 @@ module ActiveRecord
end
def create_all
+ old_pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool(ActiveRecord::Base)
each_local_configuration { |configuration| create configuration }
+ if old_pool
+ ActiveRecord::Base.connection_handler.establish_connection(ActiveRecord::Base, old_pool.spec)
+ end
end
def create_current(environment = env)
diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb
index 1e0fbddb58..a1735db5b3 100644
--- a/railties/test/application/test_runner_test.rb
+++ b/railties/test/application/test_runner_test.rb
@@ -502,6 +502,19 @@ module ApplicationTests
assert_match '1 runs, 1 assertions', output
end
+ def test_rails_db_create_all_restores_db_connection
+ create_test_file :models, 'account'
+ output = Dir.chdir(app_path) { `bin/rails db:create:all db:migrate && echo ".tables" | rails dbconsole` }
+ assert_match "ar_internal_metadata", output, "tables should be dumped"
+ end
+
+ def test_rails_db_create_all_restores_db_connection_after_drop
+ create_test_file :models, 'account'
+ Dir.chdir(app_path) { `bin/rails db:create:all` } # create all to avoid warnings
+ output = Dir.chdir(app_path) { `bin/rails db:drop:all db:create:all db:migrate && echo ".tables" | rails dbconsole` }
+ assert_match "ar_internal_metadata", output, "tables should be dumped"
+ end
+
def test_rake_passes_TESTOPTS_to_minitest
create_test_file :models, 'account'
output = Dir.chdir(app_path) { `bin/rake test TESTOPTS=-v` }