From 615e0dcdf1391a8b71ad6556c2e7b9cedf6ffa12 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Wed, 9 Apr 2014 00:17:13 +0930 Subject: Less ambition, more deprecation The "DATABASE_URL_*" idea was moving in the wrong direction. Instead, let's deprecate the situation where we end up using ENV['DATABASE_URL'] at all: the Right Way is to explicitly include it in database.yml with ERB. --- .../lib/active_record/connection_handling.rb | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb index f83829bb26..3667a42864 100644 --- a/activerecord/lib/active_record/connection_handling.rb +++ b/activerecord/lib/active_record/connection_handling.rb @@ -72,24 +72,24 @@ module ActiveRecord private def config @raw_config.dup.tap do |cfg| - urls_in_environment.each do |key, url| - cfg[key] ||= {} - cfg[key]["url"] ||= url - end - end - end - - def urls_in_environment - {}.tap do |mapping| - ENV.each do |k, v| - if k =~ /\ADATABASE_URL_(.*)/ - mapping[$1.downcase] = v + if url = ENV['DATABASE_URL'] + if cfg[@env] + if cfg[@env]["url"] + # Nothing to do + else + ActiveSupport::Deprecation.warn "Overriding database configuration with DATABASE_URL without using an ERB tag in database.yml is deprecated. Please update the entry for #{@env.inspect}:\n\n" \ + " #{@env}:\n url: <%= ENV['DATABASE_URL'] %>\n\n"\ + "This will be required in Rails 4.2" + cfg[@env]["url"] = url + end + else + cfg[@env] = {} + ActiveSupport::Deprecation.warn "Supplying DATABASE_URL without a matching entry in database.yml is deprecated. Please add an entry for #{@env.inspect}:\n\n" \ + " #{@env}:\n url: <%= ENV['DATABASE_URL'] %>\n\n"\ + "This will be required in Rails 4.2" + cfg[@env]["url"] ||= url end end - - # Check for this last, because it is prioritised over the - # longer "DATABASE_URL_#{@env}" spelling - mapping[@env] = ENV['DATABASE_URL'] if ENV['DATABASE_URL'] end end end -- cgit v1.2.3