From 6b4c8493ec70ba994855e018dc571c7fdfc63699 Mon Sep 17 00:00:00 2001 From: Mortada Alkhars Date: Fri, 12 Dec 2025 11:00:31 +0300 Subject: [PATCH] add postgres range dump for sandbox producer --- lib/phoenix/sync/sandbox/producer.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/phoenix/sync/sandbox/producer.ex b/lib/phoenix/sync/sandbox/producer.ex index a7f3231..edbbb70 100644 --- a/lib/phoenix/sync/sandbox/producer.ex +++ b/lib/phoenix/sync/sandbox/producer.ex @@ -82,7 +82,7 @@ if Phoenix.Sync.sandbox_enabled?() do %Transaction{ xid: txid, lsn: Electric.Postgres.Lsn.from_integer(txid), - last_log_offset: Enum.at(changes, -1) |> Map.fetch!(:log_offset), + last_log_offset: last_log_offset(txid, changes), changes: changes, num_changes: length(changes), commit_timestamp: DateTime.utc_now(), @@ -90,6 +90,9 @@ if Phoenix.Sync.sandbox_enabled?() do } end + defp last_log_offset(txid,[]),do: log_offset(txid, 0) + defp last_log_offset(_txid,changes),do: Enum.at(changes, -1) |> Map.fetch!(:log_offset) + defp msg_from_change({{:insert, schema_meta, values}, i}, lsn, txid) do { %NewRecord{ @@ -166,6 +169,8 @@ if Phoenix.Sync.sandbox_enabled?() do type.to_iso8601(datetime) end + defp dump(%Postgrex.Range{} = range, _type), do: range + defp dump(map, _type) when is_map(map), do: @json.encode!(map) defp dump(list, type) when is_list(list) do