diff --git a/Cargo.lock b/Cargo.lock index ddccb6b279d3..66bace95e7a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -487,7 +487,8 @@ dependencies = [ [[package]] name = "async-bb8-diesel" version = "0.1.0" -source = "git+https://github.com/oxidecomputer/async-bb8-diesel?rev=be3d9bce50051d8c0e0c06078e8066cc27db3001#be3d9bce50051d8c0e0c06078e8066cc27db3001" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "779f1fa3defe66bf147fe5c811b23a02cfcaa528a25293e0b20d1911eac1fb05" dependencies = [ "async-trait", "bb8", diff --git a/crates/diesel_models/Cargo.toml b/crates/diesel_models/Cargo.toml index 3e8efe30025d..1a0bdfe5674e 100644 --- a/crates/diesel_models/Cargo.toml +++ b/crates/diesel_models/Cargo.toml @@ -15,7 +15,7 @@ kv_store = [] s3 = ["dep:aws-sdk-s3", "dep:aws-config"] [dependencies] -async-bb8-diesel = { git = "https://github.com/oxidecomputer/async-bb8-diesel", rev = "be3d9bce50051d8c0e0c06078e8066cc27db3001" } +async-bb8-diesel = "0.1.0" aws-config = { version = "0.55.3", optional = true } aws-sdk-s3 = { version = "0.28.0", optional = true } diesel = { version = "2.1.0", features = ["postgres", "serde_json", "time", "64-column-tables"] } diff --git a/crates/diesel_models/src/query/generics.rs b/crates/diesel_models/src/query/generics.rs index 33956ab4571e..667b2516bd9a 100644 --- a/crates/diesel_models/src/query/generics.rs +++ b/crates/diesel_models/src/query/generics.rs @@ -1,6 +1,6 @@ use std::fmt::Debug; -use async_bb8_diesel::{AsyncRunQueryDsl, ConnectionError}; +use async_bb8_diesel::AsyncRunQueryDsl; use diesel::{ associations::HasTable, debug_query, @@ -93,10 +93,9 @@ where { Ok(value) => Ok(value), Err(err) => match err.current_context() { - ConnectionError::Query(DieselError::DatabaseError( - diesel::result::DatabaseErrorKind::UniqueViolation, - _, - )) => Err(err).change_context(errors::DatabaseError::UniqueViolation), + DieselError::DatabaseError(diesel::result::DatabaseErrorKind::UniqueViolation, _) => { + Err(err).change_context(errors::DatabaseError::UniqueViolation) + } _ => Err(err).change_context(errors::DatabaseError::Others), }, } @@ -168,14 +167,12 @@ where logger::debug!(query = %debug_query::(&query).to_string()); Ok(result) } - Err(ConnectionError::Query(DieselError::QueryBuilderError(_))) => { + Err(DieselError::QueryBuilderError(_)) => { Err(report!(errors::DatabaseError::NoFieldsToUpdate)) .attach_printable_lazy(|| format!("Error while updating {debug_values}")) } - Err(ConnectionError::Query(DieselError::NotFound)) => { - Err(report!(errors::DatabaseError::NotFound)) - .attach_printable_lazy(|| format!("Error while updating {debug_values}")) - } + Err(DieselError::NotFound) => Err(report!(errors::DatabaseError::NotFound)) + .attach_printable_lazy(|| format!("Error while updating {debug_values}")), _ => Err(report!(errors::DatabaseError::Others)) .attach_printable_lazy(|| format!("Error while updating {debug_values}")), } @@ -259,14 +256,12 @@ where logger::debug!(query = %debug_query::(&query).to_string()); Ok(result) } - Err(ConnectionError::Query(DieselError::QueryBuilderError(_))) => { + Err(DieselError::QueryBuilderError(_)) => { Err(report!(errors::DatabaseError::NoFieldsToUpdate)) .attach_printable_lazy(|| format!("Error while updating by ID {debug_values}")) } - Err(ConnectionError::Query(DieselError::NotFound)) => { - Err(report!(errors::DatabaseError::NotFound)) - .attach_printable_lazy(|| format!("Error while updating by ID {debug_values}")) - } + Err(DieselError::NotFound) => Err(report!(errors::DatabaseError::NotFound)) + .attach_printable_lazy(|| format!("Error while updating by ID {debug_values}")), _ => Err(report!(errors::DatabaseError::Others)) .attach_printable_lazy(|| format!("Error while updating by ID {debug_values}")), } @@ -353,9 +348,7 @@ where { Ok(value) => Ok(value), Err(err) => match err.current_context() { - ConnectionError::Query(DieselError::NotFound) => { - Err(err).change_context(errors::DatabaseError::NotFound) - } + DieselError::NotFound => Err(err).change_context(errors::DatabaseError::NotFound), _ => Err(err).change_context(errors::DatabaseError::Others), }, } @@ -404,9 +397,7 @@ where .await .into_report() .map_err(|err| match err.current_context() { - ConnectionError::Query(DieselError::NotFound) => { - err.change_context(errors::DatabaseError::NotFound) - } + DieselError::NotFound => err.change_context(errors::DatabaseError::NotFound), _ => err.change_context(errors::DatabaseError::Others), }) .attach_printable_lazy(|| "Error finding record by predicate") diff --git a/crates/drainer/Cargo.toml b/crates/drainer/Cargo.toml index 2b0ade029304..3bf056a69b38 100644 --- a/crates/drainer/Cargo.toml +++ b/crates/drainer/Cargo.toml @@ -13,7 +13,7 @@ kms = ["external_services/kms"] vergen = ["router_env/vergen"] [dependencies] -async-bb8-diesel = { git = "https://github.com/oxidecomputer/async-bb8-diesel", rev = "be3d9bce50051d8c0e0c06078e8066cc27db3001" } +async-bb8-diesel = "0.1.0" bb8 = "0.8" clap = { version = "4.3.2", default-features = false, features = ["std", "derive", "help", "usage"] } config = { version = "0.13.3", features = ["toml"] } diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml index da207e91493f..fd8b21520b5c 100644 --- a/crates/router/Cargo.toml +++ b/crates/router/Cargo.toml @@ -35,7 +35,7 @@ actix-cors = "0.6.4" actix-multipart = "0.6.0" actix-rt = "2.8.0" actix-web = "4.3.1" -async-bb8-diesel = { git = "https://github.com/oxidecomputer/async-bb8-diesel", rev = "be3d9bce50051d8c0e0c06078e8066cc27db3001" } +async-bb8-diesel = "0.1.0" async-trait = "0.1.68" aws-config = { version = "0.55.3", optional = true } aws-sdk-s3 = { version = "0.28.0", optional = true } diff --git a/crates/storage_impl/Cargo.toml b/crates/storage_impl/Cargo.toml index e4c41c41b6f4..8fb59d213364 100644 --- a/crates/storage_impl/Cargo.toml +++ b/crates/storage_impl/Cargo.toml @@ -28,7 +28,7 @@ router_derive = { version = "0.1.0", path = "../router_derive" } # Third party crates actix-web = "4.3.1" -async-bb8-diesel = { git = "https://github.com/oxidecomputer/async-bb8-diesel", rev = "be3d9bce50051d8c0e0c06078e8066cc27db3001" } +async-bb8-diesel = "0.1.0" async-trait = "0.1.72" bb8 = "0.8.1" bytes = "1.4.0" diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs index d0f56a40d02b..e1149098ec4e 100644 --- a/crates/storage_impl/src/payments/payment_intent.rs +++ b/crates/storage_impl/src/payments/payment_intent.rs @@ -1,5 +1,5 @@ #[cfg(feature = "olap")] -use async_bb8_diesel::AsyncRunQueryDsl; +use async_bb8_diesel::{AsyncConnection, AsyncRunQueryDsl}; use common_utils::{date_time, ext_traits::Encode}; #[cfg(feature = "olap")] use data_models::payments::payment_intent::PaymentIntentFetchConstraints; @@ -34,6 +34,8 @@ use redis_interface::HsetnxReply; use router_env::logger; use router_env::{instrument, tracing}; +#[cfg(feature = "olap")] +use crate::connection; use crate::{ diesel_error_to_data_error, redis::kv_store::{kv_wrapper, KvOperation}, @@ -387,7 +389,10 @@ impl PaymentIntentInterface for crate::RouterStore { filters: &PaymentIntentFetchConstraints, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result, StorageError> { - let conn = self.get_replica_pool(); + use common_utils::errors::ReportSwitchExt; + + let conn = connection::pg_connection_read(self).await.switch()?; + let conn = async_bb8_diesel::Connection::as_async_conn(&conn); //[#350]: Replace this with Boxable Expression and pass it into generic filter // when https://github.com/rust-lang/rust/issues/52662 becomes stable @@ -509,8 +514,10 @@ impl PaymentIntentInterface for crate::RouterStore { constraints: &PaymentIntentFetchConstraints, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result, StorageError> { - let conn = self.get_replica_pool(); + use common_utils::errors::ReportSwitchExt; + let conn = connection::pg_connection_read(self).await.switch()?; + let conn = async_bb8_diesel::Connection::as_async_conn(&conn); let mut query = DieselPaymentIntent::table() .inner_join( diesel_models::schema::payment_attempt::table @@ -646,8 +653,10 @@ impl PaymentIntentInterface for crate::RouterStore { constraints: &PaymentIntentFetchConstraints, _storage_scheme: MerchantStorageScheme, ) -> error_stack::Result, StorageError> { - let conn = self.get_replica_pool(); + use common_utils::errors::ReportSwitchExt; + let conn = connection::pg_connection_read(self).await.switch()?; + let conn = async_bb8_diesel::Connection::as_async_conn(&conn); let mut query = DieselPaymentIntent::table() .select(pi_dsl::active_attempt_id) .filter(pi_dsl::merchant_id.eq(merchant_id.to_owned()))