From 8737dffce73a37dff073dfe0af8931efd08632c5 Mon Sep 17 00:00:00 2001 From: Eileen Uchitelle Date: Fri, 31 Aug 2018 10:53:20 -0400 Subject: Add replica? check to DatabaseConfig Checks if the config has a "replica" key, if so the configuration is for a replica database. This is useful for excluding replicas from the configurations list when creating the rake tasks or running rake tasks. For example, we don't want to create the primary and primary_readonly. They're the same database. --- .../lib/active_record/database_configurations/database_config.rb | 4 ++++ activerecord/lib/active_record/database_configurations/hash_config.rb | 4 ++++ activerecord/lib/active_record/database_configurations/url_config.rb | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/activerecord/lib/active_record/database_configurations/database_config.rb b/activerecord/lib/active_record/database_configurations/database_config.rb index 4a58115cd5..6250827b34 100644 --- a/activerecord/lib/active_record/database_configurations/database_config.rb +++ b/activerecord/lib/active_record/database_configurations/database_config.rb @@ -13,6 +13,10 @@ module ActiveRecord @spec_name = spec_name end + def replica? + raise NotImplementedError + end + def url_config? false end diff --git a/activerecord/lib/active_record/database_configurations/hash_config.rb b/activerecord/lib/active_record/database_configurations/hash_config.rb index 2ee218c730..249107ebeb 100644 --- a/activerecord/lib/active_record/database_configurations/hash_config.rb +++ b/activerecord/lib/active_record/database_configurations/hash_config.rb @@ -31,6 +31,10 @@ module ActiveRecord super(env_name, spec_name) @config = config end + + def replica? + config["replica"] + end end end end diff --git a/activerecord/lib/active_record/database_configurations/url_config.rb b/activerecord/lib/active_record/database_configurations/url_config.rb index c3d9798c37..181f04c3fd 100644 --- a/activerecord/lib/active_record/database_configurations/url_config.rb +++ b/activerecord/lib/active_record/database_configurations/url_config.rb @@ -41,6 +41,10 @@ module ActiveRecord true end + def replica? + config["replica"] + end + private def build_config(original_config, url) if /^jdbc:/.match?(url) -- cgit v1.2.3