Skip to content

Commit

Permalink
PostgreSQL, Replace static connection param list by the one built int…
Browse files Browse the repository at this point in the history
…o libpq.

This makes the connection adapter future-proof regarding to new parameters.

To maintain backward compatibility, :requiressl is added by hand. It is
deprecated by PostgreSQL since 2003, but still accepted by libpq.
  • Loading branch information
larskanis committed Mar 25, 2015
1 parent 348377d commit 86a23fa
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@

module ActiveRecord
module ConnectionHandling # :nodoc:
VALID_CONN_PARAMS = [:host, :hostaddr, :port, :dbname, :user, :password, :connect_timeout,
:client_encoding, :options, :application_name, :fallback_application_name,
:keepalives, :keepalives_idle, :keepalives_interval, :keepalives_count,
:tty, :sslmode, :requiressl, :sslcompression, :sslcert, :sslkey,
:sslrootcert, :sslcrl, :requirepeer, :krbsrvname, :gsslib, :service]

# Establishes a connection to the database that's used by all Active Record objects
def postgresql_connection(config)
conn_params = config.symbolize_keys
Expand All @@ -37,7 +31,8 @@ def postgresql_connection(config)
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]

# Forward only valid config params to PGconn.connect.
conn_params.keep_if { |k, _| VALID_CONN_PARAMS.include?(k) }
valid_conn_param_keys = PGconn.conndefaults_hash.keys + [:requiressl]
conn_params.slice!(*valid_conn_param_keys)

# The postgres drivers don't allow the creation of an unconnected PGconn object,
# so just pass a nil connection object for the time being.
Expand Down

0 comments on commit 86a23fa

Please sign in to comment.