Skip to content
Weik.ioUniversity
Try Weik.io

React to database changes

Patterns 4 · 3:47

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:01A row in someone else's database changes, and other systems have to hear of it.
  2. 0:11Invoice 1041 is added, changed and deleted, then the table reads empty.
  3. 0:17The database's administrator opens its change log.
  4. 0:23A change tracking reads that log, publishes to the invoice-changes channel,
  5. 0:28then a route reads the channel.
  6. 0:34A change tracking is a kind of integration that reads the database's change log and publishes each change into a channel.
  7. 0:42weikio init for a change tracking writes the invoice-tracking folder and its document.
  8. 0:49The scaffold arrives for another database product, so you fill it in for yours.
  9. 0:55The filled document names postgres, the table it watches and the channel.
  10. 1:00Host, user and password are placeholders: two devtest variables and a secret.
  11. 1:09A channel is the project's named topic for events,
  12. 1:13and it keeps what is published into it.
  13. 1:15The tracking brings no channel,
  14. 1:17so the channel create command for invoice-changes in sandbox declares one before anything publishes.
  15. 1:24Each change becomes one stored event,
  16. 1:26carrying its operation and the row before and after.
  17. 1:33A route of the same project watches that channel,
  18. 1:36starting on the weikio-event-source kamelet that comes with the platform.
  19. 1:41Its log step writes what the route took in: the operation,
  20. 1:45the row's id and the status before and after.
  21. 1:51The apply stores invoice-tracking in your Weik.io installation as a version.
  22. 1:56The deploy runs that version in devtest,
  23. 1:59then invoice-tracking reads the database's log.
  24. 2:02weikio run for the invoice-watcher folder applies and deploys it without waiting on the log.
  25. 2:13The change is made in the database's own tool.
  26. 2:20weikio events show reads the first stored event, the insert.
  27. 2:25The tracking read the log and published the change into the channel.
  28. 2:33The tool sets the row's status to paid.
  29. 2:38Then it deletes the row.
  30. 2:43The channel keeps all three changes, one event each.
  31. 2:50weikio logs reads the watcher's log from the installation.
  32. 2:55The watcher took in all three changes.
  33. 3:01The Details panel names the database and the channel.
  34. 3:04One copy runs on agent dev.
  35. 3:09The Changes section gives one row per published change, newest first.
  36. 3:14Opening one shows the row before the change and the row after.
  37. 3:22The change tracking read the database's log and sent every insert,
  38. 3:27update and delete to the channel.
  39. 3:29The channel kept each as a stored event, so the Weik.io CLI or a route can read it.
  40. 3:36The route on the kamelet took each event and logged it.

Next in this track

Patterns 5 · 3:01 One copy at a time Watched

Sign in to the live demo

Sign in with the shared viewer account, which can open every screen of the example projects and can't change anything.

E-mail
viewer@demo.weik.io
Password
try-weikio-live-demo
Open the live demo