refactor(schema): add a new column for storing large customer user agents in mandate table (#8616)

This commit is contained in:
Pa1NarK
2025-07-25 14:58:37 +05:30
committed by GitHub
parent dbdf7579d2
commit b74c1e9188
8 changed files with 29 additions and 4 deletions

View File

@ -35,6 +35,8 @@ pub struct Mandate {
pub original_payment_id: Option<common_utils::id_type::PaymentId>,
pub merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
pub updated_by: Option<String>,
// This is the extended version of customer user agent that can store string upto 2048 characters unlike customer user agent that can store 255 characters at max
pub customer_user_agent_extended: Option<String>,
}
#[derive(
@ -73,6 +75,7 @@ pub struct MandateNew {
pub original_payment_id: Option<common_utils::id_type::PaymentId>,
pub merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
pub updated_by: Option<String>,
pub customer_user_agent_extended: Option<String>,
}
impl MandateNew {
@ -216,7 +219,7 @@ impl From<&MandateNew> for Mandate {
mandate_type: mandate_new.mandate_type,
customer_accepted_at: mandate_new.customer_accepted_at,
customer_ip_address: mandate_new.customer_ip_address.clone(),
customer_user_agent: mandate_new.customer_user_agent.clone(),
customer_user_agent: None,
network_transaction_id: mandate_new.network_transaction_id.clone(),
previous_attempt_id: mandate_new.previous_attempt_id.clone(),
created_at: mandate_new
@ -234,6 +237,11 @@ impl From<&MandateNew> for Mandate {
original_payment_id: mandate_new.original_payment_id.clone(),
merchant_connector_id: mandate_new.merchant_connector_id.clone(),
updated_by: mandate_new.updated_by.clone(),
// Using customer_user_agent as a fallback
customer_user_agent_extended: mandate_new
.customer_user_agent_extended
.clone()
.or_else(|| mandate_new.customer_user_agent.clone()),
}
}
}

View File

@ -723,6 +723,8 @@ diesel::table! {
merchant_connector_id -> Nullable<Varchar>,
#[max_length = 64]
updated_by -> Nullable<Varchar>,
#[max_length = 2048]
customer_user_agent_extended -> Nullable<Varchar>,
}
}

View File

@ -736,6 +736,8 @@ diesel::table! {
merchant_connector_id -> Nullable<Varchar>,
#[max_length = 64]
updated_by -> Nullable<Varchar>,
#[max_length = 2048]
customer_user_agent_extended -> Nullable<Varchar>,
}
}

View File

@ -3439,7 +3439,7 @@ pub fn generate_mandate(
.get_ip_address()
.map(masking::Secret::new),
)
.set_customer_user_agent(customer_acceptance.get_user_agent())
.set_customer_user_agent_extended(customer_acceptance.get_user_agent())
.set_customer_accepted_at(Some(customer_acceptance.get_accepted_at()))
.set_metadata(payment_method_data_option.map(|payment_method_data| {
pii::SecretSerdeValue::new(

View File

@ -671,7 +671,7 @@ impl MandateInterface for MockDb {
mandate_type: mandate_new.mandate_type,
customer_accepted_at: mandate_new.customer_accepted_at,
customer_ip_address: mandate_new.customer_ip_address,
customer_user_agent: mandate_new.customer_user_agent,
customer_user_agent: None,
network_transaction_id: mandate_new.network_transaction_id,
previous_attempt_id: mandate_new.previous_attempt_id,
created_at: mandate_new
@ -688,6 +688,10 @@ impl MandateInterface for MockDb {
connector_mandate_ids: mandate_new.connector_mandate_ids,
merchant_connector_id: mandate_new.merchant_connector_id,
updated_by: mandate_new.updated_by,
// Using customer_user_agent as a fallback
customer_user_agent_extended: mandate_new
.customer_user_agent_extended
.or_else(|| mandate_new.customer_user_agent.clone()),
};
mandates.push(mandate.clone());
Ok(mandate)

View File

@ -106,7 +106,11 @@ impl MandateResponseExt for MandateResponse {
accepted_at: mandate.customer_accepted_at,
online: Some(api::payments::OnlineMandate {
ip_address: mandate.customer_ip_address,
user_agent: mandate.customer_user_agent.unwrap_or_default(),
// Using customer_user_agent as a fallback
user_agent: mandate
.customer_user_agent_extended
.or(mandate.customer_user_agent)
.unwrap_or_default(),
}),
}),
card,

View File

@ -0,0 +1 @@
ALTER TABLE mandate DROP COLUMN IF EXISTS customer_user_agent_extended;

View File

@ -0,0 +1,4 @@
ALTER TABLE mandate
ADD COLUMN
IF NOT EXISTS customer_user_agent_extended VARCHAR
(2048);