Skip to main content

sources_core/cdc/
change.rs

1use schema_core::TableName;
2
3use crate::RowKey;
4
5use super::Ack;
6
7/// One item emitted by a [`ChangeCapture`](super::ChangeCapture) stream: a
8/// change paired with the [`Ack`] that confirms it was durably processed.
9///
10/// Dropping the `ack` without calling [`Ack::confirm`] leaves the change
11/// unconfirmed — the mechanism will redeliver it after a restart. That is what
12/// makes delivery at-least-once: an event is only forgotten once the engine
13/// says it landed downstream.
14#[derive(Debug)]
15pub struct Change {
16    pub event: ChangeEvent,
17    pub ack: Ack,
18}
19
20/// What happened to a row, identified only by its table and primary key.
21///
22/// Events are deliberately *thin*: they name the row, not its contents. The
23/// engine re-reads the current row — and resolves the document's joins and
24/// aggregates — at assembly time. This keeps every mechanism (WAL, polling, …)
25/// identical from the engine's point of view and avoids depending on a table's
26/// `REPLICA IDENTITY` to carry old or new values.
27///
28/// Note that the mechanism reports *raw per-table* changes. Mapping a change in
29/// a joined or junction table back to the parent documents that must be rebuilt
30/// is the document layer's job — not something this layer knows.
31///
32/// There is no distinct "snapshot" variant: an initial backfill is a separate
33/// finite stream of [`Upsert`](Self::Upsert)s (see
34/// [`ChangeCapture::snapshot`](super::ChangeCapture::snapshot)), so the engine
35/// knows it is seeding from *which stream* it is draining, not from the event.
36#[derive(Debug, Clone)]
37pub enum ChangeEvent {
38    /// A row was inserted or updated.
39    Upsert { table: TableName, key: RowKey },
40
41    /// A row was deleted.
42    Delete { table: TableName, key: RowKey },
43}