changed
hex_metadata.config
|
@@ -1,7 +1,7 @@
|
1
1
|
{<<"links">>,
|
2
2
|
[{<<"Source code">>,<<"https://github.com/electric-sql/phoenix_sync">>}]}.
|
3
3
|
{<<"name">>,<<"phoenix_sync">>}.
|
4
|
- {<<"version">>,<<"0.3.3">>}.
|
4
|
+ {<<"version">>,<<"0.3.4">>}.
|
5
5
|
{<<"description">>,
|
6
6
|
<<"Real-time sync for Postgres-backed Phoenix applications.">>}.
|
7
7
|
{<<"elixir">>,<<"~> 1.17">>}.
|
|
@@ -9,15 +9,15 @@
|
9
9
|
{<<"licenses">>,[<<"Apache-2.0">>]}.
|
10
10
|
{<<"files">>,
|
11
11
|
[<<"lib">>,<<"lib/phoenix">>,<<"lib/phoenix/sync">>,
|
12
|
- <<"lib/phoenix/sync/adapter">>,<<"lib/phoenix/sync/adapter/plug_api.ex">>,
|
13
12
|
<<"lib/phoenix/sync/plug">>,<<"lib/phoenix/sync/plug/utils.ex">>,
|
14
|
- <<"lib/phoenix/sync/gateway.ex">>,<<"lib/phoenix/sync/electric">>,
|
15
|
- <<"lib/phoenix/sync/electric/client_adapter.ex">>,
|
16
|
- <<"lib/phoenix/sync/adapter.ex">>,<<"lib/phoenix/sync/controller.ex">>,
|
17
13
|
<<"lib/phoenix/sync/predefined_shape.ex">>,
|
18
|
- <<"lib/phoenix/sync/application.ex">>,<<"lib/phoenix/sync/client.ex">>,
|
19
|
- <<"lib/phoenix/sync/live_view.ex">>,<<"lib/phoenix/sync/router.ex">>,
|
20
|
- <<"lib/phoenix/sync/electric.ex">>,<<"lib/phoenix/sync/plug.ex">>,
|
14
|
+ <<"lib/phoenix/sync/adapter.ex">>,<<"lib/phoenix/sync/adapter">>,
|
15
|
+ <<"lib/phoenix/sync/adapter/plug_api.ex">>,<<"lib/phoenix/sync/client.ex">>,
|
16
|
+ <<"lib/phoenix/sync/controller.ex">>,<<"lib/phoenix/sync/electric">>,
|
17
|
+ <<"lib/phoenix/sync/electric/client_adapter.ex">>,
|
18
|
+ <<"lib/phoenix/sync/gateway.ex">>,<<"lib/phoenix/sync/live_view.ex">>,
|
19
|
+ <<"lib/phoenix/sync/plug.ex">>,<<"lib/phoenix/sync/router.ex">>,
|
20
|
+ <<"lib/phoenix/sync/application.ex">>,<<"lib/phoenix/sync/electric.ex">>,
|
21
21
|
<<"lib/phoenix/sync.ex">>,<<".formatter.exs">>,<<"mix.exs">>,
|
22
22
|
<<"README.md">>,<<"LICENSE">>]}.
|
23
23
|
{<<"requirements">>,
|
|
@@ -49,11 +49,11 @@
|
49
49
|
[{<<"name">>,<<"electric">>},
|
50
50
|
{<<"app">>,<<"electric">>},
|
51
51
|
{<<"optional">>,true},
|
52
|
- {<<"requirement">>,<<"== 1.0.0-beta.20">>},
|
52
|
+ {<<"requirement">>,<<"== 1.0.1">>},
|
53
53
|
{<<"repository">>,<<"hexpm">>}],
|
54
54
|
[{<<"name">>,<<"electric_client">>},
|
55
55
|
{<<"app">>,<<"electric_client">>},
|
56
56
|
{<<"optional">>,false},
|
57
|
- {<<"requirement">>,<<">= 0.3.0-beta.4">>},
|
57
|
+ {<<"requirement">>,<<"== 0.3.0">>},
|
58
58
|
{<<"repository">>,<<"hexpm">>}]]}.
|
59
59
|
{<<"build_tools">>,[<<"mix">>]}.
|
changed
lib/phoenix/sync/electric.ex
|
@@ -320,7 +320,7 @@ defmodule Phoenix.Sync.Electric do
|
320
320
|
defp start_embedded(env, mode, db_config_fun, message) do
|
321
321
|
db_config =
|
322
322
|
db_config_fun.()
|
323
|
- |> Keyword.update!(:connection_opts, &Electric.Utils.obfuscate_password/1)
|
323
|
+ |> obfuscate_credentials()
|
324
324
|
|
325
325
|
electric_config = core_configuration(env, db_config)
|
326
326
|
|
|
@@ -367,6 +367,24 @@ defmodule Phoenix.Sync.Electric do
|
367
367
|
opts
|
368
368
|
end
|
369
369
|
end
|
370
|
+
|
371
|
+ defp obfuscate_credentials(opts) do
|
372
|
+ opts
|
373
|
+ |> Keyword.update!(:replication_connection_opts, &Electric.Utils.obfuscate_password/1)
|
374
|
+ |> then(fn opts ->
|
375
|
+ case Keyword.fetch(opts, :query_connection_opts) do
|
376
|
+ :error ->
|
377
|
+ opts
|
378
|
+
|
379
|
+ {:ok, query_connection_opts} ->
|
380
|
+ Keyword.put(
|
381
|
+ opts,
|
382
|
+ :query_connection_opts,
|
383
|
+ Electric.Utils.obfuscate_password(query_connection_opts)
|
384
|
+ )
|
385
|
+ end
|
386
|
+ end)
|
387
|
+ end
|
370
388
|
else
|
371
389
|
defp start_embedded(_env, _mode, _db_config_fun, _message) do
|
372
390
|
{:error,
|
|
@@ -428,13 +446,20 @@ defmodule Phoenix.Sync.Electric do
|
428
446
|
defp validate_database_config(_env, mode, opts) do
|
429
447
|
case Keyword.pop(opts, :repo, nil) do
|
430
448
|
{nil, opts} ->
|
431
|
- case Keyword.fetch(opts, :connection_opts) do
|
432
|
- {:ok, connection_opts} when is_list(connection_opts) ->
|
433
|
- # TODO: validate reasonable connection opts?
|
434
|
- {:start, fn -> opts end,
|
435
|
- "Starting Electric replication stream from postgresql://#{connection_opts[:host]}:#{connection_opts[:port] || 5432}/#{connection_opts[:database]}"}
|
449
|
+ case {Keyword.get(opts, :connection_opts),
|
450
|
+ Keyword.get(opts, :replication_connection_opts)} do
|
451
|
+ {[_ | _] = connection_opts, _} ->
|
452
|
+ opts =
|
453
|
+ opts
|
454
|
+ |> Keyword.delete(:connection_opts)
|
455
|
+ |> Keyword.put(:replication_connection_opts, connection_opts)
|
436
456
|
|
437
|
- :error ->
|
457
|
+ {:start, fn -> opts end, start_message(connection_opts)}
|
458
|
+
|
459
|
+ {nil, [_ | _] = connection_opts} ->
|
460
|
+ {:start, fn -> opts end, start_message(connection_opts)}
|
461
|
+
|
462
|
+ {nil, nil} ->
|
438
463
|
case mode do
|
439
464
|
:embedded ->
|
440
465
|
{:error,
|
|
@@ -450,14 +475,21 @@ defmodule Phoenix.Sync.Electric do
|
450
475
|
repo_config = apply(repo, :config, [])
|
451
476
|
|
452
477
|
{:start,
|
453
|
- fn -> Keyword.put(opts, :connection_opts, convert_repo_config(repo_config)) end,
|
454
|
- "Starting Electric replication stream using #{repo} configuration"}
|
478
|
+ fn ->
|
479
|
+ connection_opts = convert_repo_config(repo_config)
|
480
|
+
|
481
|
+ Keyword.put(opts, :replication_connection_opts, connection_opts)
|
482
|
+ end, "Starting Electric replication stream using #{repo} configuration"}
|
455
483
|
else
|
456
484
|
{:error, "#{inspect(repo)} is not a valid Ecto.Repo module"}
|
457
485
|
end
|
458
486
|
end
|
459
487
|
end
|
460
488
|
|
489
|
+ defp start_message(connection_opts) do
|
490
|
+ "Starting Electric replication stream from postgresql://#{connection_opts[:host]}:#{connection_opts[:port] || 5432}/#{connection_opts[:database]}"
|
491
|
+ end
|
492
|
+
|
461
493
|
if @electric_available? do
|
462
494
|
defp convert_repo_config(repo_config) do
|
463
495
|
expected_keys = Electric.connection_opts_schema() |> Keyword.keys()
|
changed
mix.exs
|
@@ -2,7 +2,7 @@ defmodule Phoenix.Sync.MixProject do
|
2
2
|
use Mix.Project
|
3
3
|
|
4
4
|
# Remember to update the README when you change the version
|
5
|
- @version "0.3.3"
|
5
|
+ @version "0.3.4"
|
6
6
|
|
7
7
|
def project do
|
8
8
|
[
|
|
@@ -38,8 +38,8 @@ defmodule Phoenix.Sync.MixProject do
|
38
38
|
{:ecto_sql, "~> 3.10", optional: true},
|
39
39
|
# require an exact version because electric moves very quickly atm
|
40
40
|
# and a more generous specification would inevitably break.
|
41
|
- {:electric, "== 1.0.0-beta.20", optional: true},
|
42
|
- {:electric_client, ">= 0.3.0-beta.4"}
|
41
|
+ {:electric, "== 1.0.1", optional: true},
|
42
|
+ {:electric_client, "== 0.3.0"}
|
43
43
|
] ++ deps_for_env(Mix.env())
|
44
44
|
end
|