mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add option to mute multiple database yaml warning
Adds an option to silence the warning that database configurations can throw when it's unparsable.
This commit is contained in:
parent
a50333b51e
commit
43d83e96c9
6 changed files with 44 additions and 1 deletions
|
@ -46,6 +46,10 @@ Rails.application.configure do
|
|||
# Highlight code that triggered database queries in logs.
|
||||
config.active_record.verbose_query_logs = true
|
||||
|
||||
# Show a warning when Rails couldn't parse your database.yml
|
||||
# for multiple databases.
|
||||
config.active_record.suppress_multiple_database_warning = false
|
||||
|
||||
# Debug mode disables concatenation and preprocessing of assets.
|
||||
# This option may cause significant delays in view rendering with a large
|
||||
# number of complex assets.
|
||||
|
|
|
@ -46,6 +46,10 @@ Rails.application.configure do
|
|||
# Highlight code that triggered database queries in logs.
|
||||
config.active_record.verbose_query_logs = true
|
||||
|
||||
# Show a warning when Rails couldn't parse your database.yml
|
||||
# for multiple databases.
|
||||
config.active_record.suppress_multiple_database_warning = false
|
||||
|
||||
# Debug mode disables concatenation and preprocessing of assets.
|
||||
# This option may cause significant delays in view rendering with a large
|
||||
# number of complex assets.
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
* Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
|
||||
message using `config.active_record.suppress_multiple_database_warning`.
|
||||
|
||||
*Omri Gabay*
|
||||
|
||||
* Connections can be granularly switched for abstract classes when `connected_to` is called.
|
||||
|
||||
This change allows `connected_to` to switch a `role` and/or `shard` for a single abstract class instead of all classes globally. Applications that want to use the new feature need to set `config.active_record.legacy_connection_handling` to `false` in their application configuration.
|
||||
|
|
|
@ -131,6 +131,12 @@ module ActiveRecord
|
|||
# potentially cause memory bloat.
|
||||
mattr_accessor :warn_on_records_fetched_greater_than, instance_writer: false
|
||||
|
||||
##
|
||||
# :singleton-method:
|
||||
# Show a warning when Rails couldn't parse your database.yml
|
||||
# for multiple databases.
|
||||
mattr_accessor :suppress_multiple_database_warning, instance_writer: false, default: false
|
||||
|
||||
mattr_accessor :maintain_test_schema, instance_accessor: false
|
||||
|
||||
class_attribute :belongs_to_required_by_default, instance_accessor: false
|
||||
|
|
|
@ -154,7 +154,9 @@ module ActiveRecord
|
|||
begin
|
||||
Rails.application.config.load_database_yaml
|
||||
rescue
|
||||
$stderr.puts "Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB."
|
||||
unless ActiveRecord::Base.suppress_multiple_database_warning
|
||||
$stderr.puts "Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB."
|
||||
end
|
||||
|
||||
{}
|
||||
end
|
||||
|
|
|
@ -1626,6 +1626,11 @@ module ApplicationTests
|
|||
assert_not ActiveRecord::Base.verbose_query_logs
|
||||
end
|
||||
|
||||
test "config.active_record.suppress_multiple_database_warning is false by default in development" do
|
||||
app "development"
|
||||
assert_not ActiveRecord::Base.suppress_multiple_database_warning
|
||||
end
|
||||
|
||||
test "config.annotations wrapping SourceAnnotationExtractor::Annotation class" do
|
||||
make_basic_app do |application|
|
||||
application.config.annotations.register_extensions("coffee") do |tag|
|
||||
|
@ -1865,6 +1870,23 @@ module ApplicationTests
|
|||
assert_equal({}, Rails.application.config.load_database_yaml)
|
||||
end
|
||||
|
||||
test "setup_initial_database_yaml does not print a warning if config.active_record.suppress_multiple_database_warning is true" do
|
||||
app_file "config/database.yml", <<-YAML
|
||||
<%= Rails.env %>:
|
||||
username: bobby
|
||||
adapter: sqlite3
|
||||
database: 'dev_db'
|
||||
YAML
|
||||
add_to_config <<-RUBY
|
||||
config.active_record.suppress_multiple_database_warning = true
|
||||
RUBY
|
||||
app "development"
|
||||
|
||||
assert_silent do
|
||||
ActiveRecord::Tasks::DatabaseTasks.setup_initial_database_yaml
|
||||
end
|
||||
end
|
||||
|
||||
test "raises with proper error message if no database configuration found" do
|
||||
FileUtils.rm("#{app_path}/config/database.yml")
|
||||
err = assert_raises RuntimeError do
|
||||
|
|
Loading…
Reference in a new issue