Lines
100 %
Functions
Branches
//! Records the prices whose two legs belong to different transactions.
//!
//! Such rows are legacy data: an update or delete of either transaction would
//! drop the price, so the transactions refuse to change until the owner
//! resolves the finding.
use crate::db::DBError;
use sqlx::{PgConnection, types::Uuid};
#[cfg(test)]
pub(crate) mod fixture;
mod tests;
pub(crate) const KIND: &str = "cross-transaction-price";
const DETAIL: &str = "the price's two legs are in different transactions; subjects are the \
price id, the transaction of its commodity leg, the transaction of its currency leg";
pub(super) async fn run(conn: &mut PgConnection) -> Result<(), DBError> {
let prices = sqlx::query_file!("sql/select/prices/cross_transaction.sql", None::<Uuid>)
.fetch_all(&mut *conn)
.await?;
for price in prices {
let subjects = [price.price_id, price.commodity_tx_id, price.currency_tx_id];
sqlx::query_file!(
"sql/insert/data_findings/record.sql",
KIND,
&subjects[..],
DETAIL
)
.execute(&mut *conn)
}
Ok(())