From 1148b859d7a64339c36d83f6f3a9908fc345f647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 22 Apr 2025 16:37:43 +0200 Subject: [PATCH 1/4] Assume PG default port --- lib/strategy.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/strategy.ex b/lib/strategy.ex index bff79e5..9550cbe 100644 --- a/lib/strategy.ex +++ b/lib/strategy.ex @@ -31,7 +31,7 @@ defmodule LibclusterPostgres.Strategy do username: Keyword.fetch!(state.config, :username), password: Keyword.fetch!(state.config, :password), database: Keyword.fetch!(state.config, :database), - port: Keyword.fetch!(state.config, :port), + port: Keyword.get(state.config, :port, 5432), ssl: Keyword.get(state.config, :ssl), ssl_opts: Keyword.get(state.config, :ssl_opts), socket_options: Keyword.get(state.config, :socket_options, []), From 189465b1cbbb19f60becf6868438ebf456de5a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 22 Apr 2025 17:43:24 +0200 Subject: [PATCH 2/4] Prove port is optional --- test/strategy_test.exs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/strategy_test.exs b/test/strategy_test.exs index c9f317c..b175150 100644 --- a/test/strategy_test.exs +++ b/test/strategy_test.exs @@ -8,8 +8,6 @@ defmodule LibclusterPostgres.StrategyTest do username: "postgres", password: "postgres", database: "postgres", - port: 5432, - parameters: [], channel_name: "cluster" ] From 0a24e98a6d3d466f2a6de94124bc01d9f272b2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 22 Apr 2025 18:00:19 +0200 Subject: [PATCH 3/4] Use Keyword.take --- lib/strategy.ex | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/strategy.ex b/lib/strategy.ex index 9550cbe..841b9a2 100644 --- a/lib/strategy.ex +++ b/lib/strategy.ex @@ -18,6 +18,9 @@ defmodule LibclusterPostgres.Strategy do alias Cluster.Strategy alias Cluster.Logger + @postgrex_keys [:hostname, :username, :password, :database, :port] ++ + [:ssl, :ssl_opts, :socket_options, :parameters] + def start_link(args), do: GenServer.start_link(__MODULE__, args) @spec init([%{:config => any(), :meta => any(), optional(any()) => any()}, ...]) :: @@ -26,18 +29,9 @@ defmodule LibclusterPostgres.Strategy do def init([state]) do channel_name = Keyword.get(state.config, :channel_name, clean_cookie(Node.get_cookie())) - opts = [ - hostname: Keyword.fetch!(state.config, :hostname), - username: Keyword.fetch!(state.config, :username), - password: Keyword.fetch!(state.config, :password), - database: Keyword.fetch!(state.config, :database), - port: Keyword.get(state.config, :port, 5432), - ssl: Keyword.get(state.config, :ssl), - ssl_opts: Keyword.get(state.config, :ssl_opts), - socket_options: Keyword.get(state.config, :socket_options, []), - parameters: Keyword.get(state.config, :parameters, []), - channel_name: channel_name - ] + opts = + [channel_name: channel_name] ++ + Keyword.take(state.config, @postgrex_keys) config = state.config From 05cb6cad32e4eb86b40413e7ded1c16882029817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 18 Jun 2025 07:34:06 -0700 Subject: [PATCH 4/4] Update lib/strategy.ex Co-authored-by: Todd Pickell --- lib/strategy.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/strategy.ex b/lib/strategy.ex index 841b9a2..f2e6361 100644 --- a/lib/strategy.ex +++ b/lib/strategy.ex @@ -19,7 +19,7 @@ defmodule LibclusterPostgres.Strategy do alias Cluster.Logger @postgrex_keys [:hostname, :username, :password, :database, :port] ++ - [:ssl, :ssl_opts, :socket_options, :parameters] + [:ssl, :ssl_opts, :socket, :socket_dir, :socket_options, :parameters] def start_link(args), do: GenServer.start_link(__MODULE__, args)