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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(accounts): move accounts related tables to accounts schema (#7626)
Hrithikesh4b7f55aeedfc
diff --git a/crates/common_types/src/payment_methods.rs b/crates/common_types/src/payment_methods.rsindex c6b492a103..0a5b79de75 100644--- a/crates/common_types/src/payment_methods.rs+++ b/crates/common_types/src/payment_methods.rs@@ -1,15 +1,24 @@//! Common types to be used in payment methodsuse diesel::{- backend::Backend, deserialize, deserialize::FromSql, sql_types::Jsonb, AsExpression, Queryable,+ backend::Backend,+ deserialize,+ deserialize::FromSql,+ sql_types::{Json, Jsonb},+ AsExpression, Queryable,};use serde::{Deserialize, Serialize};use utoipa::ToSchema;/// Details of all the payment methods enabled for the connector for the given merchant account++// sql_type for this can be json instead of jsonb. This is because validation at database is not required since it will always be written by the application.+// This is a performance optimization to avoid json validation at database level.+// jsonb enables faster querying on json columns, but it doesn't justify here since we are not querying on this column.+// https://docs.rs/diesel/latest/diesel/sql_types/struct.Jsonb.html#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, AsExpression)]#[serde(deny_unknown_fields)]-#[diesel(sql_type = Jsonb)]+#[diesel(sql_type = Json)]pub struct PaymentMethodsEnabled {/// Type of payment method.#[schema(value_type = PaymentMethod,example = "card")]diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rsindex ca1fe56a77..94da0f0438 100644--- a/crates/diesel_models/src/business_profile.rs+++ b/crates/diesel_models/src/business_profile.rs@@ -68,6 +68,7 @@ pub struct Profile {pub force_3ds_challenge: Option<bool>,pub is_debit_routing_enabled: bool,pub merchant_business_country: Option<common_enums::CountryAlpha2>,+ pub id: Option<common_utils::id_type::ProfileId>,}#[cfg(feature = "v1")]@@ -120,6 +121,7 @@ pub struct ProfileNew {pub force_3ds_challenge: Option<bool>,pub is_debit_routing_enabled: bool,pub merchant_business_country: Option<common_enums::CountryAlpha2>,+ pub id: Option<common_utils::id_type::ProfileId>,}#[cfg(feature = "v1")]@@ -289,6 +291,7 @@ impl ProfileUpdateInternal {is_clear_pan_retries_enabled: is_clear_pan_retries_enabled.unwrap_or(source.is_clear_pan_retries_enabled),force_3ds_challenge,+ id: source.id,is_debit_routing_enabled,merchant_business_country: merchant_business_country.or(source.merchant_business_country),@@ -348,6 +351,7 @@ pub struct Profile {pub force_3ds_challenge: Option<bool>,pub is_debit_routing_enabled: bool,pub merchant_business_country: Option<common_enums::CountryAlpha2>,+ pub id: common_utils::id_type::ProfileId,pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,pub order_fulfillment_time: Option<i64>,pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,@@ -356,7 +360,6 @@ pub struct Profile {pub default_fallback_routing: Option<pii::SecretSerdeValue>,pub three_ds_decision_manager_config: Option<common_types::payments::DecisionManagerRecord>,pub should_collect_cvv_during_payment: bool,- pub id: common_utils::id_type::ProfileId,}impl Profile {diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rsindex 5ee54987cd..769a185c13 100644--- a/crates/diesel_models/src/merchant_connector_account.rs+++ b/crates/diesel_models/src/merchant_connector_account.rs@@ -54,6 +54,7 @@ pub struct MerchantConnectorAccount {pub additional_merchant_data: Option<Encryption>,pub connector_wallets_details: Option<Encryption>,pub version: common_enums::ApiVersion,+ pub id: Option<id_type::MerchantConnectorAccountId>,}#[cfg(feature = "v1")]@@ -98,8 +99,8 @@ pub struct MerchantConnectorAccount {pub additional_merchant_data: Option<Encryption>,pub connector_wallets_details: Option<Encryption>,pub version: common_enums::ApiVersion,- pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,pub id: id_type::MerchantConnectorAccountId,+ pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,}#[cfg(feature = "v2")]@@ -140,6 +141,7 @@ pub struct MerchantConnectorAccountNew {pub additional_merchant_data: Option<Encryption>,pub connector_wallets_details: Option<Encryption>,pub version: common_enums::ApiVersion,+ pub id: Option<id_type::MerchantConnectorAccountId>,}#[cfg(feature = "v2")]@@ -167,8 +169,8 @@ pub struct MerchantConnectorAccountNew {pub status: storage_enums::ConnectorStatus,pub additional_merchant_data: Option<Encryption>,pub connector_wallets_details: Option<Encryption>,- pub id: id_type::MerchantConnectorAccountId,pub version: common_enums::ApiVersion,+ pub id: id_type::MerchantConnectorAccountId,pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,}diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 0e583b5bb7..7aabdeb26d 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -223,6 +223,8 @@ diesel::table! {force_3ds_challenge -> Nullable<Bool>,is_debit_routing_enabled -> Bool,merchant_business_country -> Nullable<CountryAlpha2>,+ #[max_length = 64]+ id -> Nullable<Varchar>,}}@@ -788,6 +790,8 @@ diesel::table! {additional_merchant_data -> Nullable<Bytea>,connector_wallets_details -> Nullable<Bytea>,version -> ApiVersion,+ #[max_length = 64]+ id -> Nullable<Varchar>,}}diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex 6373c0e564..a8ee8a78d8 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -220,6 +220,8 @@ diesel::table! {is_debit_routing_enabled -> Bool,merchant_business_country -> Nullable<CountryAlpha2>,#[max_length = 64]+ id -> Varchar,+ #[max_length = 64]routing_algorithm_id -> Nullable<Varchar>,order_fulfillment_time -> Nullable<Int8>,order_fulfillment_time_origin -> Nullable<OrderFulfillmentTimeOrigin>,@@ -230,8 +232,6 @@ diesel::table! {default_fallback_routing -> Nullable<Jsonb>,three_ds_decision_manager_config -> Nullable<Jsonb>,should_collect_cvv_during_payment -> Bool,- #[max_length = 64]- id -> Varchar,}}@@ -750,7 +750,7 @@ diesel::table! {connector_name -> Varchar,connector_account_details -> Bytea,disabled -> Nullable<Bool>,- payment_methods_enabled -> Nullable<Array<Nullable<Jsonb>>>,+ payment_methods_enabled -> Nullable<Array<Nullable<Json>>>,connector_type -> ConnectorType,metadata -> Nullable<Jsonb>,#[max_length = 255]@@ -767,9 +767,9 @@ diesel::table! {additional_merchant_data -> Nullable<Bytea>,connector_wallets_details -> Nullable<Bytea>,version -> ApiVersion,- feature_metadata -> Nullable<Jsonb>,#[max_length = 64]id -> Varchar,+ feature_metadata -> Nullable<Jsonb>,}}diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rsindex b7fa027bb0..c9e3b4f51f 100644--- a/crates/hyperswitch_domain_models/src/business_profile.rs+++ b/crates/hyperswitch_domain_models/src/business_profile.rs@@ -641,7 +641,8 @@ impl super::behaviour::Conversion for Profile {async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {Ok(diesel_models::business_profile::Profile {- profile_id: self.profile_id,+ profile_id: self.profile_id.clone(),+ id: Some(self.profile_id),merchant_id: self.merchant_id,profile_name: self.profile_name,created_at: self.created_at,@@ -793,7 +794,8 @@ impl super::behaviour::Conversion for Profile {async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {Ok(diesel_models::business_profile::ProfileNew {- profile_id: self.profile_id,+ profile_id: self.profile_id.clone(),+ id: Some(self.profile_id),merchant_id: self.merchant_id,profile_name: self.profile_name,created_at: self.created_at,diff --git a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs b/crates/hyperswitch_domain_models/src/merchant_connector_account.rsindex 1c4946a496..d888651428 100644--- a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs+++ b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs@@ -356,7 +356,8 @@ impl behaviour::Conversion for MerchantConnectorAccount {connector_account_details: self.connector_account_details.into(),test_mode: self.test_mode,disabled: self.disabled,- merchant_connector_id: self.merchant_connector_id,+ merchant_connector_id: self.merchant_connector_id.clone(),+ id: Some(self.merchant_connector_id),payment_methods_enabled: self.payment_methods_enabled,connector_type: self.connector_type,metadata: self.metadata,@@ -452,7 +453,8 @@ impl behaviour::Conversion for MerchantConnectorAccount {connector_account_details: Some(self.connector_account_details.into()),test_mode: self.test_mode,disabled: self.disabled,- merchant_connector_id: self.merchant_connector_id,+ merchant_connector_id: self.merchant_connector_id.clone(),+ id: Some(self.merchant_connector_id),payment_methods_enabled: self.payment_methods_enabled,connector_type: Some(self.connector_type),metadata: self.metadata,diff --git a/crates/router/src/db.rs b/crates/router/src/db.rsindex 84f5c34a82..7c3b74bda4 100644--- a/crates/router/src/db.rs+++ b/crates/router/src/db.rs@@ -161,7 +161,14 @@ pub trait GlobalStorageInterface:#[async_trait::async_trait]pub trait AccountsStorageInterface:- Send + Sync + dyn_clone::DynClone + OrganizationInterface + 'static+ Send+ + Sync+ + dyn_clone::DynClone+ + OrganizationInterface+ + merchant_account::MerchantAccountInterface+ + business_profile::ProfileInterface+ + merchant_connector_account::MerchantConnectorAccountInterface+ + 'static{}diff --git a/crates/router/src/db/business_profile.rs b/crates/router/src/db/business_profile.rsindex 61abb0d6fe..1a087c2903 100644--- a/crates/router/src/db/business_profile.rs+++ b/crates/router/src/db/business_profile.rs@@ -82,7 +82,7 @@ impl ProfileInterface for Store {merchant_key_store: &domain::MerchantKeyStore,business_profile: domain::Profile,) -> CustomResult<domain::Profile, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;business_profile.construct_new().await@@ -106,7 +106,7 @@ impl ProfileInterface for Store {merchant_key_store: &domain::MerchantKeyStore,profile_id: &common_utils::id_type::ProfileId,) -> CustomResult<domain::Profile, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::Profile::find_by_profile_id(&conn, profile_id).await.map_err(|error| report!(errors::StorageError::from(error)))?@@ -126,7 +126,7 @@ impl ProfileInterface for Store {merchant_id: &common_utils::id_type::MerchantId,profile_id: &common_utils::id_type::ProfileId,) -> CustomResult<domain::Profile, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::Profile::find_by_merchant_id_profile_id(&conn, merchant_id, profile_id).await.map_err(|error| report!(errors::StorageError::from(error)))?@@ -147,7 +147,7 @@ impl ProfileInterface for Store {profile_name: &str,merchant_id: &common_utils::id_type::MerchantId,) -> CustomResult<domain::Profile, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::Profile::find_by_profile_name_merchant_id(&conn, profile_name, merchant_id).await.map_err(|error| report!(errors::StorageError::from(error)))?@@ -168,7 +168,7 @@ impl ProfileInterface for Store {current_state: domain::Profile,profile_update: domain::ProfileUpdate,) -> CustomResult<domain::Profile, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;Conversion::convert(current_state).await.change_context(errors::StorageError::EncryptionError)?@@ -190,7 +190,7 @@ impl ProfileInterface for Store {profile_id: &common_utils::id_type::ProfileId,merchant_id: &common_utils::id_type::MerchantId,) -> CustomResult<bool, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;storage::Profile::delete_by_profile_id_merchant_id(&conn, profile_id, merchant_id).await.map_err(|error| report!(errors::StorageError::from(error)))@@ -203,7 +203,7 @@ impl ProfileInterface for Store {merchant_key_store: &domain::MerchantKeyStore,merchant_id: &common_utils::id_type::MerchantId,) -> CustomResult<Vec<domain::Profile>, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::Profile::list_profile_by_merchant_id(&conn, merchant_id).await.map_err(|error| report!(errors::StorageError::from(error)))diff --git a/crates/router/src/db/merchant_account.rs b/crates/router/src/db/merchant_account.rsindex 1c104b2248..24cb4b42db 100644--- a/crates/router/src/db/merchant_account.rs+++ b/crates/router/src/db/merchant_account.rs@@ -112,7 +112,7 @@ impl MerchantAccountInterface for Store {merchant_account: domain::MerchantAccount,merchant_key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantAccount, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;merchant_account.construct_new().await@@ -137,7 +137,7 @@ impl MerchantAccountInterface for Store {merchant_key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantAccount, errors::StorageError> {let fetch_func = || async {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::MerchantAccount::find_by_merchant_id(&conn, merchant_id).await.map_err(|error| report!(errors::StorageError::from(error)))@@ -183,7 +183,7 @@ impl MerchantAccountInterface for Store {merchant_account: storage::MerchantAccountUpdate,merchant_key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantAccount, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;let updated_merchant_account = Conversion::convert(this).await@@ -214,7 +214,7 @@ impl MerchantAccountInterface for Store {merchant_account: storage::MerchantAccountUpdate,merchant_key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantAccount, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;let updated_merchant_account = storage::MerchantAccount::update_with_specific_fields(&conn,merchant_id,@@ -245,7 +245,7 @@ impl MerchantAccountInterface for Store {) -> CustomResult<(domain::MerchantAccount, domain::MerchantKeyStore), errors::StorageError>{let fetch_by_pub_key_func = || async {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::MerchantAccount::find_by_publishable_key(&conn, publishable_key).await@@ -294,7 +294,7 @@ impl MerchantAccountInterface for Store {organization_id: &common_utils::id_type::OrganizationId,) -> CustomResult<Vec<domain::MerchantAccount>, errors::StorageError> {use futures::future::try_join_all;- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;let encrypted_merchant_accounts =storage::MerchantAccount::list_by_organization_id(&conn, organization_id)@@ -338,7 +338,7 @@ impl MerchantAccountInterface for Store {&self,merchant_id: &common_utils::id_type::MerchantId,) -> CustomResult<bool, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;let is_deleted_func = || async {storage::MerchantAccount::delete_by_merchant_id(&conn, merchant_id)@@ -375,7 +375,7 @@ impl MerchantAccountInterface for Store {state: &KeyManagerState,merchant_ids: Vec<common_utils::id_type::MerchantId>,) -> CustomResult<Vec<domain::MerchantAccount>, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;let encrypted_merchant_accounts =storage::MerchantAccount::list_multiple_merchant_accounts(&conn, merchant_ids)@@ -439,7 +439,7 @@ impl MerchantAccountInterface for Store {)>,errors::StorageError,> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;let encrypted_merchant_accounts =storage::MerchantAccount::list_all_merchant_accounts(&conn, limit, offset).await@@ -460,7 +460,7 @@ impl MerchantAccountInterface for Store {&self,merchant_account: storage::MerchantAccountUpdate,) -> CustomResult<usize, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;let db_func = || async {storage::MerchantAccount::update_all_merchant_accounts(diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rsindex 213c2b19f6..a9c7d99e30 100644--- a/crates/router/src/db/merchant_connector_account.rs+++ b/crates/router/src/db/merchant_connector_account.rs@@ -240,7 +240,7 @@ impl MerchantConnectorAccountInterface for Store {key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {let find_call = || async {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::MerchantConnectorAccount::find_by_merchant_id_connector(&conn,merchant_id,@@ -291,7 +291,7 @@ impl MerchantConnectorAccountInterface for Store {key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {let find_call = || async {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::MerchantConnectorAccount::find_by_profile_id_connector_name(&conn,profile_id,@@ -345,7 +345,7 @@ impl MerchantConnectorAccountInterface for Store {connector_name: &str,key_store: &domain::MerchantKeyStore,) -> CustomResult<Vec<domain::MerchantConnectorAccount>, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::MerchantConnectorAccount::find_by_merchant_id_connector_name(&conn,merchant_id,@@ -381,7 +381,7 @@ impl MerchantConnectorAccountInterface for Store {key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {let find_call = || async {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::MerchantConnectorAccount::find_by_merchant_id_merchant_connector_id(&conn,merchant_id,@@ -436,7 +436,7 @@ impl MerchantConnectorAccountInterface for Store {key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {let find_call = || async {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::MerchantConnectorAccount::find_by_id(&conn, id).await.map_err(|error| report!(errors::StorageError::from(error)))@@ -483,7 +483,7 @@ impl MerchantConnectorAccountInterface for Store {t: domain::MerchantConnectorAccount,key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;t.construct_new().await.change_context(errors::StorageError::EncryptionError)?@@ -510,7 +510,7 @@ impl MerchantConnectorAccountInterface for Store {key_store: &domain::MerchantKeyStore,connector_type: common_enums::ConnectorType,) -> CustomResult<Vec<domain::MerchantConnectorAccount>, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::MerchantConnectorAccount::list_enabled_by_profile_id(&conn,@@ -545,7 +545,7 @@ impl MerchantConnectorAccountInterface for Store {get_disabled: bool,key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantConnectorAccounts, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;let merchant_connector_account_vec =storage::MerchantConnectorAccount::find_by_merchant_id(&conn,@@ -583,7 +583,7 @@ impl MerchantConnectorAccountInterface for Store {profile_id: &common_utils::id_type::ProfileId,key_store: &domain::MerchantKeyStore,) -> CustomResult<Vec<domain::MerchantConnectorAccount>, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;+ let conn = connection::pg_accounts_connection_read(self).await?;storage::MerchantConnectorAccount::list_by_profile_id(&conn, profile_id).await.map_err(|error| report!(errors::StorageError::from(error)))@@ -613,7 +613,7 @@ impl MerchantConnectorAccountInterface for Store {storage::MerchantConnectorAccountUpdateInternal,)>,) -> CustomResult<(), errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;async fn update_call(connection: &diesel_models::PgPooledConn,@@ -731,7 +731,7 @@ impl MerchantConnectorAccountInterface for Store {let _merchant_connector_id = this.merchant_connector_id.clone();let update_call = || async {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;Conversion::convert(this).await.change_context(errors::StorageError::EncryptionError)?@@ -811,7 +811,7 @@ impl MerchantConnectorAccountInterface for Store {let _merchant_connector_id = this.get_id().clone();let update_call = || async {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;Conversion::convert(this).await.change_context(errors::StorageError::EncryptionError)?@@ -879,7 +879,7 @@ impl MerchantConnectorAccountInterface for Store {merchant_id: &common_utils::id_type::MerchantId,merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId,) -> CustomResult<bool, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;let delete_call = || async {storage::MerchantConnectorAccount::delete_by_merchant_id_merchant_connector_id(&conn,@@ -954,7 +954,7 @@ impl MerchantConnectorAccountInterface for Store {&self,id: &common_utils::id_type::MerchantConnectorAccountId,) -> CustomResult<bool, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;+ let conn = connection::pg_accounts_connection_write(self).await?;let delete_call = || async {storage::MerchantConnectorAccount::delete_by_id(&conn, id).await@@ -1240,7 +1240,8 @@ impl MerchantConnectorAccountInterface for MockDb {connector_account_details: t.connector_account_details.into(),test_mode: t.test_mode,disabled: t.disabled,- merchant_connector_id: t.merchant_connector_id,+ merchant_connector_id: t.merchant_connector_id.clone(),+ id: Some(t.merchant_connector_id),payment_methods_enabled: t.payment_methods_enabled,metadata: t.metadata,frm_configs: None,diff --git a/v2_migrations/2025-01-13-081848_alter_column_types_for_v2/down.sql b/migrations/2025-03-25-090203_add_id_column_to_profile_mca/down.sqlsimilarity index 58%rename from v2_migrations/2025-01-13-081848_alter_column_types_for_v2/down.sqlrename to migrations/2025-03-25-090203_add_id_column_to_profile_mca/down.sqlindex 2899b740dd..ffdf6f3b90 100644--- a/v2_migrations/2025-01-13-081848_alter_column_types_for_v2/down.sql+++ b/migrations/2025-03-25-090203_add_id_column_to_profile_mca/down.sql@@ -1,3 +1,6 @@-- This file should undo anything in `up.sql`+ALTER TABLE business_profile+DROP COLUMN id;+ALTER TABLE merchant_connector_account- ALTER COLUMN payment_methods_enabled TYPE JSON [ ];\ No newline at end of file+DROP COLUMN id;\ No newline at end of filediff --git a/migrations/2025-03-25-090203_add_id_column_to_profile_mca/up.sql b/migrations/2025-03-25-090203_add_id_column_to_profile_mca/up.sqlnew file mode 100644index 0000000000..22ae6e81a2--- /dev/null+++ b/migrations/2025-03-25-090203_add_id_column_to_profile_mca/up.sql@@ -0,0 +1,6 @@+-- Your SQL goes here+ALTER TABLE business_profile+ADD COLUMN id VARCHAR(64);++ALTER TABLE merchant_connector_account+ADD COLUMN id VARCHAR(64);\ No newline at end of filediff --git a/v2_compatible_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sql b/v2_compatible_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sqlindex 93126bc847..87b61f80da 100644--- a/v2_compatible_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sql+++ b/v2_compatible_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sql@@ -1,9 +1,5 @@-- This file contains queries to create the `id` column as a `SERIAL` column instead of `VARCHAR` column for tables that already have it.-- This is to revert the `id` columns to the previous state.-ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS id;---ALTER TABLE business_profile DROP COLUMN IF EXISTS id;ALTER TABLE customers DROP COLUMN IF EXISTS id;diff --git a/v2_compatible_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sql b/v2_compatible_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sqlindex b831f900ee..9ac4410616 100644--- a/v2_compatible_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sql+++ b/v2_compatible_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sql@@ -2,17 +2,6 @@-- It must be ensured that the deployed version of the application does not include the `id` column in any of its queries.-- Drop the id column as this will be used later as the primary key with a different type------------------------- Merchant Connector Account -------------------------- This migration is to modify the id column in merchant_connector_account table to be a VARCHAR(64) and to set the id column as primary key--ALTER TABLE merchant_connector_account-ADD COLUMN IF NOT EXISTS id VARCHAR(64);-------------------------- Business Profile -------------------------- This migration is to modify the id column in business_profile table to be a VARCHAR(64) and to set the id column as primary key-ALTER TABLE business_profile-ADD COLUMN id VARCHAR(64);------------------------- Customers -----------------------diff --git a/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/down.sql b/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/down.sqlindex c0b0efbd38..819ba22b90 100644--- a/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/down.sql+++ b/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/down.sql@@ -1,10 +1,13 @@------------------------ Organization -----------------------+-- Drop index on org_id in organization table+DROP INDEX IF EXISTS idx_organization_org_id;-- Re-add primary key constraint on `organization`ALTER TABLE organizationADD CONSTRAINT organization_pkey PRIMARY KEY (org_id),ALTER COLUMN org_id SET NOT NULL;------------------------ Merchant Account -------------------+DROP INDEX IF EXISTS idx_merchant_account_merchant_id;ALTER TABLE merchant_accountADD PRIMARY KEY (merchant_id),ALTER COLUMN primary_business_details SET NOT NULL,@@ -12,32 +15,40 @@ ALTER TABLE merchant_accountALTER COLUMN is_recon_enabled SET DEFAULT FALSE;------------------------ Business Profile -------------------+DROP INDEX IF EXISTS idx_business_profile_profile_id;ALTER TABLE business_profileADD PRIMARY KEY (profile_id);+---------------- Merchant Connector Account -----------------+DROP INDEX IF EXISTS idx_merchant_connector_account_merchant_connector_id;ALTER TABLE merchant_connector_accountADD PRIMARY KEY (merchant_connector_id);------------------------ Customers --------------------------+DROP INDEX IF EXISTS idx_customers_merchant_id_customer_id;ALTER TABLE customersADD PRIMARY KEY (merchant_id, customer_id);---------------------- Payment Intent -----------------------+DROP INDEX IF EXISTS idx_payment_intent_payment_id_merchant_id;ALTER TABLE payment_intentADD PRIMARY KEY (payment_id, merchant_id),ALTER COLUMN active_attempt_id SET NOT NULL,ALTER COLUMN active_attempt_id SET DEFAULT 'xxx';---------------------- Payment Attempt ----------------------+DROP INDEX IF EXISTS idx_payment_attempt_attempt_id_merchant_id;ALTER TABLE payment_attemptADD PRIMARY KEY (attempt_id, merchant_id),ALTER COLUMN amount SET NOT NULL;---------------------- Payment Methods ----------------------+DROP INDEX IF EXISTS idx_payment_methods_payment_method_id;ALTER TABLE payment_methodsADD PRIMARY KEY (payment_method_id);---------------------- Refunds ----------------------+DROP INDEX IF EXISTS idx_refund_refund_id_merchant_id;ALTER TABLE refundADD PRIMARY KEY (refund_id,merchant_id);\ No newline at end of filediff --git a/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/up.sql b/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/up.sqlindex 731d488297..ea3b08be15 100644--- a/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/up.sql+++ b/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/up.sql@@ -1,9 +1,14 @@--- Drop not null constraint on org_id in organization table--- Drop not null constraint on org_id in organization table+-- Drop not null constraints on not null columns of v1 which are either dropped or made nullable in v2.+------------------------ Organization -----------------------ALTER TABLE organizationDROP CONSTRAINT organization_pkey,ALTER COLUMN org_id DROP NOT NULL;+-- Create index on org_id in organization table+-- This is done to mullify the effects of droping primary key for v1+CREATE INDEX idx_organization_org_id ON organization (org_id);++------------------------ Merchant Account --------------------- Drop not null in merchant_account table for v1 columns that are dropped in v2ALTER TABLE merchant_accountDROP CONSTRAINT merchant_account_pkey,@@ -11,33 +16,58 @@ ALTER TABLE merchant_accountALTER COLUMN primary_business_details DROP NOT NULL,ALTER COLUMN is_recon_enabled DROP NOT NULL;+-- This is done to mullify the effects of droping primary key for v1+CREATE INDEX idx_merchant_account_merchant_id ON merchant_account (merchant_id);++------------------------ Business Profile -------------------ALTER TABLE business_profileDROP CONSTRAINT business_profile_pkey,ALTER COLUMN profile_id DROP NOT NULL;+-- This is done to mullify the effects of droping primary key for v1+CREATE INDEX idx_business_profile_profile_id ON business_profile (profile_id);++---------------- Merchant Connector Account -----------------ALTER TABLE merchant_connector_accountDROP CONSTRAINT merchant_connector_account_pkey,ALTER COLUMN merchant_connector_id DROP NOT NULL;+-- This is done to mullify the effects of droping primary key for v1+CREATE INDEX idx_merchant_connector_account_merchant_connector_id ON merchant_connector_account (merchant_connector_id);+------------------------ Customers --------------------------ALTER TABLE customersDROP CONSTRAINT customers_pkey,ALTER COLUMN customer_id DROP NOT NULL;+-- This is done to mullify the effects of droping primary key for v1+CREATE INDEX idx_customers_merchant_id_customer_id ON customers (merchant_id, customer_id);+---------------------- Payment Intent -----------------------ALTER TABLE payment_intentDROP CONSTRAINT payment_intent_pkey,ALTER COLUMN payment_id DROP NOT NULL,ALTER COLUMN active_attempt_id DROP NOT NULL,ALTER COLUMN active_attempt_id DROP DEFAULT;+-- This is done to mullify the effects of droping primary key for v1+CREATE INDEX idx_payment_intent_payment_id_merchant_id ON payment_intent (payment_id, merchant_id);+---------------------- Payment Attempt ----------------------ALTER TABLE payment_attemptDROP CONSTRAINT payment_attempt_pkey,ALTER COLUMN attempt_id DROP NOT NULL,ALTER COLUMN amount DROP NOT NULL;+-- This is done to mullify the effects of droping primary key for v1+CREATE INDEX idx_payment_attempt_attempt_id_merchant_id ON payment_attempt (attempt_id, merchant_id);+---------------------- Payment Methods ----------------------ALTER TABLE payment_methodsDROP CONSTRAINT payment_methods_pkey,ALTER COLUMN payment_method_id DROP NOT NULL;+-- This is done to mullify the effects of droping primary key for v1+CREATE INDEX idx_payment_methods_payment_method_id ON payment_methods (payment_method_id);+---------------------- Refunds ----------------------ALTER TABLE refundDROP CONSTRAINT refund_pkey,- ALTER COLUMN refund_id DROP NOT NULL;\ No newline at end of file+ ALTER COLUMN refund_id DROP NOT NULL;+-- This is done to mullify the effects of droping primary key for v1+CREATE INDEX idx_refund_refund_id_merchant_id ON refund (refund_id, merchant_id);\ No newline at end of filediff --git a/v2_migrations/2025-01-13-081848_alter_column_types_for_v2/up.sql b/v2_migrations/2025-01-13-081848_alter_column_types_for_v2/up.sqldeleted file mode 100644index 11c9e9447e..0000000000--- a/v2_migrations/2025-01-13-081848_alter_column_types_for_v2/up.sql+++ /dev/null@@ -1,3 +0,0 @@--- Your SQL goes here-ALTER TABLE merchant_connector_account- ALTER COLUMN payment_methods_enabled TYPE JSONB [ ];\ No newline at end of file