Add identity_hash column
Build and Publish Docker Container / build (push) Failing after 9m27s

This commit is contained in:
2024-05-29 21:08:51 +01:00
parent f19f861297
commit 3df05b2d9c
5 changed files with 57 additions and 2 deletions
+3 -1
View File
@@ -82,10 +82,12 @@ async fn update_transactions(
insertions: &[Insertion],
tx: &DatabaseTransaction,
) -> Result<Vec<String>, AppError> {
let insert =
transaction::Entity::insert_many(insertions.iter().map(|i| &i.transaction).cloned())
.on_conflict(
OnConflict::column(transaction::Column::Id)
OnConflict::columns([transaction::Column::Id, transaction::Column::IdentityHash])
.update_columns(transaction::Column::iter())
.to_owned(),
)
+13
View File
@@ -1,3 +1,4 @@
use std::hash::Hash;
use crate::ingestion::db::Insertion;
use anyhow::{anyhow, Context};
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime};
@@ -64,6 +65,17 @@ impl MonzoRow {
}.into_active_model())
}
/// Compute a hash of this row, returning the number as an i64 to be used as a unique constraint
/// in the database.
pub fn compute_hash(&self) -> i64 {
use std::collections::hash_map::DefaultHasher;
use std::hash::Hasher;
let mut hasher = DefaultHasher::new();
self.hash(&mut hasher);
hasher.finish() as i64
}
pub fn into_insertion(self) -> Result<Insertion, anyhow::Error> {
let expenditures: Vec<_> = match self.category_split {
Some(split) if !split.is_empty() => split
@@ -90,6 +102,7 @@ impl MonzoRow {
receipt: self.receipt,
total_amount: self.total_amount,
description: self.description,
identity_hash: Some(self.compute_hash()),
}.into_active_model(),
contained_expenditures: expenditures,