Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/phoenix/sync/sandbox/producer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,17 @@ 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(),
affected_relations: Enum.into(changes, MapSet.new(), & &1.relation)
}
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{
Expand Down Expand Up @@ -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
Expand Down