Capture changes
Capture every change to your tables using Change Capture Pipelines
Sequin streams the latest versions of rows from your tables. But sometimes you want to capture every discrete change to your tables, not just the latest state of each row. With Change Capture Pipelines, Sequin can capture inserts, updates, and deletes as they happen, storing them in an event log table in your database. You can then stream these events to your applications using Sequin’s existing consumption methods.
This quickstart assumes you’ve already installed and setup Sequin in the prior quickstart. It refers to the public.regions
table from that guide.
Create a Change Capture Pipeline
Create a Change Capture Pipeline to capture changes:
-
Navigate to the Change Capture Pipelines tab and click the Create Change Capture Pipeline button.
-
Under “Source configuration”, the
public.regions
table should be selected already: -
Select which operations you want to capture. For this example, you can leave all three selected:
insert
,update
, anddelete
: -
You can skip “Add filter.”
-
Under “Destination configuration”, click “Create event table.” Here, Sequin shows you the steps for creating a table for your events:
-
Name the table
sequin_events
. Don’t specify a retention policy. Then, to create the table, open a console to thesequin_playground
database: -
You can type
\e
and pressEnter
to open up the SQL editor. Then, paste in the SQL operations that Sequin provided to create the event table. (If your editor is Vim, type:wq
to quit and run the commands.) -
After creating your event table, click “Done” to close the modal. Your new table should now appear in the destination list. Select it:
-
Give your Change Capture Pipeline a name (i.e.
region_to_sequin_events
) and click Create Change Capture Pipeline.
Sequin will now capture every change to the regions
table and write it to your event log.
Make some changes
Let’s see the Change Capture Pipeline in action:
-
Open a terminal and connect to the
sequin_playground
database: -
Turn on “extended display” mode by typing
\x
and pressingEnter
. -
Insert a new region:
-
Query your event log table to see the insert:
You should see something like:
-
Update the region:
-
Query your event log again:
Now you’ll see the update, including both the new values (
record
) and what changed (changes
): -
Finally, delete the region:
-
Query your event log one more time to see the delete event:
The delete event includes the final state of the row before deletion:
You’ve captured insert, update, and delete events into your event log table!
Stream your events
Now that you’re capturing changes, you can create a Stream for your event log table and stream the events to consumers:
- Navigate to the Streams tab and click Create Stream.
- Select your
sequin_events
table. seq
will be auto-selected as your sort column.- Click Create Stream.
You can now use the Consume Group API or webhooks to stream these events to your applications.
Next steps
You’ve seen how to capture changes to your tables and stream those changes to consumers. Now you can:
Was this page helpful?