Page MenuHomePhabricator

D6177.id20698.diff
No OneTemporary

D6177.id20698.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,3 +13,22 @@
pub const SANDBOX_ENV_VAR: &str = "COMM_SERVICES_SANDBOX";
pub const LOG_LEVEL_ENV_VAR: &str =
tracing_subscriber::filter::EnvFilter::DEFAULT_ENV;
+
+// DynamoDB constants
+
+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_RECOVERY_DATA: &str = "recoveryData";
+pub const BACKUP_TABLE_FIELD_COMPACTION_HOLDER: &str = "compactionHolder";
+pub const BACKUP_TABLE_FIELD_ATTACHMENT_HOLDERS: &str = "attachmentHolders";
+pub const BACKUP_TABLE_INDEX_USERID_CREATED: &str = "userID-created-index";
+
+pub const LOG_TABLE_NAME: &str = "backup-service-log";
+pub const LOG_TABLE_FIELD_BACKUP_ID: &str = "backupID";
+pub const LOG_TABLE_FIELD_LOG_ID: &str = "logID";
+pub const LOG_TABLE_FIELD_PERSISTED_IN_BLOB: &str = "persistedInBlob";
+pub const LOG_TABLE_FIELD_VALUE: &str = "value";
+pub const LOG_TABLE_FIELD_ATTACHMENT_HOLDERS: &str = "attachmentHolders";
+pub const LOG_TABLE_FIELD_DATA_HASH: &str = "dataHash";
diff --git a/services/backup/src/database.rs b/services/backup/src/database.rs
new file mode 100644
--- /dev/null
+++ b/services/backup/src/database.rs
@@ -0,0 +1,89 @@
+use chrono::{DateTime, Utc};
+use std::sync::Arc;
+
+#[derive(Clone, Debug)]
+pub struct BackupItem {
+ pub user_id: String,
+ pub backup_id: String,
+ pub created: DateTime<Utc>,
+ pub recovery_data: String,
+ pub compaction_holder: String,
+ pub attachment_holders: String,
+}
+
+#[derive(Clone, Debug)]
+pub struct LogItem {
+ pub backup_id: String,
+ pub log_id: String,
+ pub persisted_in_blob: bool,
+ pub value: String,
+ pub attachment_holders: String,
+ pub data_hash: String,
+}
+
+#[derive(Clone)]
+pub struct DatabaseClient {
+ client: Arc<aws_sdk_dynamodb::Client>,
+}
+
+impl DatabaseClient {
+ pub fn new(aws_config: &aws_types::SdkConfig) -> Self {
+ DatabaseClient {
+ client: Arc::new(aws_sdk_dynamodb::Client::new(aws_config)),
+ }
+ }
+
+ // backup item
+ pub async fn put_backup_item(
+ &self,
+ backup_item: BackupItem,
+ ) -> Result<(), Error> {
+ unimplemented!()
+ }
+
+ pub async fn find_backup_item(
+ &self,
+ user_id: &str,
+ backup_id: &str,
+ ) -> Result<Option<BackupItem>, Error> {
+ unimplemented!()
+ }
+
+ pub async fn find_last_backup_item(
+ &self,
+ user_id: &str,
+ ) -> Result<Option<BackupItem>, Error> {
+ unimplemented!()
+ }
+
+ pub async fn remove_backup_item(&self, backup_id: &str) -> Result<(), Error> {
+ unimplemented!()
+ }
+
+ // log item
+ pub async fn put_log_item(&self, log_item: LogItem) -> Result<(), Error> {
+ unimplemented!()
+ }
+
+ pub async fn find_log_item(
+ &self,
+ backup_id: &str,
+ log_id: &str,
+ ) -> Result<Option<LogItem>, Error> {
+ unimplemented!()
+ }
+
+ pub async fn find_log_items_for_backup(
+ &self,
+ backup_id: &str,
+ ) -> Result<Vec<LogItem>, Error> {
+ unimplemented!()
+ }
+
+ pub async fn remove_log_item(&self, log_id: &str) -> Result<(), Error> {
+ unimplemented!()
+ }
+}
+
+// TODO: Replace this with dedicated DB error
+type Error = anyhow::Error;
diff --git a/services/backup/src/main.rs b/services/backup/src/main.rs
--- a/services/backup/src/main.rs
+++ b/services/backup/src/main.rs
@@ -9,6 +9,7 @@
pub mod blob;
pub mod config;
pub mod constants;
+pub mod database;
pub mod service;
// re-export this to be available as crate::CONFIG

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 17, 4:20 PM (21 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2525766
Default Alt Text
D6177.id20698.diff (3 KB)

Event Timeline