aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2014-04-08 03:54:23 +0930
committerMatthew Draper <matthew@trebex.net>2014-04-08 15:14:26 +0930
commit2b817cde622e625f08a638d909f3e9b12f0b3066 (patch)
treebd7e4343c208222e3b23035ae0992e6cd994a39e /activerecord/lib/active_record
parent77692ff9c32c1b4999bd4ff51af6b84186729478 (diff)
downloadrails-2b817cde622e625f08a638d909f3e9b12f0b3066.tar.gz
rails-2b817cde622e625f08a638d909f3e9b12f0b3066.tar.bz2
rails-2b817cde622e625f08a638d909f3e9b12f0b3066.zip
Only apply DATABASE_URL for Rails.env
As we like ENV vars, also support DATABASE_URL_#{env}, for more obscure use cases.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_handling.rb42
1 files changed, 14 insertions, 28 deletions
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb
index bbb866cedf..5a83797ee5 100644
--- a/activerecord/lib/active_record/connection_handling.rb
+++ b/activerecord/lib/active_record/connection_handling.rb
@@ -58,9 +58,8 @@ module ActiveRecord
end
class MergeAndResolveDefaultUrlConfig # :nodoc:
- def initialize(raw_configurations, url = ENV['DATABASE_URL'])
+ def initialize(raw_configurations)
@raw_config = raw_configurations.dup
- @url = url
end
# Returns fully resolved connection hashes.
@@ -71,35 +70,22 @@ module ActiveRecord
private
def config
- if @url
- raw_merged_into_default
- else
- @raw_config
+ cfg = Hash.new do |hash, key|
+ entry = @raw_config[key]
+ env_url = nil
+ if key.to_s == DEFAULT_ENV.call.to_s
+ env_url = ENV["DATABASE_URL"]
+ end
+ env_url ||= ENV["DATABASE_URL_#{key.upcase}"]
+ entry ||= {} if env_url
+ entry.merge!("url" => env_url) { |h, v1, v2| v1 || v2 } if entry.is_a?(Hash)
+ hash[key] = entry if entry
end
- end
- def raw_merged_into_default
- default = default_url_hash
+ @raw_config.keys.each {|k| cfg[k] }
+ cfg[DEFAULT_ENV.call.to_s]
- @raw_config.each do |env, values|
- default[env] = values || {}
- default[env].merge!("url" => @url) { |h, v1, v2| v1 || v2 } if default[env].is_a?(Hash)
- end
- default
- end
-
- # When the raw configuration is not present and ENV['DATABASE_URL']
- # is available we return a hash with the connection information in
- # the connection URL. This hash responds to any string key with
- # resolved connection information.
- def default_url_hash
- Hash.new do |hash, key|
- hash[key] = if key.is_a? String
- ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(@url).to_hash
- else
- nil
- end
- end
+ cfg
end
end