Sha256: b078dbcdd2fa6bc2688d593c72b753fcea03f9b004c86b8bf3c4f85a11e256ba

Contents?: true

Size: 1.23 KB

Versions: 10

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Switchman
  module ActiveRecord
    module DatabaseConfigurations
      private

      # key difference: assumes a hybrid two-tier structure; each third tier
      # is implicitly named, and their config is constructing by merging into
      # its parent
      def build_configs(configs)
        return configs.configurations if configs.is_a?(DatabaseConfigurations)
        return configs if configs.is_a?(Array)

        db_configs = configs.flat_map do |env_name, config|
          roles = config.keys.select { |k| config[k].is_a?(Hash) }
          base_config = config.except(*roles)

          name = "#{env_name}/primary"
          name = 'primary' if env_name == default_env
          base_db = build_db_config_from_raw_config(env_name, name, base_config)
          [base_db] + roles.map do |role|
            build_db_config_from_raw_config(env_name, "#{env_name}/#{role}",
                                            base_config.merge(config[role]).merge(replica: true))
          end
        end

        db_configs << environment_url_config(default_env, 'primary', {}) unless db_configs.find(&:for_current_env?)

        merge_db_environment_variables(default_env, db_configs.compact)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
switchman-3.0.9 lib/switchman/active_record/database_configurations.rb
switchman-3.0.8 lib/switchman/active_record/database_configurations.rb
switchman-3.0.7 lib/switchman/active_record/database_configurations.rb
switchman-3.0.6 lib/switchman/active_record/database_configurations.rb
switchman-3.0.5 lib/switchman/active_record/database_configurations.rb
switchman-3.0.4 lib/switchman/active_record/database_configurations.rb
switchman-3.0.3 lib/switchman/active_record/database_configurations.rb
switchman-3.0.2 lib/switchman/active_record/database_configurations.rb
switchman-3.0.1 lib/switchman/active_record/database_configurations.rb
switchman-3.0.0 lib/switchman/active_record/database_configurations.rb