Skip to content

Commit c9b25c8

Browse files
committed
Allow pg query param syntax
Allow configuring Postgres password through the socket URL. For example: ```ruby ActiveRecord::DatabaseConfigurations::UrlConfig.new( :production, :production, 'postgres:///?user=user&password=secret&dbname=app', {} ).configuration_hash ``` will now return, ```ruby { :user=>"user", :password=>"secret", :dbname=>"app", :adapter=>"postgresql" } ```
1 parent ee98178 commit c9b25c8

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

activerecord/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@
8080

8181
*Kevin Newton*
8282

83+
* Allow configuring Postgres password through the socket URL.
84+
85+
For example:
86+
```ruby
87+
ActiveRecord::DatabaseConfigurations::UrlConfig.new(
88+
:production, :production, 'postgres:///?user=user&password=secret&dbname=app', {}
89+
).configuration_hash
90+
```
91+
92+
will now return,
93+
94+
```ruby
95+
{ :user=>"user", :password=>"secret", :dbname=>"app", :adapter=>"postgresql" }
96+
```
97+
98+
*Abeid Ahmed*
99+
83100
* Fix `eager_loading?` when ordering with `Symbol`
84101

85102
`eager_loading?` is triggered correctly when using `order` with symbols.

activerecord/lib/active_record/database_configurations/connection_url_resolver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def raw_config
6767
database: uri.opaque
6868
)
6969
else
70-
query_hash.merge(
70+
query_hash.reverse_merge(
7171
adapter: @adapter,
7272
username: uri.user,
7373
password: uri.password,

activerecord/test/cases/database_configurations/resolver_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ def test_url_sub_key_merges_correctly
6262
}, pool_config.configuration_hash)
6363
end
6464

65+
def test_url_sub_key_merges_correctly_when_query_param
66+
hash = { "url" => "abstract:///?user=user&password=passwd&dbname=app" }
67+
pool_config = resolve_db_config :production, "production" => hash
68+
69+
assert_equal({
70+
adapter: "abstract",
71+
user: "user",
72+
password: "passwd",
73+
dbname: "app"
74+
}, pool_config.configuration_hash)
75+
end
76+
6577
def test_url_host_no_db
6678
pool_config = resolve_db_config "abstract://foo?encoding=utf8"
6779
assert_equal({

0 commit comments

Comments
 (0)