Skip to content

Commit 22b2ec6

Browse files
committed
Update to support electric 1.4
- Fix invalid protocol typing - Support more esoteric version tuples
1 parent aaeaef7 commit 22b2ec6

27 files changed

Lines changed: 389 additions & 224 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ electric_phoenix-*.tar
2424

2525
# Temporary files, for example, from tests.
2626
/tmp/
27+
.claude
28+

apps/phoenix_sync_example/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ defmodule PhoenixSyncExample.MixProject do
5050
{:dns_cluster, "~> 0.1.1"},
5151
{:bandit, "~> 1.5"},
5252
{:phoenix_sync, path: "../.."},
53-
{:electric, "~> 1.1.0"}
53+
{:electric, "~> 1.0"}
5454
]
5555
end
5656

apps/phoenix_sync_example/mix.lock

Lines changed: 18 additions & 17 deletions
Large diffs are not rendered by default.

apps/plug_sync/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule PlugSync.MixProject do
2626
{:bandit, "~> 1.0"},
2727
{:postgrex, "~> 0.21"},
2828
{:ecto_sql, "~> 3.0"},
29-
{:electric, "~> 1.1.2"},
29+
{:electric, "~> 1.0"},
3030
{:phoenix_sync, [path: "../..", override: true]},
3131
{:igniter, "~> 0.6"}
3232
]

apps/plug_sync/mix.lock

Lines changed: 17 additions & 16 deletions
Large diffs are not rendered by default.

apps/txid_match/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defmodule TXIDMatch.MixProject do
2222
# Run "mix help deps" to learn about dependencies.
2323
defp deps do
2424
[
25-
{:electric, "~> 1.1.1", override: true},
25+
{:electric, "~> 1.0", override: true},
2626
{:electric_client, "~> 0.7", override: true},
2727
{:nimble_options, "~> 1.1"},
2828
{:phoenix_live_view, "~> 1.0", optional: true},

lib/mix/tasks/phoenix_sync.install.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ if Code.ensure_loaded?(Igniter) do
300300
defp required_electric_version do
301301
Phoenix.Sync.MixProject.project()
302302
|> Keyword.fetch!(:deps)
303-
|> Enum.find(&match?({:electric, _, _}, &1))
303+
|> Enum.find(&(elem(&1, 0) == :electric))
304304
|> elem(1)
305305
end
306306

lib/phoenix/sync/electric.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,9 @@ defmodule Phoenix.Sync.Electric do
640640
end
641641
end
642642

643-
if Code.ensure_loaded?(Electric.Shapes.Api) &&
644-
Code.ensure_loaded?(Phoenix.Sync.Electric.ApiAdapter) do
643+
if Code.ensure_loaded?(Electric.Shapes.Api) do
644+
Code.ensure_loaded(Phoenix.Sync.Electric.ApiAdapter)
645+
645646
defimpl Phoenix.Sync.Adapter.PlugApi, for: Electric.Shapes.Api do
646647
alias Electric.Shapes
647648

@@ -701,7 +702,7 @@ if Code.ensure_loaded?(Electric.Shapes.Api) &&
701702
end
702703
end
703704

704-
def send_response(%ApiAdapter{}, conn, {request, response}) do
705+
def send_response(_api, conn, {request, response}) do
705706
conn
706707
|> content_type()
707708
|> Plug.Conn.assign(:request, request)

lib/phoenix/sync/plug/cors.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ defmodule Phoenix.Sync.Plug.CORS do
1313
@electric_headers [
1414
"electric-cursor",
1515
"electric-handle",
16+
"electric-has-data",
1617
"electric-offset",
1718
"electric-schema",
1819
"electric-up-to-date",
19-
"electric-internal-known-error"
20+
"electric-internal-known-error",
21+
"retry-after"
2022
]
2123

2224
@expose_headers ["transfer-encoding" | @electric_headers]

lib/phoenix/sync/sandbox.ex

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,14 @@ if Phoenix.Sync.sandbox_enabled?() do
253253

254254
:ok = maybe_set_shared_mode(owner, stack_id, opts)
255255

256-
# give the inspector access to the sandboxed connection
257-
Ecto.Adapters.SQL.Sandbox.allow(repo, owner, Sandbox.Inspector.name(stack_id))
258-
259256
# mark the stack as ready
260257
Electric.StatusMonitor.mark_pg_lock_acquired(stack_id, owner)
261258
Electric.StatusMonitor.mark_replication_client_ready(stack_id, owner)
262-
Electric.StatusMonitor.mark_connection_pool_ready(stack_id, owner)
259+
Electric.StatusMonitor.mark_connection_pool_ready(stack_id, :admin, owner)
260+
Electric.StatusMonitor.mark_connection_pool_ready(stack_id, :snapshot, owner)
261+
Electric.StatusMonitor.mark_integrety_checks_passed(stack_id, owner)
262+
Electric.StatusMonitor.mark_shape_log_collector_ready(stack_id, owner)
263+
Electric.StatusMonitor.mark_supervisor_processes_ready(stack_id, owner)
263264

264265
api_config = Sandbox.Stack.config(stack_id, repo)
265266
api = Electric.Application.api(api_config)
@@ -292,7 +293,8 @@ if Phoenix.Sync.sandbox_enabled?() do
292293
defp generate_stack_id(opts) do
293294
tags = Keyword.get(opts, :tags, %{})
294295
# with parameterised tests the same file:line can be running simultaneously
295-
uid = System.unique_integer() |> to_string()
296+
uid = System.unique_integer([:positive, :monotonic]) |> to_string()
297+
now = System.monotonic_time(:microsecond)
296298

297299
suffix =
298300
case Map.fetch(tags, :line) do
@@ -306,7 +308,7 @@ if Phoenix.Sync.sandbox_enabled?() do
306308
:error -> ""
307309
end
308310

309-
"#{inspect(__MODULE__.Stack)}#{uid}#{prefix}#{suffix}"
311+
"#{inspect(__MODULE__.Stack)}#{now}-#{uid}#{prefix}#{suffix}"
310312
end
311313

312314
defp maybe_set_shared_mode(owner, stack_id, opts) do

0 commit comments

Comments
 (0)