Skip to content

Commit d0b0c1c

Browse files
Merge pull request rails#43118 from mbayucot/43114-add-ssl-support-for-postgresql-dbconsole
Add SSL support for postgresql in `bin/rails dbconsole`
2 parents b71a9cc + 32612c6 commit d0b0c1c

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

railties/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Add SSL support for postgresql in `bin/rails dbconsole`.
2+
3+
Fixes #43114.
4+
5+
*Michael Bayucot*
6+
17
* Add support for comments above gem declaration in Rails application templates, e.g. `gem("nokogiri", comment: "For XML")`.
28

39
*Linas Juškevičius*

railties/lib/rails/commands/dbconsole/dbconsole_command.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ def start
4444
find_cmd_and_exec(["mysql", "mysql5"], *args)
4545

4646
when /^postgres|^postgis/
47-
ENV["PGUSER"] = config[:username] if config[:username]
48-
ENV["PGHOST"] = config[:host] if config[:host]
49-
ENV["PGPORT"] = config[:port].to_s if config[:port]
50-
ENV["PGPASSWORD"] = config[:password].to_s if config[:password] && @options[:include_password]
47+
ENV["PGUSER"] = config[:username] if config[:username]
48+
ENV["PGHOST"] = config[:host] if config[:host]
49+
ENV["PGPORT"] = config[:port].to_s if config[:port]
50+
ENV["PGPASSWORD"] = config[:password].to_s if config[:password] && @options[:include_password]
51+
ENV["PGSSLMODE"] = config[:sslmode].to_s if config[:sslmode]
52+
ENV["PGSSLCERT"] = config[:sslcert].to_s if config[:sslcert]
53+
ENV["PGSSLKEY"] = config[:sslkey].to_s if config[:sslkey]
54+
ENV["PGSSLROOTCERT"] = config[:sslrootcert].to_s if config[:sslrootcert]
5155
find_cmd_and_exec("psql", db_config.database)
5256

5357
when "sqlite3"

railties/test/commands/dbconsole_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ def test_postgresql_full
140140
assert_not_equal "q1w2e3", ENV["PGPASSWORD"]
141141
end
142142

143+
def test_postgresql_with_ssl
144+
start(adapter: "postgresql", database: "db", sslmode: "verify-full", sslcert: "client.crt", sslkey: "client.key", sslrootcert: "root.crt")
145+
assert_not aborted
146+
assert_equal ["psql", "db"], dbconsole.find_cmd_and_exec_args
147+
assert_equal "verify-full", ENV["PGSSLMODE"]
148+
assert_equal "client.crt", ENV["PGSSLCERT"]
149+
assert_equal "client.key", ENV["PGSSLKEY"]
150+
assert_equal "root.crt", ENV["PGSSLROOTCERT"]
151+
end
152+
143153
def test_postgresql_include_password
144154
start({ adapter: "postgresql", database: "db", username: "user", password: "q1w2e3" }, ["-p"])
145155
assert_not aborted

0 commit comments

Comments
 (0)