1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed db:prepare task to not touch schema when dump_schema_after_migration is false.

This commit is contained in:
Wojciech Wnętrzak 2019-07-24 08:50:23 +02:00
parent 31105c81cc
commit 5c1f6d1ff6
No known key found for this signature in database
GPG key ID: 0EABD3BE530ECAC6
2 changed files with 20 additions and 3 deletions

View file

@ -297,10 +297,11 @@ db_namespace = namespace :db do
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
ActiveRecord::Base.establish_connection(db_config.config)
ActiveRecord::Tasks::DatabaseTasks.migrate
# Skipped when no database
ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config.config, ActiveRecord::Base.schema_format, db_config.spec_name)
ActiveRecord::Tasks::DatabaseTasks.migrate
if ActiveRecord::Base.dump_schema_after_migration
ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config.config, ActiveRecord::Base.schema_format, db_config.spec_name)
end
rescue ActiveRecord::NoDatabaseError
ActiveRecord::Tasks::DatabaseTasks.create_current(db_config.env_name, db_config.spec_name)

View file

@ -630,6 +630,22 @@ module ApplicationTests
assert_match(/CreateRecipes: migrated/, output)
end
end
test "db:prepare does not touch schema when dumping is disabled" do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "db:create", "db:migrate"
app_file "db/schema.rb", "Not touched"
app_file "config/initializers/disable_dumping_schema.rb", <<-RUBY
Rails.application.config.active_record.dump_schema_after_migration = false
RUBY
rails "db:prepare"
assert_equal("Not touched", File.read("db/schema.rb").strip)
end
end
end
end
end