Permalink
Browse files

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.
  • Loading branch information...
eileencodes committed Dec 20, 2017
1 parent f9a8646 commit b988ecb99ff6c8854e4b74ef8a7ade8d9ef5d954
Showing with 7 additions and 3 deletions.
  1. +7 −3 activerecord/lib/active_record/tasks/database_tasks.rb
@@ -117,9 +117,9 @@ def current_config(options = {})
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 @@ def drop_current(environment = env)
}
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|

0 comments on commit b988ecb

Please sign in to comment.