aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2017-12-20 17:05:11 -0500
committereileencodes <eileencodes@gmail.com>2018-02-05 13:35:05 -0500
commitb988ecb99ff6c8854e4b74ef8a7ade8d9ef5d954 (patch)
tree866439dfcaabc8bedec6ce27f9fba9accd2c671d /activerecord
parentf9a8646d8150956524a72af9f85c832bbe84061b (diff)
downloadrails-b988ecb99ff6c8854e4b74ef8a7ade8d9ef5d954.tar.gz
rails-b988ecb99ff6c8854e4b74ef8a7ade8d9ef5d954.tar.bz2
rails-b988ecb99ff6c8854e4b74ef8a7ade8d9ef5d954.zip
Add ability to turn off verbose for database tasks
You could use the `VERBOSE` env var to turn off output for migrations tasks but you couldn't use it for other tasks. This change moves the `verbose?` check to a method so we can also use it in create and drop respectively. tenderlove and I noticed this as part of the ongoing work in parallel testing. When the parallel tests boot the app needs to create new databases for each worker. The output from these is unnecessary but there was previously no way to turn it off. Now if `VERBOSE=false` is passes to `bin/rails db:create` the text "Created blah blah db" will no longer be output.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index ed589f9b43..d5b457721a 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -117,9 +117,9 @@ module ActiveRecord
def create(*arguments)
configuration = arguments.first
class_for_adapter(configuration["adapter"]).new(*arguments).create
- $stdout.puts "Created database '#{configuration['database']}'"
+ $stdout.puts "Created database '#{configuration['database']}'" if verbose?
rescue DatabaseAlreadyExists
- $stderr.puts "Database '#{configuration['database']}' already exists"
+ $stderr.puts "Database '#{configuration['database']}' already exists" if verbose?
rescue Exception => error
$stderr.puts error
$stderr.puts "Couldn't create database for #{configuration.inspect}"
@@ -163,10 +163,14 @@ module ActiveRecord
}
end
+ def verbose?
+ ENV["VERBOSE"] ? ENV["VERBOSE"] != "false" : true
+ end
+
def migrate
check_target_version
- verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] != "false" : true
+ verbose = verbose?
scope = ENV["SCOPE"]
verbose_was, Migration.verbose = Migration.verbose, verbose
Base.connection.migration_context.migrate(target_version) do |migration|