instance method resolve_pool_config

Ruby on Rails 7.0.10

Since v6.1.7.10 Private

Available in: v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

resolve_pool_config(config, owner_name, role, shard)

Returns an instance of PoolConfig for a given adapter. Accepts a hash one layer deep that contains all connection information.

Example

config = { "production" => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3" } }
pool_config = Base.configurations.resolve_pool_config(:production)
pool_config.db_config.configuration_hash
# => { host: "localhost", database: "foo", adapter: "sqlite3" }

Parameters

config req
owner_name req
role req
shard req
Source
# File activerecord/lib/active_record/connection_adapters/abstract/connection_handler.rb, line 258
        def resolve_pool_config(config, owner_name, role, shard)
          db_config = Base.configurations.resolve(config)

          raise(AdapterNotSpecified, "database configuration does not specify adapter") unless db_config.adapter

          # Require the adapter itself and give useful feedback about
          #   1. Missing adapter gems and
          #   2. Adapter gems' missing dependencies.
          path_to_adapter = "active_record/connection_adapters/#{db_config.adapter}_adapter"
          begin
            require path_to_adapter
          rescue LoadError => e
            # We couldn't require the adapter itself. Raise an exception that
            # points out config typos and missing gems.
            if e.path == path_to_adapter
              # We can assume that a non-builtin adapter was specified, so it's
              # either misspelled or missing from Gemfile.
              raise LoadError, "Could not load the '#{db_config.adapter}' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile.", e.backtrace

              # Bubbled up from the adapter require. Prefix the exception message
              # with some guidance about how to address it and reraise.
            else
              raise LoadError, "Error loading the '#{db_config.adapter}' Active Record adapter. Missing a gem it depends on? #{e.message}", e.backtrace
            end
          end

          unless ActiveRecord::Base.respond_to?(db_config.adapter_method)
            raise AdapterNotFound, "database configuration specifies nonexistent #{db_config.adapter} adapter"
          end

          ConnectionAdapters::PoolConfig.new(owner_name, db_config, role, shard)
        end

Defined in activerecord/lib/active_record/connection_adapters/abstract/connection_handler.rb line 258 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ConnectionAdapters::ConnectionHandler

Type at least 2 characters to search.

↑↓ navigate · open · esc close