mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 17:52:24 +00:00
sqlite_store fix change operation for object restore
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
use super::SqliteStore;
|
use super::{ChangeOperation, SqliteStore};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::{
|
use crate::{
|
||||||
model::{AddressObject, Addressbook},
|
model::{AddressObject, Addressbook},
|
||||||
AddressbookStore,
|
AddressbookStore,
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use serde::Serialize;
|
|
||||||
use sqlx::{Sqlite, Transaction};
|
use sqlx::{Sqlite, Transaction};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
@@ -23,21 +22,13 @@ impl TryFrom<AddressObjectRow> for AddressObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, sqlx::Type)]
|
|
||||||
#[serde(rename_all = "kebab-case")]
|
|
||||||
enum AddressbookChangeOperation {
|
|
||||||
// There's no distinction between Add and Modify
|
|
||||||
Add,
|
|
||||||
Delete,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logs an operation to the events
|
// Logs an operation to the events
|
||||||
async fn log_object_operation(
|
async fn log_object_operation(
|
||||||
tx: &mut Transaction<'_, Sqlite>,
|
tx: &mut Transaction<'_, Sqlite>,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
addressbook_id: &str,
|
addressbook_id: &str,
|
||||||
object_id: &str,
|
object_id: &str,
|
||||||
operation: AddressbookChangeOperation,
|
operation: ChangeOperation,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
@@ -290,7 +281,7 @@ impl AddressbookStore for SqliteStore {
|
|||||||
&principal,
|
&principal,
|
||||||
&addressbook_id,
|
&addressbook_id,
|
||||||
object_id,
|
object_id,
|
||||||
AddressbookChangeOperation::Add,
|
ChangeOperation::Add,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -334,7 +325,7 @@ impl AddressbookStore for SqliteStore {
|
|||||||
principal,
|
principal,
|
||||||
addressbook_id,
|
addressbook_id,
|
||||||
object_id,
|
object_id,
|
||||||
AddressbookChangeOperation::Delete,
|
ChangeOperation::Delete,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
@@ -364,7 +355,7 @@ impl AddressbookStore for SqliteStore {
|
|||||||
principal,
|
principal,
|
||||||
addressbook_id,
|
addressbook_id,
|
||||||
object_id,
|
object_id,
|
||||||
AddressbookChangeOperation::Delete,
|
ChangeOperation::Add,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
use super::SqliteStore;
|
use super::{ChangeOperation, SqliteStore};
|
||||||
use crate::model::object::CalendarObject;
|
use crate::model::object::CalendarObject;
|
||||||
use crate::model::Calendar;
|
use crate::model::Calendar;
|
||||||
use crate::{CalendarStore, Error};
|
use crate::{CalendarStore, Error};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use serde::Serialize;
|
|
||||||
use sqlx::Sqlite;
|
use sqlx::Sqlite;
|
||||||
use sqlx::Transaction;
|
use sqlx::Transaction;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
@@ -23,21 +22,13 @@ impl TryFrom<CalendarObjectRow> for CalendarObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, sqlx::Type)]
|
|
||||||
#[serde(rename_all = "kebab-case")]
|
|
||||||
enum CalendarChangeOperation {
|
|
||||||
// There's no distinction between Add and Modify
|
|
||||||
Add,
|
|
||||||
Delete,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logs an operation to the events
|
// Logs an operation to the events
|
||||||
async fn log_object_operation(
|
async fn log_object_operation(
|
||||||
tx: &mut Transaction<'_, Sqlite>,
|
tx: &mut Transaction<'_, Sqlite>,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
object_id: &str,
|
object_id: &str,
|
||||||
operation: CalendarChangeOperation,
|
operation: ChangeOperation,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
@@ -249,7 +240,7 @@ impl CalendarStore for SqliteStore {
|
|||||||
&principal,
|
&principal,
|
||||||
&cal_id,
|
&cal_id,
|
||||||
object_id,
|
object_id,
|
||||||
CalendarChangeOperation::Add,
|
ChangeOperation::Add,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -288,14 +279,7 @@ impl CalendarStore for SqliteStore {
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
log_object_operation(
|
log_object_operation(&mut tx, principal, cal_id, id, ChangeOperation::Delete).await?;
|
||||||
&mut tx,
|
|
||||||
principal,
|
|
||||||
cal_id,
|
|
||||||
id,
|
|
||||||
CalendarChangeOperation::Delete,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -318,14 +302,7 @@ impl CalendarStore for SqliteStore {
|
|||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
log_object_operation(
|
log_object_operation(&mut tx, principal, cal_id, object_id, ChangeOperation::Add).await?;
|
||||||
&mut tx,
|
|
||||||
principal,
|
|
||||||
cal_id,
|
|
||||||
object_id,
|
|
||||||
CalendarChangeOperation::Delete,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
|
use serde::Serialize;
|
||||||
use sqlx::{sqlite::SqliteConnectOptions, Pool, Sqlite, SqlitePool};
|
use sqlx::{sqlite::SqliteConnectOptions, Pool, Sqlite, SqlitePool};
|
||||||
|
|
||||||
pub mod addressbook_store;
|
pub mod addressbook_store;
|
||||||
pub mod calendar_store;
|
pub mod calendar_store;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, sqlx::Type)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
pub(crate) enum ChangeOperation {
|
||||||
|
// There's no distinction between Add and Modify
|
||||||
|
Add,
|
||||||
|
Delete,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SqliteStore {
|
pub struct SqliteStore {
|
||||||
db: SqlitePool,
|
db: SqlitePool,
|
||||||
|
|||||||
Reference in New Issue
Block a user