diff options
author | John Crepezzi <seejohnrun@github.com> | 2019-07-26 00:49:38 -0400 |
---|---|---|
committer | John Crepezzi <seejohnrun@github.com> | 2019-07-26 17:32:14 -0400 |
commit | 7df0eefacf1b6cbfdad8775ac86c6917f16bf859 (patch) | |
tree | 7e91b859acdb7230e5f82cfdb8310c953591e09b /activerecord/lib | |
parent | 41bc4c6207147a5eeafa323d763e66c06e61cacf (diff) | |
download | rails-7df0eefacf1b6cbfdad8775ac86c6917f16bf859.tar.gz rails-7df0eefacf1b6cbfdad8775ac86c6917f16bf859.tar.bz2 rails-7df0eefacf1b6cbfdad8775ac86c6917f16bf859.zip |
Allow separate database env variables per-connection
This commit adds a feature which allows separate database ENV variables
to be defined for each spec in a 3-tier config. The names for the
environment variables will be `#{name.upcase}_DATABASE_URL`
This commit also introduces a change in behavior around handling of
`DATABASE_URL`. Instead of using `DATABASE_URL` to change _all_ specs
in a multi-database configuration, it will now only affect the `primary`
connection.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/database_configurations.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/database_configurations.rb b/activerecord/lib/active_record/database_configurations.rb index 8baa0f5af6..db76cc8a7e 100644 --- a/activerecord/lib/active_record/database_configurations.rb +++ b/activerecord/lib/active_record/database_configurations.rb @@ -168,12 +168,19 @@ module ActiveRecord end def environment_url_config(env, spec_name, config) - url = ENV["DATABASE_URL"] + url = environment_value_for(spec_name) return unless url ActiveRecord::DatabaseConfigurations::UrlConfig.new(env, spec_name, url, config) end + def environment_value_for(spec_name) + spec_env_key = "#{spec_name.upcase}_DATABASE_URL" + url = ENV[spec_env_key] + url ||= ENV["DATABASE_URL"] if spec_name == "primary" + url + end + def method_missing(method, *args, &blk) case method when :each, :first |