#!/usr/bin/env bash # The change-event envelope: snapshot reads, then insert, update, delete (and the tombstone) with the default replica identity. set -eu . "$(dirname "$0")/lib.sh" OUT=output/02-event-format.txt mkdir -p output { echo "### Replica identity of orders (d = default, primary key only)" sqlp -c "select relname, relreplident from pg_class where relname = 'orders'" echo echo "### Four statements, one transaction each" sql -c "insert into orders values (3, 'meera', 'NEW', 999)" sql -c "update orders set status = 'PAID' where id = 3" sql -c "update orders set amount_cents = 1099 where id = 3" sql -c "delete from orders where id = 3" sleep 4 echo echo "### Topic shop.public.orders in WAL order (p = partition). The two op=r records are the initial snapshot." kafka_consume shop.public.orders 6000 | summarize --sort-lsn echo echo "### The raw insert envelope for id 3, exactly as Kafka stores it (value, pretty-printed with jq)" kafka_consume shop.public.orders 6000 | awk -F'|' '$2 == "{\"id\":3}" && $3 ~ /"op":"c"/ {print $3}' | jq . } 2>&1 | tee "$OUT"