Skip to content

Commit

Permalink
Allow socket usage in DATABASE_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
dlackty committed Mar 2, 2024
1 parent 00b54e5 commit ffee0e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/active_record/connection_adapters/trilogy_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ def initialize_type_map(m)
end

def initialize(connection, logger, connection_options, config)
config = config.dup

# Trilogy ignores `socket` if `host` is set. We want the opposite to allow
# configuring UNIX domain sockets via `DATABASE_URL`.
config.delete(:host) if config[:socket]

super
# Ensure that we're treating prepared_statements in the same way that Rails 7.1 does
@prepared_statements = self.class.type_cast_config_to_boolean(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,13 @@ class Post < ActiveRecord::Base; end
assert_equal current_sql_mode, ["STRICT_ALL_TABLES"]
end

test "socket has precedence over host" do
error = assert_raises ActiveRecord::ConnectionNotEstablished do
trilogy_adapter(host: "invalid", port: 12345, socket: "/var/invalid.sock").connect!
end
assert_includes error.message, "/var/invalid.sock"
end

def trilogy_adapter_with_connection(connection, **config_overrides)
ActiveRecord::ConnectionAdapters::TrilogyAdapter
.new(connection, nil, {}, @configuration.merge(config_overrides))
Expand Down

0 comments on commit ffee0e4

Please sign in to comment.