Skip to content

Commit 6b4c849

Browse files
committed
add postgres range dump for sandbox producer
1 parent aaeaef7 commit 6b4c849

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/phoenix/sync/sandbox/producer.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,17 @@ if Phoenix.Sync.sandbox_enabled?() do
8282
%Transaction{
8383
xid: txid,
8484
lsn: Electric.Postgres.Lsn.from_integer(txid),
85-
last_log_offset: Enum.at(changes, -1) |> Map.fetch!(:log_offset),
85+
last_log_offset: last_log_offset(txid, changes),
8686
changes: changes,
8787
num_changes: length(changes),
8888
commit_timestamp: DateTime.utc_now(),
8989
affected_relations: Enum.into(changes, MapSet.new(), & &1.relation)
9090
}
9191
end
9292

93+
defp last_log_offset(txid,[]),do: log_offset(txid, 0)
94+
defp last_log_offset(_txid,changes),do: Enum.at(changes, -1) |> Map.fetch!(:log_offset)
95+
9396
defp msg_from_change({{:insert, schema_meta, values}, i}, lsn, txid) do
9497
{
9598
%NewRecord{
@@ -166,6 +169,8 @@ if Phoenix.Sync.sandbox_enabled?() do
166169
type.to_iso8601(datetime)
167170
end
168171

172+
defp dump(%Postgrex.Range{} = range, _type), do: range
173+
169174
defp dump(map, _type) when is_map(map), do: @json.encode!(map)
170175

171176
defp dump(list, type) when is_list(list) do

0 commit comments

Comments
 (0)