Skip to main content

hypercall_db/types/
archiver.rs

1//! ORM-free domain types for the db-archiver.
2//!
3//! These types carry archived data between the persistence layer and the
4//! archiver binary without any Diesel dependency.
5
6use chrono::{DateTime, NaiveDateTime, Utc};
7use rust_decimal::Decimal;
8use serde::Serialize;
9
10/// Safe archival boundary: the engine snapshot's last_command_id plus an
11/// age cutoff for non-journal tables.
12#[derive(Debug, Clone)]
13pub struct ArchivalBoundary {
14    pub max_command_id: i64,
15    pub age_cutoff: DateTime<Utc>,
16}
17
18/// Engine event row for archival (mirrors `engine_events` columns).
19#[derive(Debug, Clone, Serialize)]
20pub struct ArchivedEvent {
21    pub event_id: i64,
22    pub command_id: i64,
23    pub event_idx: i32,
24    pub event_data: Vec<u8>,
25    pub event_key: Option<String>,
26    pub l2_sequence: Option<i64>,
27    pub created_at: DateTime<Utc>,
28    pub published_at: Option<DateTime<Utc>>,
29    pub publish_attempts: i32,
30    pub last_publish_error: Option<String>,
31    pub last_publish_attempt_at: Option<DateTime<Utc>>,
32    /// String representation of the Postgres `engine_event_type` enum.
33    pub event_type: String,
34}
35
36/// Engine command row for archival (mirrors `engine_commands` columns).
37#[derive(Debug, Clone, Serialize)]
38pub struct ArchivedCommand {
39    pub command_id: i64,
40    pub received_ts_ms: i64,
41    pub command_data: Option<Vec<u8>>,
42    pub response_data: Option<Vec<u8>>,
43    pub order_id: Option<i64>,
44    /// UUID serialized as a hyphenated string.
45    pub request_uuid: String,
46    /// String representation of the Postgres `engine_command_type` enum.
47    pub command_type: Option<String>,
48    pub created_at: DateTime<Utc>,
49}
50
51/// Order action row for archival (mirrors `order_actions` columns).
52#[derive(Debug, Clone, Serialize)]
53pub struct ArchivedOrderAction {
54    pub id: Option<i32>,
55    pub timestamp: i64,
56    pub wallet: Vec<u8>,
57    pub action: String,
58    pub symbol: String,
59    pub price: Decimal,
60    pub size: Decimal,
61    pub side: String,
62    pub tif: String,
63    pub client_id: Option<String>,
64    pub created_at: Option<NaiveDateTime>,
65}
66
67/// Order update row for archival (mirrors `order_updates` columns).
68#[derive(Debug, Clone, Serialize)]
69pub struct ArchivedOrderUpdate {
70    pub id: Option<i32>,
71    pub timestamp: i64,
72    pub order_id: Option<i64>,
73    pub status: String,
74    pub reason: Option<String>,
75    pub filled_size: Decimal,
76    pub symbol: String,
77    pub price: Decimal,
78    pub size: Decimal,
79    pub side: String,
80    pub tif: String,
81    pub client_id: Option<String>,
82    pub created_at: Option<NaiveDateTime>,
83}