Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5uEyg58znuchZ8C8i
36 lines
1.3 KiB
Bash
Executable File
36 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Why an update has before=null, why a delete has placeholder values, and what REPLICA IDENTITY FULL changes.
|
|
set -eu
|
|
. "$(dirname "$0")/lib.sh"
|
|
OUT=output/03-replica-identity.txt
|
|
mkdir -p output
|
|
latest() { # latest <key-id> <n> : last n events for an order id, in WAL order
|
|
kafka_consume shop.public.orders 6000 | grep -F "|{\"id\":$1}|" | summarize --sort-lsn | tail -"$2"
|
|
}
|
|
{
|
|
sql -c "insert into orders values (4, 'dev', 'NEW', 500)"
|
|
echo "### REPLICA IDENTITY DEFAULT: update and delete of order 4"
|
|
sql -c "update orders set status = 'PAID' where id = 4"
|
|
sql -c "delete from orders where id = 4"
|
|
sleep 4
|
|
latest 4 4
|
|
|
|
echo
|
|
echo "### Switch the table to REPLICA IDENTITY FULL"
|
|
sql -c "alter table orders replica identity full"
|
|
sqlp -c "select relname, relreplident from pg_class where relname = 'orders'"
|
|
sql -c "insert into orders values (5, 'kiran', 'NEW', 700)"
|
|
sql -c "update orders set status = 'PAID' where id = 5"
|
|
sql -c "delete from orders where id = 5"
|
|
sleep 4
|
|
echo "### Same three statements for order 5"
|
|
latest 5 4
|
|
|
|
echo
|
|
echo "### Add a column while the connector is running; the next event carries it, no restart needed"
|
|
sql -c "alter table orders add column note text"
|
|
sql -c "update orders set note = 'gift wrap' where id = 1"
|
|
sleep 4
|
|
latest 1 1
|
|
} 2>&1 | tee "$OUT"
|