未验证 提交 cfd4bff3 编写于 作者: E Eileen M. Uchitelle 提交者: GitHub

Merge pull request #37601 from Edouard-chin/ec-reset-connection-when-migrating

Reestablish connection to previous database after migrating:
......@@ -80,11 +80,14 @@ db_namespace = namespace :db do
desc "Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
task migrate: :load_config do
original_config = ActiveRecord::Base.connection_config
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
ActiveRecord::Base.establish_connection(db_config)
ActiveRecord::Tasks::DatabaseTasks.migrate
end
db_namespace["_dump"].invoke
ensure
ActiveRecord::Base.establish_connection(original_config)
end
# IMPORTANT: This task won't dump the schema if ActiveRecord::Base.dump_schema_after_migration is set to false
......
......@@ -231,6 +231,23 @@ def generate_models_for_animals
end
end
test "db:migrate set back connection to its original state" do
Dir.chdir(app_path) do
dummy_task = <<~RUBY
task foo: :environment do
Book.first
end
RUBY
app_file('Rakefile', dummy_task, 'a+')
generate_models_for_animals
assert_nothing_raised do
rails("db:migrate", "foo")
end
end
end
test "db:migrate and db:schema:dump and db:schema:load works on all databases" do
require "#{app_path}/config/environment"
db_migrate_and_schema_dump_and_load "schema"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册