Skip to content

Commit

Permalink
reestablish previous connection after creating all databases
Browse files Browse the repository at this point in the history
creating all databases mutates the connection pool.  This patch restores
the connection pool to the connection spec established before creating
all databases.  Fixes #23279
  • Loading branch information
tenderlove committed Feb 23, 2016
1 parent b2c2d32 commit 7988759
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions activerecord/lib/active_record/tasks/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ def create(*arguments)
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)
Expand Down
13 changes: 13 additions & 0 deletions railties/test/application/test_runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,19 @@ def test_pass_TEST_env_on_rake_test
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` }
Expand Down

1 comment on commit 7988759

@schneems
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks ❤️

Please sign in to comment.