提交 b988ecb9 编写于 作者: E eileencodes

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.
上级 f9a8646d
...@@ -117,9 +117,9 @@ def current_config(options = {}) ...@@ -117,9 +117,9 @@ def current_config(options = {})
def create(*arguments) def create(*arguments)
configuration = arguments.first configuration = arguments.first
class_for_adapter(configuration["adapter"]).new(*arguments).create class_for_adapter(configuration["adapter"]).new(*arguments).create
$stdout.puts "Created database '#{configuration['database']}'" $stdout.puts "Created database '#{configuration['database']}'" if verbose?
rescue DatabaseAlreadyExists rescue DatabaseAlreadyExists
$stderr.puts "Database '#{configuration['database']}' already exists" $stderr.puts "Database '#{configuration['database']}' already exists" if verbose?
rescue Exception => error rescue Exception => error
$stderr.puts error $stderr.puts error
$stderr.puts "Couldn't create database for #{configuration.inspect}" $stderr.puts "Couldn't create database for #{configuration.inspect}"
...@@ -163,10 +163,14 @@ def drop_current(environment = env) ...@@ -163,10 +163,14 @@ def drop_current(environment = env)
} }
end end
def verbose?
ENV["VERBOSE"] ? ENV["VERBOSE"] != "false" : true
end
def migrate def migrate
check_target_version check_target_version
verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] != "false" : true verbose = verbose?
scope = ENV["SCOPE"] scope = ENV["SCOPE"]
verbose_was, Migration.verbose = Migration.verbose, verbose verbose_was, Migration.verbose = Migration.verbose, verbose
Base.connection.migration_context.migrate(target_version) do |migration| Base.connection.migration_context.migrate(target_version) do |migration|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册