Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(payment_method_v2): add `customer_id` column in v2 customers table (#10933)

Shankar Singh Cb55eeaefb9f6
diff --git a/crates/diesel_models/src/customers.rs b/crates/diesel_models/src/customers.rs
index 2f704b6db7..f9eef640d1 100644
--- a/crates/diesel_models/src/customers.rs
+++ b/crates/diesel_models/src/customers.rs
@@ -95,6 +95,7 @@ pub struct CustomerNew {
pub id: common_utils::id_type::GlobalCustomerId,
pub created_by: Option<String>,
pub last_modified_by: Option<String>,
+ pub customer_id: Option<common_utils::id_type::GlobalCustomerId>,
}
#[cfg(feature = "v2")]
@@ -129,6 +130,7 @@ impl From<CustomerNew> for Customer {
status: customer_new.status,
created_by: customer_new.created_by,
last_modified_by: customer_new.last_modified_by,
+ customer_id: customer_new.customer_id,
}
}
}
@@ -187,6 +189,7 @@ pub struct Customer {
#[diesel(deserialize_as = RequiredFromNullableWithDefault<DeleteStatus>)]
pub status: DeleteStatus,
pub id: common_utils::id_type::GlobalCustomerId,
+ pub customer_id: Option<common_utils::id_type::GlobalCustomerId>,
}
#[cfg(feature = "v1")]
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 29dc664d20..1d71f5416b 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -431,6 +431,8 @@ diesel::table! {
status -> Nullable<DeleteStatus>,
#[max_length = 64]
id -> Varchar,
+ #[max_length = 64]
+ customer_id -> Nullable<Varchar>,
}
}
diff --git a/crates/hyperswitch_domain_models/src/customer.rs b/crates/hyperswitch_domain_models/src/customer.rs
index 40ec1db1e7..438d0c7514 100644
--- a/crates/hyperswitch_domain_models/src/customer.rs
+++ b/crates/hyperswitch_domain_models/src/customer.rs
@@ -275,7 +275,8 @@ impl behaviour::Conversion for Customer {
type NewDstType = diesel_models::customers::CustomerNew;
async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
Ok(diesel_models::customers::Customer {
- id: self.id,
+ id: self.id.clone(),
+ customer_id: Some(self.id),
merchant_reference_id: self.merchant_reference_id,
merchant_id: self.merchant_id,
name: self.name.map(Encryption::from),
@@ -373,7 +374,7 @@ impl behaviour::Conversion for Customer {
async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
let now = date_time::now();
Ok(diesel_models::customers::CustomerNew {
- id: self.id,
+ id: self.id.clone(),
merchant_reference_id: self.merchant_reference_id,
merchant_id: self.merchant_id,
name: self.name.map(Encryption::from),
@@ -397,6 +398,7 @@ impl behaviour::Conversion for Customer {
.as_ref()
.map(|created_by| created_by.to_string()),
last_modified_by: self.created_by.map(|created_by| created_by.to_string()), // Same as created_by on creation
+ customer_id: Some(self.id),
})
}
}
diff --git a/v2_migrations/2026-01-13-131545_add customer_id in v2 customers table/down.sql b/v2_migrations/2026-01-13-131545_add customer_id in v2 customers table/down.sql
new file mode 100644
index 0000000000..dfc51f9ce0
--- /dev/null
+++ b/v2_migrations/2026-01-13-131545_add customer_id in v2 customers table/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE customers DROP COLUMN IF EXISTS customer_id;
\ No newline at end of file
diff --git a/v2_migrations/2026-01-13-131545_add customer_id in v2 customers table/up.sql b/v2_migrations/2026-01-13-131545_add customer_id in v2 customers table/up.sql
new file mode 100644
index 0000000000..25b070a363
--- /dev/null
+++ b/v2_migrations/2026-01-13-131545_add customer_id in v2 customers table/up.sql
@@ -0,0 +1,2 @@
+-- Your SQL goes here
+ALTER TABLE customers ADD COLUMN customer_id VARCHAR(64);
\ No newline at end of file