maxwell_cdc/row.rs
1//! Row and bootstrap-control payloads.
2
3use alloc::string::String;
4use alloc::vec::Vec;
5use serde::{Deserialize, Serialize};
6use serde_json::{Map, Number, Value};
7
8/// A row change message (insert, update, delete, or bootstrap insert).
9#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub struct RowChange {
11 /// Database name.
12 pub database: String,
13 /// Table name.
14 pub table: String,
15 /// SQL statement that produced this row, present when `output_row_query` is enabled.
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub query: Option<String>,
18 /// Transaction timestamp in seconds since epoch.
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub ts: Option<i64>,
21 /// Transaction ID.
22 #[serde(skip_serializing_if = "Option::is_none")]
23 pub xid: Option<i64>,
24 /// Offset of this row within its transaction, present on uncommitted rows when
25 /// `output_xoffset` is enabled.
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub xoffset: Option<i64>,
28 /// Whether the transaction was committed.
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub commit: Option<bool>,
31 /// Binlog position (filename:offset).
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub position: Option<String>,
34 /// Global transaction ID, present when `output_gtid_position` is enabled.
35 #[serde(skip_serializing_if = "Option::is_none")]
36 pub gtid: Option<String>,
37 /// MySQL server ID.
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub server_id: Option<i64>,
40 /// Thread ID.
41 #[serde(skip_serializing_if = "Option::is_none")]
42 pub thread_id: Option<i64>,
43 /// Schema ID, present when `output_schema_id` is enabled.
44 #[serde(skip_serializing_if = "Option::is_none")]
45 pub schema_id: Option<i64>,
46 /// When Maxwell produced the message, in seconds with a fractional part. A [`Number`]
47 /// because Maxwell writes it as an arbitrary-precision decimal.
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub push_ts: Option<Number>,
50 /// Comment attached to the originating bootstrap task.
51 #[serde(skip_serializing_if = "Option::is_none")]
52 pub comment: Option<String>,
53 /// Primary key values.
54 #[serde(skip_serializing_if = "Option::is_none")]
55 pub primary_key: Option<Vec<Value>>,
56 /// Primary key column names.
57 #[serde(skip_serializing_if = "Option::is_none")]
58 pub primary_key_columns: Option<Vec<String>>,
59 /// Current row data as JSON object.
60 ///
61 /// A MySQL `DECIMAL` wider than `f64` loses digits here, because [`Value`] holds
62 /// fractional numbers as `f64`. Column order is not preserved either.
63 pub data: Map<String, Value>,
64 /// Previous row data (for updates only).
65 #[serde(skip_serializing_if = "Option::is_none")]
66 pub old: Option<Map<String, Value>>,
67 /// Fields Maxwell emitted that this crate does not model, kept verbatim. Keys must not
68 /// collide with the named fields above, or serializing writes them twice.
69 #[serde(flatten)]
70 pub extra: Map<String, Value>,
71}
72
73/// A control message (bootstrap start/complete).
74#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
75pub struct ControlMessage {
76 /// Database name.
77 pub database: String,
78 /// Table name.
79 pub table: String,
80 /// Event timestamp in seconds since epoch.
81 #[serde(skip_serializing_if = "Option::is_none")]
82 pub ts: Option<i64>,
83 /// When Maxwell produced the message, in seconds with a fractional part. A [`Number`]
84 /// because Maxwell writes it as an arbitrary-precision decimal.
85 #[serde(skip_serializing_if = "Option::is_none")]
86 pub push_ts: Option<Number>,
87 /// Comment attached to the originating bootstrap task.
88 #[serde(skip_serializing_if = "Option::is_none")]
89 pub comment: Option<String>,
90 /// Event data (typically empty for control messages).
91 pub data: Map<String, Value>,
92 /// Primary key values.
93 #[serde(skip_serializing_if = "Option::is_none")]
94 pub primary_key: Option<Vec<Value>>,
95 /// Primary key column names.
96 #[serde(skip_serializing_if = "Option::is_none")]
97 pub primary_key_columns: Option<Vec<String>>,
98 /// Fields Maxwell emitted that this crate does not model, kept verbatim. Keys must not
99 /// collide with the named fields above, or serializing writes them twice.
100 #[serde(flatten)]
101 pub extra: Map<String, Value>,
102}