Page MenuHomePhabricator

D9019.id30539.diff
No OneTemporary

D9019.id30539.diff

diff --git a/services/backup/src/constants.rs b/services/backup/src/constants.rs
--- a/services/backup/src/constants.rs
+++ b/services/backup/src/constants.rs
@@ -13,15 +13,19 @@
tracing_subscriber::filter::EnvFilter::DEFAULT_ENV;
// DynamoDB constants
+pub mod backup_table {
+ pub const TABLE_NAME: &str = "backup-service-backup";
+ pub const CREATED_INDEX: &str = "userID-created-index";
-pub const BACKUP_TABLE_NAME: &str = "backup-service-backup";
-pub const BACKUP_TABLE_FIELD_USER_ID: &str = "userID";
-pub const BACKUP_TABLE_FIELD_BACKUP_ID: &str = "backupID";
-pub const BACKUP_TABLE_FIELD_CREATED: &str = "created";
-pub const BACKUP_TABLE_FIELD_USER_DATA: &str = "userData";
-pub const BACKUP_TABLE_FIELD_USER_KEYS: &str = "userKeys";
-pub const BACKUP_TABLE_FIELD_ATTACHMENTS: &str = "attachments";
-pub const BACKUP_TABLE_INDEX_USERID_CREATED: &str = "userID-created-index";
+ pub mod attr {
+ pub const USER_ID: &str = "userID";
+ pub const BACKUP_ID: &str = "backupID";
+ pub const CREATED: &str = "created";
+ pub const USER_DATA: &str = "userData";
+ pub const USER_KEYS: &str = "userKeys";
+ pub const ATTACHMENTS: &str = "attachments";
+ }
+}
pub const LOG_TABLE_NAME: &str = "backup-service-log";
pub const LOG_TABLE_FIELD_BACKUP_ID: &str = "backupID";
diff --git a/services/backup/src/database/backup_item.rs b/services/backup/src/database/backup_item.rs
--- a/services/backup/src/database/backup_item.rs
+++ b/services/backup/src/database/backup_item.rs
@@ -6,11 +6,7 @@
};
use std::collections::HashMap;
-use crate::constants::{
- BACKUP_TABLE_FIELD_ATTACHMENTS, BACKUP_TABLE_FIELD_BACKUP_ID,
- BACKUP_TABLE_FIELD_CREATED, BACKUP_TABLE_FIELD_USER_DATA,
- BACKUP_TABLE_FIELD_USER_ID, BACKUP_TABLE_FIELD_USER_KEYS,
-};
+use crate::constants::backup_table;
#[derive(Clone, Debug)]
pub struct BackupItem {
@@ -60,30 +56,30 @@
fn from(value: BackupItem) -> Self {
let mut attrs = HashMap::from([
(
- BACKUP_TABLE_FIELD_USER_ID.to_string(),
+ backup_table::attr::USER_ID.to_string(),
AttributeValue::S(value.user_id),
),
(
- BACKUP_TABLE_FIELD_BACKUP_ID.to_string(),
+ backup_table::attr::BACKUP_ID.to_string(),
AttributeValue::S(value.backup_id),
),
(
- BACKUP_TABLE_FIELD_CREATED.to_string(),
+ backup_table::attr::CREATED.to_string(),
AttributeValue::S(value.created.to_rfc3339()),
),
(
- BACKUP_TABLE_FIELD_USER_KEYS.to_string(),
+ backup_table::attr::USER_KEYS.to_string(),
value.user_keys.into(),
),
(
- BACKUP_TABLE_FIELD_USER_DATA.to_string(),
+ backup_table::attr::USER_DATA.to_string(),
value.user_data.into(),
),
]);
if !value.attachments.is_empty() {
attrs.insert(
- BACKUP_TABLE_FIELD_ATTACHMENTS.to_string(),
+ backup_table::attr::ATTACHMENTS.to_string(),
AttributeValue::L(
value
.attachments
@@ -105,30 +101,30 @@
mut value: HashMap<String, AttributeValue>,
) -> Result<Self, Self::Error> {
let user_id = String::try_from_attr(
- BACKUP_TABLE_FIELD_USER_ID,
- value.remove(BACKUP_TABLE_FIELD_USER_ID),
+ backup_table::attr::USER_ID,
+ value.remove(backup_table::attr::USER_ID),
)?;
let backup_id = String::try_from_attr(
- BACKUP_TABLE_FIELD_BACKUP_ID,
- value.remove(BACKUP_TABLE_FIELD_BACKUP_ID),
+ backup_table::attr::BACKUP_ID,
+ value.remove(backup_table::attr::BACKUP_ID),
)?;
let created = DateTime::<Utc>::try_from_attr(
- BACKUP_TABLE_FIELD_CREATED,
- value.remove(BACKUP_TABLE_FIELD_CREATED),
+ backup_table::attr::CREATED,
+ value.remove(backup_table::attr::CREATED),
)?;
let user_keys = BlobInfo::try_from_attr(
- BACKUP_TABLE_FIELD_USER_KEYS,
- value.remove(BACKUP_TABLE_FIELD_USER_KEYS),
+ backup_table::attr::USER_KEYS,
+ value.remove(backup_table::attr::USER_KEYS),
)?;
let user_data = BlobInfo::try_from_attr(
- BACKUP_TABLE_FIELD_USER_DATA,
- value.remove(BACKUP_TABLE_FIELD_USER_DATA),
+ backup_table::attr::USER_DATA,
+ value.remove(backup_table::attr::USER_DATA),
)?;
- let attachments = value.remove(BACKUP_TABLE_FIELD_ATTACHMENTS);
+ let attachments = value.remove(backup_table::attr::ATTACHMENTS);
let attachments = if attachments.is_some() {
- attachments.attr_try_into(BACKUP_TABLE_FIELD_ATTACHMENTS)?
+ attachments.attr_try_into(backup_table::attr::ATTACHMENTS)?
} else {
vec![]
};
@@ -161,21 +157,21 @@
mut value: HashMap<String, AttributeValue>,
) -> Result<Self, Self::Error> {
let user_id = String::try_from_attr(
- BACKUP_TABLE_FIELD_USER_ID,
- value.remove(BACKUP_TABLE_FIELD_USER_ID),
+ backup_table::attr::USER_ID,
+ value.remove(backup_table::attr::USER_ID),
)?;
let created = DateTime::<Utc>::try_from_attr(
- BACKUP_TABLE_FIELD_CREATED,
- value.remove(BACKUP_TABLE_FIELD_CREATED),
+ backup_table::attr::CREATED,
+ value.remove(backup_table::attr::CREATED),
)?;
let backup_id = String::try_from_attr(
- BACKUP_TABLE_FIELD_BACKUP_ID,
- value.remove(BACKUP_TABLE_FIELD_BACKUP_ID),
+ backup_table::attr::BACKUP_ID,
+ value.remove(backup_table::attr::BACKUP_ID),
)?;
let user_keys = BlobInfo::try_from_attr(
- BACKUP_TABLE_FIELD_USER_KEYS,
- value.remove(BACKUP_TABLE_FIELD_USER_KEYS),
+ backup_table::attr::USER_KEYS,
+ value.remove(backup_table::attr::USER_KEYS),
)?;
Ok(OrderedBackupItem {
diff --git a/services/backup/src/database/mod.rs b/services/backup/src/database/mod.rs
--- a/services/backup/src/database/mod.rs
+++ b/services/backup/src/database/mod.rs
@@ -11,9 +11,7 @@
use tracing::{error, trace, warn};
use crate::constants::{
- BACKUP_TABLE_FIELD_BACKUP_ID, BACKUP_TABLE_FIELD_USER_ID,
- BACKUP_TABLE_INDEX_USERID_CREATED, BACKUP_TABLE_NAME,
- LOG_TABLE_FIELD_ATTACHMENT_HOLDERS, LOG_TABLE_FIELD_BACKUP_ID,
+ backup_table, LOG_TABLE_FIELD_ATTACHMENT_HOLDERS, LOG_TABLE_FIELD_BACKUP_ID,
LOG_TABLE_FIELD_DATA_HASH, LOG_TABLE_FIELD_LOG_ID,
LOG_TABLE_FIELD_PERSISTED_IN_BLOB, LOG_TABLE_FIELD_VALUE, LOG_TABLE_NAME,
};
@@ -45,7 +43,7 @@
self
.client
.put_item()
- .table_name(BACKUP_TABLE_NAME)
+ .table_name(backup_table::TABLE_NAME)
.set_item(Some(item))
.send()
.await
@@ -67,7 +65,7 @@
let output = self
.client
.get_item()
- .table_name(BACKUP_TABLE_NAME)
+ .table_name(backup_table::TABLE_NAME)
.set_key(Some(item_key))
.send()
.await
@@ -93,10 +91,10 @@
let response = self
.client
.query()
- .table_name(BACKUP_TABLE_NAME)
- .index_name(BACKUP_TABLE_INDEX_USERID_CREATED)
+ .table_name(backup_table::TABLE_NAME)
+ .index_name(backup_table::CREATED_INDEX)
.key_condition_expression("#userID = :valueToMatch")
- .expression_attribute_names("#userID", BACKUP_TABLE_FIELD_USER_ID)
+ .expression_attribute_names("#userID", backup_table::attr::USER_ID)
.expression_attribute_values(
":valueToMatch",
AttributeValue::S(user_id.to_string()),
@@ -129,7 +127,7 @@
let response = self
.client
.delete_item()
- .table_name(BACKUP_TABLE_NAME)
+ .table_name(backup_table::TABLE_NAME)
.set_key(Some(item_key))
.return_values(ReturnValue::AllOld)
.send()
@@ -155,10 +153,10 @@
let response = self
.client
.query()
- .table_name(BACKUP_TABLE_NAME)
- .index_name(BACKUP_TABLE_INDEX_USERID_CREATED)
+ .table_name(backup_table::TABLE_NAME)
+ .index_name(backup_table::CREATED_INDEX)
.key_condition_expression("#userID = :valueToMatch")
- .expression_attribute_names("#userID", BACKUP_TABLE_FIELD_USER_ID)
+ .expression_attribute_names("#userID", backup_table::attr::USER_ID)
.expression_attribute_values(
":valueToMatch",
AttributeValue::S(user_id.to_string()),
@@ -220,11 +218,11 @@
) -> HashMap<String, AttributeValue> {
HashMap::from([
(
- BACKUP_TABLE_FIELD_USER_ID.to_string(),
+ backup_table::attr::USER_ID.to_string(),
AttributeValue::S(user_id.to_string()),
),
(
- BACKUP_TABLE_FIELD_BACKUP_ID.to_string(),
+ backup_table::attr::BACKUP_ID.to_string(),
AttributeValue::S(backup_id.to_string()),
),
])

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 5:28 AM (18 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2569086
Default Alt Text
D9019.id30539.diff (8 KB)

Event Timeline