1
//! Records the prices whose two legs belong to different transactions.
2
//!
3
//! Such rows are legacy data: an update or delete of either transaction would
4
//! drop the price, so the transactions refuse to change until the owner
5
//! resolves the finding.
6

            
7
use crate::db::DBError;
8
use sqlx::{PgConnection, types::Uuid};
9

            
10
#[cfg(test)]
11
pub(crate) mod fixture;
12
#[cfg(test)]
13
mod tests;
14

            
15
pub(crate) const KIND: &str = "cross-transaction-price";
16

            
17
const DETAIL: &str = "the price's two legs are in different transactions; subjects are the \
18
price id, the transaction of its commodity leg, the transaction of its currency leg";
19

            
20
7206
pub(super) async fn run(conn: &mut PgConnection) -> Result<(), DBError> {
21
7206
    let prices = sqlx::query_file!("sql/select/prices/cross_transaction.sql", None::<Uuid>)
22
7206
        .fetch_all(&mut *conn)
23
7206
        .await?;
24
7206
    for price in prices {
25
3
        let subjects = [price.price_id, price.commodity_tx_id, price.currency_tx_id];
26
3
        sqlx::query_file!(
27
            "sql/insert/data_findings/record.sql",
28
            KIND,
29
3
            &subjects[..],
30
            DETAIL
31
        )
32
3
        .execute(&mut *conn)
33
3
        .await?;
34
    }
35
7206
    Ok(())
36
7206
}