Skip to content
Weik.ioUniversity
Try Weik.io

React to database changes

Patterns 4 · 3:49

A change tracking integration publishes every insert, update and delete in a database table into a channel, and a watcher route reacts to each one. The database administrator first turns on the database's own change feature.

Download the mp4Recorded on 2026.2

What it covers

  • Scaffolding the change tracking with weikio init --kind change-tracking
  • The filled document for PostgreSQL and public.invoice, with its placeholders from variables and a secret
  • The channel invoice-changes, made with weikio channel create, where each change is one stored event
  • The watcher route, started by the kamelet weikio-event-source, with its log step
  • Three changes to invoice 1041, read back with weikio events show and weikio logs
  • The agent dev as the leading copy, and each change on the admin UI's Changes tab

Commands in this video

Terminal
$ weikio init invoice-tracking --kind change-tracking
$ weikio channel create sandbox/invoice-changes
$ weikio apply -f ./invoice-tracking
$ weikio deploy sandbox/invoice-tracking --env devtest
$ weikio run ./invoice-watcher --no-logs
$ psql -d erp -c "INSERT INTO invoice (id, customer, amount, status) VALUES (1041, 'Lakeside Bakery', 640, 'open')"
$ weikio events show sandbox/invoice-changes --seq 1
$ psql -d erp -c "UPDATE invoice SET status = 'paid' WHERE id = 1041"
$ psql -d erp -c "DELETE FROM invoice WHERE id = 1041"
$ weikio logs sandbox/invoice-watcher --since 10m
Transcript
  1. 0:01An invoice changes in the database.
  2. 0:03Other systems must hear of every change.
  3. 0:12The three changes to invoice 1041 left no rows.
  4. 0:16The database's administrator switches on its change feature.
  5. 0:23The tools are a change tracking, a channel, and the kamelet weikio-event-source.
  6. 0:33The change tracking is an integration of its own kind.
  7. 0:36The command wrote its scaffold, and the tracking publishes every insert,
  8. 0:41update and delete into a channel.
  9. 0:44The scaffold names SQL Server, and the filled document names postgres,
  10. 0:50public.invoice and another channel, invoice-changes.
  11. 0:56The placeholders read variables and a secret:
  12. 0:59erp-db-host, erp-db-user, erp-db-password.
  13. 1:07A channel is a hub service that keeps its events.
  14. 1:11Every change the tracking publishes is one stored event.
  15. 1:15It holds an op letter, c for create, u for update,
  16. 1:19d for delete, and the row before and after.
  17. 1:22The command created the channel sandbox/invoice-changes.
  18. 1:29The kamelet weikio-event-source starts the watcher's route on the channel.
  19. 1:34The route sees each stored event as it lands.
  20. 1:37Its file shows the kamelet, the channel and the log step.
  21. 1:41The log step prints each change's operation, invoice and status.
  22. 1:48The apply sends the folder to the hub.
  23. 1:52The change tracking is created with no warning, because the channel exists.
  24. 1:57The deploy answers with one agent running.
  25. 2:02The watcher runs, from the kamelet weikio-event-source.
  26. 2:11The database's own tool inserts invoice 1041.
  27. 2:19Two seconds later, the channel holds one stored event.
  28. 2:23It carries op c, before null and after the new row.
  29. 2:32The tool updates the row for invoice 1041.
  30. 2:35Then the row is removed.
  31. 2:42The channel holds three stored events.
  32. 2:49weikio logs reads ten minutes of the watcher's log.
  33. 2:53The received lines read op c, u, d.
  34. 3:03The change tracking runs one copy at a time, dev is the leader.
  35. 3:10Its Changes lists each change for invoice 1041.
  36. 3:16The event holds op u, open in before and paid in after.
  37. 3:25The change tracking publishes every insert,
  38. 3:28update and delete of the table into a channel.
  39. 3:31The channel invoice-changes keeps each one as a stored event.
  40. 3:35The kamelet weikio-event-source starts the watcher's route,
  41. 3:39and the route sees each event.

Next in this track

Patterns 5 · 2:58 One copy at a time Watched