Skip to content

Commit

Permalink
refactor(schema): add a new column for storing large connector transa…
Browse files Browse the repository at this point in the history
…ction IDs (#7017)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
kashif-m and hyperswitch-bot[bot] authored Feb 12, 2025
1 parent 40a36fd commit fa09db1
Show file tree
Hide file tree
Showing 28 changed files with 987 additions and 122 deletions.
8 changes: 4 additions & 4 deletions crates/common_utils/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ crate::impl_to_sql_from_sql_json!(BrowserInformation);
/// In case connector's use an identifier whose length exceeds 128 characters,
/// the hash value of such identifiers will be stored as connector_transaction_id.
/// The actual connector's identifier will be stored in a separate column -
/// connector_transaction_data or something with a similar name.
/// processor_transaction_data or something with a similar name.
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, AsExpression)]
#[diesel(sql_type = sql_types::Text)]
pub enum ConnectorTransactionId {
Expand All @@ -1438,7 +1438,7 @@ impl ConnectorTransactionId {
}
}

/// Implementation for forming ConnectorTransactionId and an optional string to be used for connector_transaction_id and connector_transaction_data
/// Implementation for forming ConnectorTransactionId and an optional string to be used for connector_transaction_id and processor_transaction_data
pub fn form_id_and_data(src: String) -> (Self, Option<String>) {
let txn_id = Self::from(src.clone());
match txn_id {
Expand All @@ -1456,10 +1456,10 @@ impl ConnectorTransactionId {
(Self::TxnId(id), _) => Ok(id),
(Self::HashedData(_), Some(id)) => Ok(id),
(Self::HashedData(id), None) => Err(report!(ValidationError::InvalidValue {
message: "connector_transaction_data is empty for HashedData variant".to_string(),
message: "processor_transaction_data is empty for HashedData variant".to_string(),
})
.attach_printable(format!(
"connector_transaction_data is empty for connector_transaction_id {}",
"processor_transaction_data is empty for connector_transaction_id {}",
id
))),
}
Expand Down
16 changes: 10 additions & 6 deletions crates/diesel_models/src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ pub struct Capture {
pub capture_sequence: i16,
// reference to the capture at connector side
pub connector_response_reference_id: Option<String>,
/// INFO: This field is deprecated and replaced by processor_capture_data
pub connector_capture_data: Option<String>,
pub processor_capture_data: Option<String>,
}

#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay, Serialize, Deserialize)]
Expand All @@ -55,7 +57,9 @@ pub struct CaptureNew {
pub connector_capture_id: Option<ConnectorTransactionId>,
pub capture_sequence: i16,
pub connector_response_reference_id: Option<String>,
/// INFO: This field is deprecated and replaced by processor_capture_data
pub connector_capture_data: Option<String>,
pub processor_capture_data: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -64,7 +68,7 @@ pub enum CaptureUpdate {
status: storage_enums::CaptureStatus,
connector_capture_id: Option<ConnectorTransactionId>,
connector_response_reference_id: Option<String>,
connector_capture_data: Option<String>,
processor_capture_data: Option<String>,
},
ErrorUpdate {
status: storage_enums::CaptureStatus,
Expand All @@ -84,7 +88,7 @@ pub struct CaptureUpdateInternal {
pub modified_at: Option<PrimitiveDateTime>,
pub connector_capture_id: Option<ConnectorTransactionId>,
pub connector_response_reference_id: Option<String>,
pub connector_capture_data: Option<String>,
pub processor_capture_data: Option<String>,
}

impl CaptureUpdate {
Expand All @@ -97,7 +101,7 @@ impl CaptureUpdate {
modified_at: _,
connector_capture_id,
connector_response_reference_id,
connector_capture_data,
processor_capture_data,
} = self.into();
Capture {
status: status.unwrap_or(source.status),
Expand All @@ -108,7 +112,7 @@ impl CaptureUpdate {
connector_capture_id: connector_capture_id.or(source.connector_capture_id),
connector_response_reference_id: connector_response_reference_id
.or(source.connector_response_reference_id),
connector_capture_data: connector_capture_data.or(source.connector_capture_data),
processor_capture_data: processor_capture_data.or(source.processor_capture_data),
..source
}
}
Expand All @@ -122,13 +126,13 @@ impl From<CaptureUpdate> for CaptureUpdateInternal {
status,
connector_capture_id: connector_transaction_id,
connector_response_reference_id,
connector_capture_data,
processor_capture_data,
} => Self {
status: Some(status),
connector_capture_id: connector_transaction_id,
modified_at: now,
connector_response_reference_id,
connector_capture_data,
processor_capture_data,
..Self::default()
},
CaptureUpdate::ErrorUpdate {
Expand Down
2 changes: 1 addition & 1 deletion crates/diesel_models/src/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub enum Insertable {
pub enum Updateable {
PaymentIntentUpdate(Box<PaymentIntentUpdateMems>),
PaymentAttemptUpdate(Box<PaymentAttemptUpdateMems>),
RefundUpdate(RefundUpdateMems),
RefundUpdate(Box<RefundUpdateMems>),
CustomerUpdate(CustomerUpdateMems),
AddressUpdate(Box<AddressUpdateMems>),
PayoutsUpdate(PayoutsUpdateMems),
Expand Down
Loading

0 comments on commit fa09db1

Please sign in to comment.