Skip to content

Commit 2845b42

Browse files
committed
Postgres, define dbconsole method to fix a handful of tests
1 parent 2de6c30 commit 2845b42

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/arjdbc/postgresql/adapter.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,25 @@ def jdbc_connection_class
787787
def new_client(conn_params, adapter_instance)
788788
jdbc_connection_class.new(conn_params, adapter_instance)
789789
end
790+
791+
def dbconsole(config, options = {})
792+
pg_config = config.configuration_hash
793+
794+
ENV["PGUSER"] = pg_config[:username] if pg_config[:username]
795+
ENV["PGHOST"] = pg_config[:host] if pg_config[:host]
796+
ENV["PGPORT"] = pg_config[:port].to_s if pg_config[:port]
797+
ENV["PGPASSWORD"] = pg_config[:password].to_s if pg_config[:password] && options[:include_password]
798+
ENV["PGSSLMODE"] = pg_config[:sslmode].to_s if pg_config[:sslmode]
799+
ENV["PGSSLCERT"] = pg_config[:sslcert].to_s if pg_config[:sslcert]
800+
ENV["PGSSLKEY"] = pg_config[:sslkey].to_s if pg_config[:sslkey]
801+
ENV["PGSSLROOTCERT"] = pg_config[:sslrootcert].to_s if pg_config[:sslrootcert]
802+
if pg_config[:variables]
803+
ENV["PGOPTIONS"] = pg_config[:variables].filter_map do |name, value|
804+
"-c #{name}=#{value.to_s.gsub(/[ \\]/, '\\\\\0')}" unless value == ":default" || value == :default
805+
end.join(" ")
806+
end
807+
find_cmd_and_exec("psql", config.database)
808+
end
790809
end
791810

792811
def initialize(...)

0 commit comments

Comments
 (0)