diff --git a/services/backup/src/http/handlers/backup.rs b/services/backup/src/http/handlers/backup.rs --- a/services/backup/src/http/handlers/backup.rs +++ b/services/backup/src/http/handlers/backup.rs @@ -58,6 +58,9 @@ Some(user_data_blob_info), attachments, siwe_backup_msg, + // TODO: use real values here + 0, + Default::default(), ); db_client @@ -176,6 +179,9 @@ Some(user_data_blob_info), attachments, existing_backup_item.siwe_backup_msg.clone(), + // TODO: use real values here + 0, + Default::default(), ); db_client @@ -417,6 +423,9 @@ user_data, attachments, siwe_backup_msg, + // TODO: use real values here + 0, + Default::default(), ); Ok((item, revokes)) diff --git a/shared/comm-lib/src/backup/database.rs b/shared/comm-lib/src/backup/database.rs --- a/shared/comm-lib/src/backup/database.rs +++ b/shared/comm-lib/src/backup/database.rs @@ -4,6 +4,8 @@ use crate::blob::types::BlobInfo; +use super::BackupVersionInfo; + #[cfg(feature = "blob-client")] use crate::blob::client::BlobServiceClient; #[cfg(feature = "aws")] @@ -37,6 +39,10 @@ pub user_data: Option, pub attachments: Vec, pub siwe_backup_msg: Option, + #[serde(default)] + pub total_size: u64, + #[serde(default)] + pub version_info: BackupVersionInfo, } impl BackupItem { @@ -47,6 +53,8 @@ user_data: Option, attachments: Vec, siwe_backup_msg: Option, + total_size: u64, + version_info: BackupVersionInfo, ) -> Self { BackupItem { user_id, @@ -56,6 +64,8 @@ user_data, attachments, siwe_backup_msg, + total_size, + version_info, } } @@ -198,6 +208,39 @@ user_data, attachments, siwe_backup_msg, + // TODO: Parse real values from DDB + total_size: 0, + version_info: Default::default(), }) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_backup_item_deserialize_defaults() { + // BackupItem is passed between services. It might happen that one service + // has old implementation that doesn't include `total_size` + // and `version_info` fields. It should deserialize the defaults then fields. It should insert the + // defaults then. + let payload = r#"{ + "user_id": "uid", + "backup_id": "bid", + "created":"2025-05-13T11:20:33.799712136Z", + "user_keys": {"blobHash":"hash1","holder":"holder1"}, + "user_data": null, + "attachments": [], + "siwe_backup_msg": null + }"#; + + let deserialized: BackupItem = + serde_json::from_str(payload).expect("failed to deserialized BackupItem"); + + assert_eq!(deserialized.total_size, 0u64); + assert_eq!(deserialized.version_info.code_version, 0u16); + assert_eq!(deserialized.version_info.state_version, 0u16); + assert_eq!(deserialized.version_info.db_version, 0u16); + } +} diff --git a/shared/comm-lib/src/backup/mod.rs b/shared/comm-lib/src/backup/mod.rs --- a/shared/comm-lib/src/backup/mod.rs +++ b/shared/comm-lib/src/backup/mod.rs @@ -4,6 +4,16 @@ /// shared database types and constants pub mod database; +#[derive(Debug, Default, Clone, Serialize, Deserialize)] +pub struct BackupVersionInfo { + /// App code version + pub code_version: u16, + /// Redux state version + pub state_version: u16, + /// SQLite DB version + pub db_version: u16, +} + #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct LatestBackupInfoResponse {