diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 660474e91ee..754fd9bf31c 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1,14 +1,15 @@ +mod accounts; mod payments; mod ui; use std::num::{ParseFloatError, TryFromIntError}; +pub use accounts::MerchantProductType; pub use payments::ProductType; use serde::{Deserialize, Serialize}; pub use ui::*; use utoipa::ToSchema; pub use super::connector_enums::RoutableConnectors; - #[doc(hidden)] pub mod diesel_exports { pub use super::{ diff --git a/crates/common_enums/src/enums/accounts.rs b/crates/common_enums/src/enums/accounts.rs new file mode 100644 index 00000000000..9a5247512e4 --- /dev/null +++ b/crates/common_enums/src/enums/accounts.rs @@ -0,0 +1,28 @@ +use serde; +use utoipa::ToSchema; +#[derive( + Default, + Clone, + Debug, + Eq, + PartialEq, + serde::Deserialize, + serde::Serialize, + strum::Display, + strum::EnumString, + ToSchema, + Hash, +)] +#[router_derive::diesel_enum(storage_type = "text")] +#[serde(rename_all = "snake_case")] +#[strum(serialize_all = "snake_case")] +pub enum MerchantProductType { + Orchestration, + #[default] + Legacy, + Vault, + Recon, + Recovery, + CostObservability, + DynamicRouting, +} diff --git a/crates/diesel_models/drop_id.patch b/crates/diesel_models/drop_id.patch new file mode 100644 index 00000000000..657db97ae4f --- /dev/null +++ b/crates/diesel_models/drop_id.patch @@ -0,0 +1,66 @@ +diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs +index b35e809a0..749a5dd47 100644 +--- a/crates/diesel_models/src/schema.rs ++++ b/crates/diesel_models/src/schema.rs +@@ -142,14 +142,13 @@ diesel::table! { + } + + diesel::table! { + use diesel::sql_types::*; + use crate::enums::diesel_exports::*; + +- blocklist_fingerprint (id) { +- id -> Int4, ++ blocklist_fingerprint (merchant_id, fingerprint_id) { + #[max_length = 64] + merchant_id -> Varchar, + #[max_length = 64] + fingerprint_id -> Varchar, + data_kind -> BlocklistDataKind, + encrypted_fingerprint -> Text, +@@ -158,14 +157,13 @@ diesel::table! { + } + + diesel::table! { + use diesel::sql_types::*; + use crate::enums::diesel_exports::*; + +- blocklist_lookup (id) { +- id -> Int4, ++ blocklist_lookup (merchant_id, fingerprint) { + #[max_length = 64] + merchant_id -> Varchar, + fingerprint -> Text, + } + } + +@@ -300,13 +298,12 @@ diesel::table! { + + diesel::table! { + use diesel::sql_types::*; + use crate::enums::diesel_exports::*; + + configs (key) { +- id -> Int4, + #[max_length = 255] + key -> Varchar, + config -> Text, + } + } + +@@ -615,14 +612,13 @@ diesel::table! { + } + + diesel::table! { + use diesel::sql_types::*; + use crate::enums::diesel_exports::*; + +- locker_mock_up (id) { +- id -> Int4, ++ locker_mock_up (card_id) { + #[max_length = 255] + card_id -> Varchar, + #[max_length = 255] + external_id -> Varchar, + #[max_length = 255] + card_fingerprint -> Varchar, diff --git a/crates/diesel_models/remove_id.patch b/crates/diesel_models/remove_id.patch deleted file mode 100644 index 5b2e96ded3f..00000000000 --- a/crates/diesel_models/remove_id.patch +++ /dev/null @@ -1,108 +0,0 @@ -diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs -index 55f8e935b..469ad1d22 100644 ---- a/crates/diesel_models/src/schema.rs -+++ b/crates/diesel_models/src/schema.rs -@@ -5,7 +5,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - address (address_id) { -- id -> Nullable, - #[max_length = 64] - address_id -> Varchar, - #[max_length = 128] -@@ -129,7 +128,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - blocklist (merchant_id, fingerprint_id) { -- id -> Int4, - #[max_length = 64] - merchant_id -> Varchar, - #[max_length = 64] -@@ -284,7 +282,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - customers (customer_id, merchant_id) { -- id -> Int4, - #[max_length = 64] - customer_id -> Varchar, - #[max_length = 64] -@@ -337,7 +334,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - dispute (dispute_id) { -- id -> Int4, - #[max_length = 64] - dispute_id -> Varchar, - #[max_length = 255] -@@ -588,7 +584,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - mandate (mandate_id) { -- id -> Int4, - #[max_length = 64] - mandate_id -> Varchar, - #[max_length = 64] -@@ -634,7 +629,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - merchant_account (merchant_id) { -- id -> Int4, - #[max_length = 64] - merchant_id -> Varchar, - #[max_length = 255] -@@ -678,7 +672,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - merchant_connector_account (merchant_connector_id) { -- id -> Int4, - #[max_length = 64] - merchant_id -> Varchar, - #[max_length = 64] -@@ -741,7 +734,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - payment_attempt (attempt_id, merchant_id) { -- id -> Nullable, - #[max_length = 64] - payment_id -> Varchar, - #[max_length = 64] -@@ -832,7 +824,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - payment_intent (payment_id, merchant_id) { -- id -> Nullable, - #[max_length = 64] - payment_id -> Varchar, - #[max_length = 64] -@@ -935,7 +926,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - payment_methods (payment_method_id) { -- id -> Int4, - #[max_length = 64] - customer_id -> Varchar, - #[max_length = 64] -@@ -1100,7 +1090,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - refund (merchant_id, refund_id) { -- id -> Int4, - #[max_length = 64] - internal_reference_id -> Varchar, - #[max_length = 64] -@@ -1169,7 +1158,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - roles (role_id) { -- id -> Int4, - #[max_length = 64] - role_name -> Varchar, - #[max_length = 64] -@@ -1276,7 +1263,6 @@ diesel::table! { - use crate::enums::diesel_exports::*; - - users (user_id) { -- id -> Int4, - #[max_length = 64] - user_id -> Varchar, - #[max_length = 255] diff --git a/crates/diesel_models/src/blocklist_fingerprint.rs b/crates/diesel_models/src/blocklist_fingerprint.rs index 93b39e69a59..3cc7904d7e9 100644 --- a/crates/diesel_models/src/blocklist_fingerprint.rs +++ b/crates/diesel_models/src/blocklist_fingerprint.rs @@ -16,10 +16,8 @@ pub struct BlocklistFingerprintNew { #[derive( Clone, Debug, Eq, PartialEq, Queryable, Identifiable, Selectable, Deserialize, Serialize, )] -#[diesel(table_name = blocklist_fingerprint, check_for_backend(diesel::pg::Pg))] +#[diesel(table_name = blocklist_fingerprint, primary_key(merchant_id, fingerprint_id), check_for_backend(diesel::pg::Pg))] pub struct BlocklistFingerprint { - #[serde(skip_serializing)] - pub id: i32, pub merchant_id: common_utils::id_type::MerchantId, pub fingerprint_id: String, pub data_kind: common_enums::BlocklistDataKind, diff --git a/crates/diesel_models/src/blocklist_lookup.rs b/crates/diesel_models/src/blocklist_lookup.rs index dd7cd0252df..6edaff0de21 100644 --- a/crates/diesel_models/src/blocklist_lookup.rs +++ b/crates/diesel_models/src/blocklist_lookup.rs @@ -22,10 +22,8 @@ pub struct BlocklistLookupNew { Deserialize, Serialize, )] -#[diesel(table_name = blocklist_lookup, check_for_backend(diesel::pg::Pg))] +#[diesel(table_name = blocklist_lookup, primary_key(merchant_id, fingerprint), check_for_backend(diesel::pg::Pg))] pub struct BlocklistLookup { - #[serde(skip)] - pub id: i32, pub merchant_id: common_utils::id_type::MerchantId, pub fingerprint: String, } diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs index fdded6a3a34..d0ee9e8926f 100644 --- a/crates/diesel_models/src/business_profile.rs +++ b/crates/diesel_models/src/business_profile.rs @@ -310,14 +310,6 @@ pub struct Profile { pub always_collect_shipping_details_from_wallet_connector: Option, pub tax_connector_id: Option, pub is_tax_connector_enabled: Option, - pub routing_algorithm_id: Option, - pub order_fulfillment_time: Option, - pub order_fulfillment_time_origin: Option, - pub frm_routing_algorithm_id: Option, - pub payout_routing_algorithm_id: Option, - pub default_fallback_routing: Option, - pub should_collect_cvv_during_payment: bool, - pub id: common_utils::id_type::ProfileId, pub version: common_enums::ApiVersion, pub dynamic_routing_algorithm: Option, pub is_network_tokenization_enabled: bool, @@ -327,9 +319,17 @@ pub struct Profile { pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, - pub three_ds_decision_manager_config: Option, pub card_testing_guard_config: Option, pub card_testing_secret_key: Option, + pub routing_algorithm_id: Option, + pub order_fulfillment_time: Option, + pub order_fulfillment_time_origin: Option, + pub frm_routing_algorithm_id: Option, + pub payout_routing_algorithm_id: Option, + pub default_fallback_routing: Option, + pub three_ds_decision_manager_config: Option, + pub should_collect_cvv_during_payment: bool, + pub id: common_utils::id_type::ProfileId, } impl Profile { diff --git a/crates/diesel_models/src/configs.rs b/crates/diesel_models/src/configs.rs index 37381961d96..15eba159f78 100644 --- a/crates/diesel_models/src/configs.rs +++ b/crates/diesel_models/src/configs.rs @@ -13,10 +13,8 @@ pub struct ConfigNew { } #[derive(Default, Clone, Debug, Identifiable, Queryable, Selectable, Deserialize, Serialize)] -#[diesel(table_name = configs, check_for_backend(diesel::pg::Pg))] +#[diesel(table_name = configs, primary_key(key), check_for_backend(diesel::pg::Pg))] pub struct Config { - #[serde(skip)] - pub id: i32, pub key: String, pub config: String, } @@ -49,7 +47,6 @@ impl From for ConfigUpdateInternal { impl From for Config { fn from(config_new: ConfigNew) -> Self { Self { - id: 0i32, key: config_new.key, config: config_new.config, } diff --git a/crates/diesel_models/src/locker_mock_up.rs b/crates/diesel_models/src/locker_mock_up.rs index 04f3607a6ca..99e0b2d0987 100644 --- a/crates/diesel_models/src/locker_mock_up.rs +++ b/crates/diesel_models/src/locker_mock_up.rs @@ -3,9 +3,8 @@ use diesel::{Identifiable, Insertable, Queryable, Selectable}; use crate::schema::locker_mock_up; #[derive(Clone, Debug, Eq, Identifiable, Queryable, Selectable, PartialEq)] -#[diesel(table_name = locker_mock_up, check_for_backend(diesel::pg::Pg))] +#[diesel(table_name = locker_mock_up, primary_key(card_id), check_for_backend(diesel::pg::Pg))] pub struct LockerMockUp { - pub id: i32, pub card_id: String, pub external_id: String, pub card_fingerprint: String, diff --git a/crates/diesel_models/src/merchant_account.rs b/crates/diesel_models/src/merchant_account.rs index b5c2bc28572..40c6a1e4ff3 100644 --- a/crates/diesel_models/src/merchant_account.rs +++ b/crates/diesel_models/src/merchant_account.rs @@ -52,6 +52,8 @@ pub struct MerchantAccount { pub pm_collect_link_config: Option, pub version: common_enums::ApiVersion, pub is_platform_account: bool, + pub id: Option, + pub product_type: Option, } #[cfg(feature = "v1")] @@ -85,12 +87,14 @@ pub struct MerchantAccountSetter { pub pm_collect_link_config: Option, pub version: common_enums::ApiVersion, pub is_platform_account: bool, + pub product_type: Option, } #[cfg(feature = "v1")] impl From for MerchantAccount { fn from(item: MerchantAccountSetter) -> Self { Self { + id: Some(item.merchant_id.clone()), merchant_id: item.merchant_id, return_url: item.return_url, enable_payment_response_hash: item.enable_payment_response_hash, @@ -120,6 +124,7 @@ impl From for MerchantAccount { pm_collect_link_config: item.pm_collect_link_config, version: item.version, is_platform_account: item.is_platform_account, + product_type: item.product_type, } } } @@ -150,8 +155,9 @@ pub struct MerchantAccount { pub organization_id: common_utils::id_type::OrganizationId, pub recon_status: storage_enums::ReconStatus, pub version: common_enums::ApiVersion, - pub id: common_utils::id_type::MerchantId, pub is_platform_account: bool, + pub id: common_utils::id_type::MerchantId, + pub product_type: Option, } #[cfg(feature = "v2")] @@ -170,6 +176,7 @@ impl From for MerchantAccount { recon_status: item.recon_status, version: item.version, is_platform_account: item.is_platform_account, + product_type: item.product_type, } } } @@ -188,6 +195,7 @@ pub struct MerchantAccountSetter { pub recon_status: storage_enums::ReconStatus, pub version: common_enums::ApiVersion, pub is_platform_account: bool, + pub product_type: Option, } impl MerchantAccount { @@ -235,6 +243,8 @@ pub struct MerchantAccountNew { pub pm_collect_link_config: Option, pub version: common_enums::ApiVersion, pub is_platform_account: bool, + pub id: Option, + pub product_type: Option, } #[cfg(feature = "v2")] @@ -252,6 +262,7 @@ pub struct MerchantAccountNew { pub id: common_utils::id_type::MerchantId, pub version: common_enums::ApiVersion, pub is_platform_account: bool, + pub product_type: Option, } #[cfg(feature = "v2")] @@ -267,6 +278,7 @@ pub struct MerchantAccountUpdateInternal { pub organization_id: Option, pub recon_status: Option, pub is_platform_account: Option, + pub product_type: Option, } #[cfg(feature = "v2")] @@ -282,6 +294,7 @@ impl MerchantAccountUpdateInternal { organization_id, recon_status, is_platform_account, + product_type, } = self; MerchantAccount { @@ -297,6 +310,7 @@ impl MerchantAccountUpdateInternal { version: source.version, id: source.id, is_platform_account: is_platform_account.unwrap_or(source.is_platform_account), + product_type: product_type.or(source.product_type), } } } @@ -331,6 +345,7 @@ pub struct MerchantAccountUpdateInternal { pub payment_link_config: Option, pub pm_collect_link_config: Option, pub is_platform_account: Option, + pub product_type: Option, } #[cfg(feature = "v1")] @@ -363,6 +378,7 @@ impl MerchantAccountUpdateInternal { payment_link_config, pm_collect_link_config, is_platform_account, + product_type, } = self; MerchantAccount { @@ -399,6 +415,8 @@ impl MerchantAccountUpdateInternal { pm_collect_link_config: pm_collect_link_config.or(source.pm_collect_link_config), version: source.version, is_platform_account: is_platform_account.unwrap_or(source.is_platform_account), + id: source.id, + product_type: product_type.or(source.product_type), } } } diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rs index 01853cb7aa6..5ee54987cdb 100644 --- a/crates/diesel_models/src/merchant_connector_account.rs +++ b/crates/diesel_models/src/merchant_connector_account.rs @@ -98,8 +98,8 @@ pub struct MerchantConnectorAccount { pub additional_merchant_data: Option, pub connector_wallets_details: Option, pub version: common_enums::ApiVersion, - pub id: id_type::MerchantConnectorAccountId, pub feature_metadata: Option, + pub id: id_type::MerchantConnectorAccountId, } #[cfg(feature = "v2")] diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 9409be94163..3701f48c686 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -82,6 +82,13 @@ pub struct PaymentAttempt { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub card_network: Option, + pub shipping_cost: Option, + pub order_tax_amount: Option, + pub request_extended_authorization: Option, + pub extended_authorization_applied: Option, + pub capture_before: Option, + pub card_discovery: Option, + pub charges: Option, pub payment_method_type_v2: storage_enums::PaymentMethod, pub connector_payment_id: Option, pub payment_method_subtype: storage_enums::PaymentMethodType, @@ -94,13 +101,6 @@ pub struct PaymentAttempt { pub connector_payment_data: Option, pub connector_token_details: Option, pub id: id_type::GlobalAttemptId, - pub shipping_cost: Option, - pub order_tax_amount: Option, - pub request_extended_authorization: Option, - pub extended_authorization_applied: Option, - pub capture_before: Option, - pub card_discovery: Option, - pub charges: Option, pub feature_metadata: Option, } @@ -308,6 +308,8 @@ pub struct PaymentAttemptNew { pub card_network: Option, pub shipping_cost: Option, pub order_tax_amount: Option, + pub charges: Option, + pub feature_metadata: Option, pub payment_method_type_v2: storage_enums::PaymentMethod, pub payment_method_subtype: storage_enums::PaymentMethodType, pub id: id_type::GlobalAttemptId, @@ -316,8 +318,6 @@ pub struct PaymentAttemptNew { pub request_extended_authorization: Option, pub extended_authorization_applied: Option, pub capture_before: Option, - pub charges: Option, - pub feature_metadata: Option, } #[cfg(feature = "v1")] diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs index f10616ceb1b..77cd5db77ba 100644 --- a/crates/diesel_models/src/payment_intent.rs +++ b/crates/diesel_models/src/payment_intent.rs @@ -58,6 +58,10 @@ pub struct PaymentIntent { pub organization_id: common_utils::id_type::OrganizationId, pub tax_details: Option, pub skip_external_tax_calculation: Option, + pub request_extended_authorization: Option, + pub psd2_sca_exemption_type: Option, + pub split_payments: Option, + pub platform_merchant_id: Option, pub merchant_reference_id: Option, pub billing_address: Option, pub shipping_address: Option, @@ -76,10 +80,6 @@ pub struct PaymentIntent { pub routing_algorithm_id: Option, pub payment_link_config: Option, pub id: common_utils::id_type::GlobalPaymentId, - pub request_extended_authorization: Option, - pub psd2_sca_exemption_type: Option, - pub split_payments: Option, - pub platform_merchant_id: Option, } #[cfg(feature = "v1")] @@ -380,8 +380,8 @@ pub struct PaymentIntentNew { pub skip_external_tax_calculation: Option, pub request_extended_authorization: Option, pub psd2_sca_exemption_type: Option, - pub platform_merchant_id: Option, pub split_payments: Option, + pub platform_merchant_id: Option, } #[cfg(feature = "v2")] diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs index e8c6e1737b3..fc499904575 100644 --- a/crates/diesel_models/src/payment_method.rs +++ b/crates/diesel_models/src/payment_method.rs @@ -89,14 +89,14 @@ pub struct PaymentMethod { pub client_secret: Option, pub payment_method_billing_address: Option, pub updated_by: Option, - pub locker_fingerprint_id: Option, - pub payment_method_type_v2: Option, - pub payment_method_subtype: Option, - pub id: common_utils::id_type::GlobalPaymentMethodId, pub version: common_enums::ApiVersion, pub network_token_requestor_reference_id: Option, pub network_token_locker_id: Option, pub network_token_payment_method_data: Option, + pub locker_fingerprint_id: Option, + pub payment_method_type_v2: Option, + pub payment_method_subtype: Option, + pub id: common_utils::id_type::GlobalPaymentMethodId, } impl PaymentMethod { @@ -177,14 +177,14 @@ pub struct PaymentMethodNew { pub client_secret: Option, pub payment_method_billing_address: Option, pub updated_by: Option, - pub locker_fingerprint_id: Option, - pub payment_method_type_v2: Option, - pub payment_method_subtype: Option, - pub id: common_utils::id_type::GlobalPaymentMethodId, pub version: common_enums::ApiVersion, pub network_token_requestor_reference_id: Option, pub network_token_locker_id: Option, pub network_token_payment_method_data: Option, + pub locker_fingerprint_id: Option, + pub payment_method_type_v2: Option, + pub payment_method_subtype: Option, + pub id: common_utils::id_type::GlobalPaymentMethodId, } impl PaymentMethodNew { diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index 57c43a1955b..1de8483a3f3 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -145,8 +145,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - blocklist_fingerprint (id) { - id -> Int4, + blocklist_fingerprint (merchant_id, fingerprint_id) { #[max_length = 64] merchant_id -> Varchar, #[max_length = 64] @@ -161,8 +160,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - blocklist_lookup (id) { - id -> Int4, + blocklist_lookup (merchant_id, fingerprint) { #[max_length = 64] merchant_id -> Varchar, fingerprint -> Text, @@ -307,7 +305,6 @@ diesel::table! { use crate::enums::diesel_exports::*; configs (key) { - id -> Int4, #[max_length = 255] key -> Varchar, config -> Text, @@ -622,8 +619,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - locker_mock_up (id) { - id -> Int4, + locker_mock_up (card_id) { #[max_length = 255] card_id -> Varchar, #[max_length = 255] @@ -742,6 +738,10 @@ diesel::table! { pm_collect_link_config -> Nullable, version -> ApiVersion, is_platform_account -> Bool, + #[max_length = 64] + id -> Nullable, + #[max_length = 64] + product_type -> Nullable, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index 2351bdb83c9..6018d0a6999 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -5,7 +5,6 @@ diesel::table! { use crate::enums::diesel_exports::*; address (address_id) { - id -> Nullable, #[max_length = 64] address_id -> Varchar, #[max_length = 128] @@ -132,7 +131,6 @@ diesel::table! { use crate::enums::diesel_exports::*; blocklist (merchant_id, fingerprint_id) { - id -> Int4, #[max_length = 64] merchant_id -> Varchar, #[max_length = 64] @@ -207,6 +205,16 @@ diesel::table! { #[max_length = 64] tax_connector_id -> Nullable, is_tax_connector_enabled -> Nullable, + version -> ApiVersion, + dynamic_routing_algorithm -> Nullable, + is_network_tokenization_enabled -> Bool, + is_auto_retries_enabled -> Nullable, + max_auto_retries_enabled -> Nullable, + always_request_extended_authorization -> Nullable, + is_click_to_pay_enabled -> Bool, + authentication_product_ids -> Nullable, + card_testing_guard_config -> Nullable, + card_testing_secret_key -> Nullable, #[max_length = 64] routing_algorithm_id -> Nullable, order_fulfillment_time -> Nullable, @@ -216,20 +224,10 @@ diesel::table! { #[max_length = 64] payout_routing_algorithm_id -> Nullable, default_fallback_routing -> Nullable, + three_ds_decision_manager_config -> Nullable, should_collect_cvv_during_payment -> Bool, #[max_length = 64] id -> Varchar, - version -> ApiVersion, - dynamic_routing_algorithm -> Nullable, - is_network_tokenization_enabled -> Bool, - is_auto_retries_enabled -> Nullable, - max_auto_retries_enabled -> Nullable, - always_request_extended_authorization -> Nullable, - is_click_to_pay_enabled -> Bool, - authentication_product_ids -> Nullable, - three_ds_decision_manager_config -> Nullable, - card_testing_guard_config -> Nullable, - card_testing_secret_key -> Nullable, } } @@ -382,7 +380,6 @@ diesel::table! { use crate::enums::diesel_exports::*; dispute (dispute_id) { - id -> Int4, #[max_length = 64] dispute_id -> Varchar, #[max_length = 255] @@ -671,7 +668,6 @@ diesel::table! { use crate::enums::diesel_exports::*; mandate (mandate_id) { - id -> Int4, #[max_length = 64] mandate_id -> Varchar, #[max_length = 64] @@ -729,9 +725,11 @@ diesel::table! { organization_id -> Varchar, recon_status -> ReconStatus, version -> ApiVersion, + is_platform_account -> Bool, #[max_length = 64] id -> Varchar, - is_platform_account -> Bool, + #[max_length = 64] + product_type -> Nullable, } } @@ -763,9 +761,9 @@ diesel::table! { additional_merchant_data -> Nullable, connector_wallets_details -> Nullable, version -> ApiVersion, + feature_metadata -> Nullable, #[max_length = 64] id -> Varchar, - feature_metadata -> Nullable, } } @@ -862,6 +860,13 @@ diesel::table! { organization_id -> Varchar, #[max_length = 32] card_network -> Nullable, + shipping_cost -> Nullable, + order_tax_amount -> Nullable, + request_extended_authorization -> Nullable, + extended_authorization_applied -> Nullable, + capture_before -> Nullable, + card_discovery -> Nullable, + charges -> Nullable, payment_method_type_v2 -> Varchar, #[max_length = 128] connector_payment_id -> Nullable, @@ -878,13 +883,6 @@ diesel::table! { connector_token_details -> Nullable, #[max_length = 64] id -> Varchar, - shipping_cost -> Nullable, - order_tax_amount -> Nullable, - request_extended_authorization -> Nullable, - extended_authorization_applied -> Nullable, - capture_before -> Nullable, - card_discovery -> Nullable, - charges -> Nullable, feature_metadata -> Nullable, } } @@ -938,6 +936,11 @@ diesel::table! { organization_id -> Varchar, tax_details -> Nullable, skip_external_tax_calculation -> Nullable, + request_extended_authorization -> Nullable, + psd2_sca_exemption_type -> Nullable, + split_payments -> Nullable, + #[max_length = 64] + platform_merchant_id -> Nullable, #[max_length = 64] merchant_reference_id -> Nullable, billing_address -> Nullable, @@ -959,11 +962,6 @@ diesel::table! { payment_link_config -> Nullable, #[max_length = 64] id -> Varchar, - request_extended_authorization -> Nullable, - psd2_sca_exemption_type -> Nullable, - split_payments -> Nullable, - #[max_length = 64] - platform_merchant_id -> Nullable, } } @@ -1023,6 +1021,12 @@ diesel::table! { payment_method_billing_address -> Nullable, #[max_length = 64] updated_by -> Nullable, + version -> ApiVersion, + #[max_length = 128] + network_token_requestor_reference_id -> Nullable, + #[max_length = 64] + network_token_locker_id -> Nullable, + network_token_payment_method_data -> Nullable, #[max_length = 64] locker_fingerprint_id -> Nullable, #[max_length = 64] @@ -1031,12 +1035,6 @@ diesel::table! { payment_method_subtype -> Nullable, #[max_length = 64] id -> Varchar, - version -> ApiVersion, - #[max_length = 128] - network_token_requestor_reference_id -> Nullable, - #[max_length = 64] - network_token_locker_id -> Nullable, - network_token_payment_method_data -> Nullable, } } @@ -1159,7 +1157,6 @@ diesel::table! { use crate::enums::diesel_exports::*; refund (merchant_id, refund_id) { - id -> Int4, #[max_length = 64] internal_reference_id -> Varchar, #[max_length = 64] @@ -1266,7 +1263,6 @@ diesel::table! { use crate::enums::diesel_exports::*; roles (role_id) { - id -> Int4, #[max_length = 64] role_name -> Varchar, #[max_length = 64] @@ -1441,7 +1437,6 @@ diesel::table! { use crate::enums::diesel_exports::*; users (user_id) { - id -> Int4, #[max_length = 64] user_id -> Varchar, #[max_length = 255] diff --git a/crates/hyperswitch_domain_models/src/merchant_account.rs b/crates/hyperswitch_domain_models/src/merchant_account.rs index c42b0005513..8aeb72a5886 100644 --- a/crates/hyperswitch_domain_models/src/merchant_account.rs +++ b/crates/hyperswitch_domain_models/src/merchant_account.rs @@ -48,6 +48,7 @@ pub struct MerchantAccount { pub pm_collect_link_config: Option, pub version: common_enums::ApiVersion, pub is_platform_account: bool, + pub product_type: Option, } #[cfg(feature = "v1")] @@ -83,6 +84,7 @@ pub struct MerchantAccountSetter { pub pm_collect_link_config: Option, pub version: common_enums::ApiVersion, pub is_platform_account: bool, + pub product_type: Option, } #[cfg(feature = "v1")] @@ -118,6 +120,7 @@ impl From for MerchantAccount { pm_collect_link_config: item.pm_collect_link_config, version: item.version, is_platform_account: item.is_platform_account, + product_type: item.product_type, } } } @@ -137,6 +140,7 @@ pub struct MerchantAccountSetter { pub organization_id: common_utils::id_type::OrganizationId, pub recon_status: diesel_models::enums::ReconStatus, pub is_platform_account: bool, + pub product_type: Option, } #[cfg(feature = "v2")] @@ -154,6 +158,7 @@ impl From for MerchantAccount { organization_id, recon_status, is_platform_account, + product_type, } = item; Self { id, @@ -167,6 +172,7 @@ impl From for MerchantAccount { organization_id, recon_status, is_platform_account, + product_type, } } } @@ -185,6 +191,7 @@ pub struct MerchantAccount { pub organization_id: common_utils::id_type::OrganizationId, pub recon_status: diesel_models::enums::ReconStatus, pub is_platform_account: bool, + pub product_type: Option, } impl MerchantAccount { @@ -317,6 +324,7 @@ impl From for MerchantAccountUpdateInternal { is_recon_enabled: None, recon_status: None, is_platform_account: None, + product_type: None, }, MerchantAccountUpdate::StorageSchemeUpdate { storage_scheme } => Self { storage_scheme: Some(storage_scheme), @@ -345,6 +353,7 @@ impl From for MerchantAccountUpdateInternal { payment_link_config: None, pm_collect_link_config: None, is_platform_account: None, + product_type: None, }, MerchantAccountUpdate::ReconUpdate { recon_status } => Self { recon_status: Some(recon_status), @@ -373,6 +382,7 @@ impl From for MerchantAccountUpdateInternal { payment_link_config: None, pm_collect_link_config: None, is_platform_account: None, + product_type: None, }, MerchantAccountUpdate::UnsetDefaultProfile => Self { default_profile: Some(None), @@ -401,6 +411,7 @@ impl From for MerchantAccountUpdateInternal { payment_link_config: None, pm_collect_link_config: None, is_platform_account: None, + product_type: None, }, MerchantAccountUpdate::ModifiedAtUpdate => Self { modified_at: now, @@ -429,6 +440,7 @@ impl From for MerchantAccountUpdateInternal { payment_link_config: None, pm_collect_link_config: None, is_platform_account: None, + product_type: None, }, MerchantAccountUpdate::ToPlatformAccount => Self { modified_at: now, @@ -457,6 +469,7 @@ impl From for MerchantAccountUpdateInternal { payment_link_config: None, pm_collect_link_config: None, is_platform_account: Some(true), + product_type: None, }, } } @@ -483,6 +496,7 @@ impl From for MerchantAccountUpdateInternal { organization_id: None, recon_status: None, is_platform_account: None, + product_type: None, }, MerchantAccountUpdate::StorageSchemeUpdate { storage_scheme } => Self { storage_scheme: Some(storage_scheme), @@ -494,6 +508,7 @@ impl From for MerchantAccountUpdateInternal { organization_id: None, recon_status: None, is_platform_account: None, + product_type: None, }, MerchantAccountUpdate::ReconUpdate { recon_status } => Self { recon_status: Some(recon_status), @@ -505,6 +520,7 @@ impl From for MerchantAccountUpdateInternal { metadata: None, organization_id: None, is_platform_account: None, + product_type: None, }, MerchantAccountUpdate::ModifiedAtUpdate => Self { modified_at: now, @@ -516,6 +532,7 @@ impl From for MerchantAccountUpdateInternal { organization_id: None, recon_status: None, is_platform_account: None, + product_type: None, }, MerchantAccountUpdate::ToPlatformAccount => Self { modified_at: now, @@ -527,6 +544,7 @@ impl From for MerchantAccountUpdateInternal { organization_id: None, recon_status: None, is_platform_account: Some(true), + product_type: None, }, } } @@ -553,6 +571,7 @@ impl super::behaviour::Conversion for MerchantAccount { recon_status: self.recon_status, version: crate::consts::API_VERSION, is_platform_account: self.is_platform_account, + product_type: self.product_type, }; Ok(diesel_models::MerchantAccount::from(setter)) @@ -613,6 +632,7 @@ impl super::behaviour::Conversion for MerchantAccount { organization_id: item.organization_id, recon_status: item.recon_status, is_platform_account: item.is_platform_account, + product_type: item.product_type, }) } .await @@ -635,6 +655,7 @@ impl super::behaviour::Conversion for MerchantAccount { recon_status: self.recon_status, version: crate::consts::API_VERSION, is_platform_account: self.is_platform_account, + product_type: self.product_type, }) } } @@ -675,6 +696,7 @@ impl super::behaviour::Conversion for MerchantAccount { pm_collect_link_config: self.pm_collect_link_config, version: self.version, is_platform_account: self.is_platform_account, + product_type: self.product_type, }; Ok(diesel_models::MerchantAccount::from(setter)) @@ -753,6 +775,7 @@ impl super::behaviour::Conversion for MerchantAccount { pm_collect_link_config: item.pm_collect_link_config, version: item.version, is_platform_account: item.is_platform_account, + product_type: item.product_type, }) } .await @@ -764,6 +787,7 @@ impl super::behaviour::Conversion for MerchantAccount { async fn construct_new(self) -> CustomResult { let now = date_time::now(); Ok(diesel_models::merchant_account::MerchantAccountNew { + id: None, merchant_id: self.merchant_id, merchant_name: self.merchant_name.map(Encryption::from), merchant_details: self.merchant_details.map(Encryption::from), @@ -792,6 +816,7 @@ impl super::behaviour::Conversion for MerchantAccount { pm_collect_link_config: self.pm_collect_link_config, version: crate::consts::API_VERSION, is_platform_account: self.is_platform_account, + product_type: self.product_type, }) } } diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index bc93b9c53eb..201b2a815cb 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -403,6 +403,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate { pm_collect_link_config, version: hyperswitch_domain_models::consts::API_VERSION, is_platform_account: false, + product_type: None, }, ) } @@ -671,6 +672,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate { organization_id: organization.get_organization_id(), recon_status: diesel_models::enums::ReconStatus::NotRequested, is_platform_account: false, + product_type: None, }), ) } diff --git a/crates/router/src/db/configs.rs b/crates/router/src/db/configs.rs index 9b8ab5231b6..2ffea09939c 100644 --- a/crates/router/src/db/configs.rs +++ b/crates/router/src/db/configs.rs @@ -1,5 +1,5 @@ use diesel_models::configs::ConfigUpdateInternal; -use error_stack::{report, ResultExt}; +use error_stack::report; use router_env::{instrument, tracing}; use storage_impl::redis::cache::{self, CacheKind, CONFIG_CACHE}; @@ -191,7 +191,6 @@ impl ConfigInterface for MockDb { let mut configs = self.configs.lock().await; let config_new = storage::Config { - id: i32::try_from(configs.len()).change_context(errors::StorageError::MockDbError)?, key: config.key, config: config.config, }; diff --git a/crates/router/src/db/locker_mock_up.rs b/crates/router/src/db/locker_mock_up.rs index abae3fe2468..9c756355afd 100644 --- a/crates/router/src/db/locker_mock_up.rs +++ b/crates/router/src/db/locker_mock_up.rs @@ -1,4 +1,4 @@ -use error_stack::{report, ResultExt}; +use error_stack::report; use router_env::{instrument, tracing}; use super::{MockDb, Store}; @@ -88,8 +88,6 @@ impl LockerMockUpInterface for MockDb { } let created_locker = storage::LockerMockUp { - id: i32::try_from(locked_lockers.len()) - .change_context(errors::StorageError::MockDbError)?, card_id: new.card_id, external_id: new.external_id, card_fingerprint: new.card_fingerprint, diff --git a/diesel.toml b/diesel.toml index 9079080b31f..e4dd50432dc 100644 --- a/diesel.toml +++ b/diesel.toml @@ -5,4 +5,4 @@ file = "crates/diesel_models/src/schema.rs" import_types = ["diesel::sql_types::*", "crate::enums::diesel_exports::*"] generate_missing_sql_type_definitions = false -patch_file="crates/diesel_models/remove_id.patch" +patch_file="crates/diesel_models/drop_id.patch" diff --git a/justfile b/justfile index 5a0d13396ba..f98da88e40d 100644 --- a/justfile +++ b/justfile @@ -168,8 +168,20 @@ resultant_dir := source_directory() / 'final-migrations' # Copy v1 and v2 migrations to a single directory [private] copy_migrations: - @mkdir -p {{ resultant_dir }} - @cp -r {{ v1_migration_dir }}/. {{ v2_migration_dir }}/. {{ resultant_dir }}/ + #! /usr/bin/env bash + mkdir -p {{resultant_dir}} + cp -r {{v1_migration_dir}}/* {{resultant_dir}}/ + + # Prefix v2 migrations with 9 + sh -c ' + for dir in "{{v2_migration_dir}}"/*; do + if [ -d "$dir" ]; then + base_name=$(basename "$dir") + new_name="9$base_name" + cp -r "$dir" "{{resultant_dir}}/$new_name" + fi + done + ' echo "Created {{ resultant_dir }}" # Delete the newly created directory diff --git a/migrations/2025-02-06-111828_drop_int_id_column_accross_database/down.sql b/migrations/2025-02-06-111828_drop_int_id_column_accross_database/down.sql new file mode 100644 index 00000000000..6f8033dc4cb --- /dev/null +++ b/migrations/2025-02-06-111828_drop_int_id_column_accross_database/down.sql @@ -0,0 +1,41 @@ +-- This file contains queries to re-create the `id` column as a `VARCHAR(64)` column for tables that had it removed. +-- It must be ensured that the deployed version of the application includes the `id` column in any of its queries. +-- Re-create the id column as this was used as the primary key with a different type +------------------------ Merchant Account ----------------------- +ALTER TABLE merchant_account ADD COLUMN id VARCHAR(64); + +------------------------ Merchant Connector Account ----------------------- +ALTER TABLE merchant_connector_account ADD COLUMN id VARCHAR(64); + +------------------------ Customers ----------------------- +ALTER TABLE customers ADD COLUMN id VARCHAR(64); + +------------------------ Payment Intent ----------------------- +ALTER TABLE payment_intent ADD COLUMN id VARCHAR(64); + +------------------------ Payment Attempt ----------------------- +ALTER TABLE payment_attempt ADD COLUMN id VARCHAR(64); + +------------------------ Payment Methods ----------------------- +ALTER TABLE payment_methods ADD COLUMN id VARCHAR(64); + +------------------------ Address ----------------------- +ALTER TABLE address ADD COLUMN id VARCHAR(64); + +------------------------ Dispute ----------------------- +ALTER TABLE dispute ADD COLUMN id VARCHAR(64); + +------------------------ Mandate ----------------------- +ALTER TABLE mandate ADD COLUMN id VARCHAR(64); + +------------------------ Refund ----------------------- +ALTER TABLE refund ADD COLUMN id VARCHAR(64); + +------------------------ BlockList ----------------------- +ALTER TABLE blocklist ADD COLUMN id VARCHAR(64); + +------------------------ Roles ----------------------- +ALTER TABLE roles ADD COLUMN id VARCHAR(64); + +------------------------ Users ----------------------- +ALTER TABLE users ADD COLUMN id VARCHAR(64); diff --git a/migrations/2025-02-06-111828_drop_int_id_column_accross_database/up.sql b/migrations/2025-02-06-111828_drop_int_id_column_accross_database/up.sql new file mode 100644 index 00000000000..21b594faf78 --- /dev/null +++ b/migrations/2025-02-06-111828_drop_int_id_column_accross_database/up.sql @@ -0,0 +1,47 @@ +-- This file contains queries to re-create the `id` column as a `VARCHAR` column instead of `SERIAL` column for tables that already have it. +-- 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 Account ----------------------- +ALTER TABLE merchant_account DROP COLUMN IF EXISTS id; + +------------------------ Merchant Connector Account ----------------------- +ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS id; + + +------------------------ Customers ----------------------- +ALTER TABLE customers DROP COLUMN IF EXISTS id; + + + +------------------------ Payment Intent ----------------------- +ALTER TABLE payment_intent DROP COLUMN id; + + +------------------------ Payment Attempt ----------------------- +ALTER TABLE payment_attempt DROP COLUMN id; + + +------------------------ Payment Methods ----------------------- +ALTER TABLE payment_methods DROP COLUMN IF EXISTS id; + +------------------------ Address ----------------------- +ALTER TABLE address DROP COLUMN IF EXISTS id; + +------------------------ Dispute ----------------------- +ALTER TABLE dispute DROP COLUMN IF EXISTS id; + +------------------------ Mandate ----------------------- +ALTER TABLE mandate DROP COLUMN IF EXISTS id; + +------------------------ Refund ----------------------- +ALTER TABLE refund DROP COLUMN IF EXISTS id; + +------------------------ BlockList ----------------------- +ALTER TABLE blocklist DROP COLUMN IF EXISTS id; + +------------------------ Roles ----------------------- +ALTER TABLE roles DROP COLUMN IF EXISTS id; + +------------------------ Users ----------------------- +ALTER TABLE users DROP COLUMN IF EXISTS id; + diff --git a/migrations/2025-02-10-101701_recreate_varchar_id_column_for_merchant_account/down.sql b/migrations/2025-02-10-101701_recreate_varchar_id_column_for_merchant_account/down.sql new file mode 100644 index 00000000000..a144b645412 --- /dev/null +++ b/migrations/2025-02-10-101701_recreate_varchar_id_column_for_merchant_account/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE merchant_account DROP id; \ No newline at end of file diff --git a/migrations/2025-02-10-101701_recreate_varchar_id_column_for_merchant_account/up.sql b/migrations/2025-02-10-101701_recreate_varchar_id_column_for_merchant_account/up.sql new file mode 100644 index 00000000000..73f911583b8 --- /dev/null +++ b/migrations/2025-02-10-101701_recreate_varchar_id_column_for_merchant_account/up.sql @@ -0,0 +1,3 @@ +-- Your SQL goes here +ALTER TABLE merchant_account +ADD COLUMN IF NOT EXISTS id VARCHAR(64); \ No newline at end of file diff --git a/migrations/2025-02-11-062329_add-product-type-column-merchant-account/down.sql b/migrations/2025-02-11-062329_add-product-type-column-merchant-account/down.sql new file mode 100644 index 00000000000..90f2bc21a0b --- /dev/null +++ b/migrations/2025-02-11-062329_add-product-type-column-merchant-account/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE merchant_account DROP product_type; \ No newline at end of file diff --git a/migrations/2025-02-11-062329_add-product-type-column-merchant-account/up.sql b/migrations/2025-02-11-062329_add-product-type-column-merchant-account/up.sql new file mode 100644 index 00000000000..8567c86278b --- /dev/null +++ b/migrations/2025-02-11-062329_add-product-type-column-merchant-account/up.sql @@ -0,0 +1,3 @@ +-- Your SQL goes here +ALTER TABLE merchant_account +ADD COLUMN IF NOT EXISTS product_type VARCHAR(64); \ No newline at end of file diff --git a/v2_migrations/2024-08-23-112510_payment_methods_v2_db_changes/down.sql b/v2_migrations/2024-08-23-112510_payment_methods_v2_db_changes/down.sql deleted file mode 100644 index 30c499e6c42..00000000000 --- a/v2_migrations/2024-08-23-112510_payment_methods_v2_db_changes/down.sql +++ /dev/null @@ -1,42 +0,0 @@ --- This file should undo anything in `up.sql` -ALTER TABLE payment_methods - ADD COLUMN IF NOT EXISTS accepted_currency "Currency" [ ], - ADD COLUMN IF NOT EXISTS scheme VARCHAR(32), - ADD COLUMN IF NOT EXISTS token VARCHAR(128), - ADD COLUMN IF NOT EXISTS cardholder_name VARCHAR(255), - ADD COLUMN IF NOT EXISTS issuer_name VARCHAR(64), - ADD COLUMN IF NOT EXISTS issuer_country VARCHAR(64), - ADD COLUMN IF NOT EXISTS is_stored BOOLEAN, - ADD COLUMN IF NOT EXISTS direct_debit_token VARCHAR(128), - ADD COLUMN IF NOT EXISTS swift_code VARCHAR(32), - ADD COLUMN IF NOT EXISTS payment_method_issuer VARCHAR(128), - ADD COLUMN IF NOT EXISTS metadata JSON, - ADD COLUMN IF NOT EXISTS payment_method VARCHAR, - ADD COLUMN IF NOT EXISTS payment_method_type VARCHAR(64); - -CREATE TYPE "PaymentMethodIssuerCode" AS ENUM ( - 'jp_hdfc', - 'jp_icici', - 'jp_googlepay', - 'jp_applepay', - 'jp_phonepe', - 'jp_wechat', - 'jp_sofort', - 'jp_giropay', - 'jp_sepa', - 'jp_bacs' -); - -ALTER TABLE payment_methods ADD COLUMN IF NOT EXISTS payment_method_issuer_code "PaymentMethodIssuerCode"; - -ALTER TABLE payment_methods - DROP COLUMN IF EXISTS locker_fingerprint_id, - DROP COLUMN IF EXISTS payment_method_type_v2, - DROP COLUMN IF EXISTS payment_method_subtype; - -ALTER TABLE payment_methods ADD COLUMN IF NOT EXISTS payment_method_id VARCHAR(64); -UPDATE payment_methods SET payment_method_id = id; -ALTER TABLE payment_methods DROP CONSTRAINT IF EXISTS payment_methods_pkey; -ALTER TABLE payment_methods ADD CONSTRAINT payment_methods_pkey PRIMARY KEY (payment_method_id); -ALTER TABLE payment_methods DROP COLUMN IF EXISTS id; -ALTER TABLE payment_methods ADD COLUMN IF NOT EXISTS id SERIAL; diff --git a/v2_migrations/2024-08-23-112510_payment_methods_v2_db_changes/up.sql b/v2_migrations/2024-08-23-112510_payment_methods_v2_db_changes/up.sql deleted file mode 100644 index fb319d9f05d..00000000000 --- a/v2_migrations/2024-08-23-112510_payment_methods_v2_db_changes/up.sql +++ /dev/null @@ -1,31 +0,0 @@ --- Your SQL goes here -ALTER TABLE payment_methods - DROP COLUMN IF EXISTS accepted_currency, - DROP COLUMN IF EXISTS scheme, - DROP COLUMN IF EXISTS token, - DROP COLUMN IF EXISTS cardholder_name, - DROP COLUMN IF EXISTS issuer_name, - DROP COLUMN IF EXISTS issuer_country, - DROP COLUMN IF EXISTS payer_country, - DROP COLUMN IF EXISTS is_stored, - DROP COLUMN IF EXISTS direct_debit_token, - DROP COLUMN IF EXISTS swift_code, - DROP COLUMN IF EXISTS payment_method_issuer, - DROP COLUMN IF EXISTS payment_method_issuer_code, - DROP COLUMN IF EXISTS metadata, - DROP COLUMN IF EXISTS payment_method, - DROP COLUMN IF EXISTS payment_method_type; - -DROP TYPE IF EXISTS "PaymentMethodIssuerCode"; - -ALTER TABLE payment_methods - ADD COLUMN IF NOT EXISTS locker_fingerprint_id VARCHAR(64), - ADD COLUMN IF NOT EXISTS payment_method_type_v2 VARCHAR(64), - ADD COLUMN IF NOT EXISTS payment_method_subtype VARCHAR(64); - -ALTER TABLE payment_methods DROP COLUMN IF EXISTS id; -ALTER TABLE payment_methods ADD COLUMN IF NOT EXISTS id VARCHAR(64); -UPDATE payment_methods SET id = payment_method_id; -ALTER TABLE payment_methods DROP CONSTRAINT IF EXISTS payment_methods_pkey; -ALTER TABLE payment_methods ADD CONSTRAINT payment_methods_pkey PRIMARY KEY (id); -ALTER TABLE payment_methods DROP COLUMN IF EXISTS payment_method_id; diff --git a/v2_migrations/2024-08-28-081721_add_v2_columns/down.sql b/v2_migrations/2024-08-28-081721_add_v2_columns/down.sql index 08e4b0a3568..92f74b1d9ac 100644 --- a/v2_migrations/2024-08-28-081721_add_v2_columns/down.sql +++ b/v2_migrations/2024-08-28-081721_add_v2_columns/down.sql @@ -11,7 +11,8 @@ ALTER TABLE business_profile DROP COLUMN routing_algorithm_id, DROP COLUMN frm_routing_algorithm_id, DROP COLUMN payout_routing_algorithm_id, DROP COLUMN default_fallback_routing, - DROP COLUMN should_collect_cvv_during_payment; + DROP COLUMN should_collect_cvv_during_payment, + DROP COLUMN three_ds_decision_manager_config; DROP TYPE "OrderFulfillmentTimeOrigin"; @@ -46,4 +47,9 @@ ALTER TABLE payment_attempt DROP COLUMN payment_method_type_v2, DROP COLUMN connector_token_details; ALTER TABLE merchant_connector_account -ALTER COLUMN payment_methods_enabled TYPE JSON [ ]; + DROP COLUMN IF EXISTS feature_metadata; + +ALTER TABLE payment_methods + DROP COLUMN IF EXISTS locker_fingerprint_id, + DROP COLUMN IF EXISTS payment_method_type_v2, + DROP COLUMN IF EXISTS payment_method_subtype; \ No newline at end of file diff --git a/v2_migrations/2024-08-28-081721_add_v2_columns/up.sql b/v2_migrations/2024-08-28-081721_add_v2_columns/up.sql index 03059985875..3094cdb3320 100644 --- a/v2_migrations/2024-08-28-081721_add_v2_columns/up.sql +++ b/v2_migrations/2024-08-28-081721_add_v2_columns/up.sql @@ -4,7 +4,7 @@ ALTER TABLE customers ADD COLUMN IF NOT EXISTS merchant_reference_id VARCHAR(64), ADD COLUMN IF NOT EXISTS default_billing_address BYTEA DEFAULT NULL, ADD COLUMN IF NOT EXISTS default_shipping_address BYTEA DEFAULT NULL, - ADD COLUMN IF NOT EXISTS status "DeleteStatus" NOT NULL DEFAULT 'active'; + ADD COLUMN IF NOT EXISTS status "DeleteStatus"; CREATE TYPE "OrderFulfillmentTimeOrigin" AS ENUM ('create', 'confirm'); @@ -15,13 +15,14 @@ ADD COLUMN routing_algorithm_id VARCHAR(64) DEFAULT NULL, ADD COLUMN frm_routing_algorithm_id VARCHAR(64) DEFAULT NULL, ADD COLUMN payout_routing_algorithm_id VARCHAR(64) DEFAULT NULL, ADD COLUMN default_fallback_routing JSONB DEFAULT NULL, + ADD COLUMN three_ds_decision_manager_config jsonb, -- Intentionally not adding a default value here since we would have to -- check if any merchants have enabled this from configs table, -- before filling data for this column. -- If no merchants have enabled this, then we can use `false` as the default value -- when adding the column, later we can drop the default added for the column -- so that we ensure new records inserted always have a value for the column. -ADD COLUMN should_collect_cvv_during_payment BOOLEAN NOT NULL; + ADD COLUMN should_collect_cvv_during_payment BOOLEAN; ALTER TABLE payment_intent ADD COLUMN merchant_reference_id VARCHAR(64), @@ -56,4 +57,9 @@ ADD COLUMN payment_method_type_v2 VARCHAR, -- Change the type of the column from JSON to JSONB ALTER TABLE merchant_connector_account -ALTER COLUMN payment_methods_enabled TYPE JSONB [ ]; + ADD COLUMN IF NOT EXISTS feature_metadata JSONB; + +ALTER TABLE payment_methods + ADD COLUMN IF NOT EXISTS locker_fingerprint_id VARCHAR(64), + ADD COLUMN IF NOT EXISTS payment_method_type_v2 VARCHAR(64), + ADD COLUMN IF NOT EXISTS payment_method_subtype VARCHAR(64); \ No newline at end of file diff --git a/v2_migrations/2024-08-28-081722_drop_not_null_constraints_on_v1_columns/down.sql b/v2_migrations/2024-08-28-081722_drop_not_null_constraints_on_v1_columns/down.sql index 46c0d151e19..10fd9adfa55 100644 --- a/v2_migrations/2024-08-28-081722_drop_not_null_constraints_on_v1_columns/down.sql +++ b/v2_migrations/2024-08-28-081722_drop_not_null_constraints_on_v1_columns/down.sql @@ -1,3 +1,39 @@ --- This file should undo anything in `up.sql` -ALTER TABLE organization ALTER COLUMN org_id SET NOT NULL; -ALTER TABLE organization ADD PRIMARY KEY (org_id); \ No newline at end of file +------------------------ Organization ----------------------- +-- Re-add primary key constraint on `organization` +ALTER TABLE organization + ADD CONSTRAINT organization_pkey PRIMARY KEY (org_id), + ALTER COLUMN org_id SET NOT NULL; + +------------------------ Merchant Account ------------------- +ALTER TABLE merchant_account + ADD PRIMARY KEY (merchant_id), + ALTER COLUMN primary_business_details SET NOT NULL, + ALTER COLUMN is_recon_enabled SET NOT NULL, + ALTER COLUMN is_recon_enabled SET DEFAULT FALSE; + +------------------------ Business Profile ------------------- +ALTER TABLE business_profile + ADD PRIMARY KEY (profile_id); + +---------------- Merchant Connector Account ----------------- +ALTER TABLE merchant_connector_account + ADD PRIMARY KEY (merchant_connector_id); + +------------------------ Customers -------------------------- +ALTER TABLE customers + ADD PRIMARY KEY (merchant_id, customer_id); + +---------------------- Payment Intent ----------------------- +ALTER TABLE payment_intent + ADD PRIMARY KEY (payment_id, merchant_id), + ALTER COLUMN active_attempt_id SET NOT NULL, + ALTER COLUMN active_attempt_id SET DEFAULT 'xxx'; + +---------------------- Payment Attempt ---------------------- +ALTER TABLE payment_attempt + ADD PRIMARY KEY (attempt_id, merchant_id), + ALTER COLUMN amount SET NOT NULL; + +---------------------- Payment Methods ---------------------- +ALTER TABLE payment_methods + ADD PRIMARY KEY (payment_method_id); diff --git a/v2_migrations/2024-08-28-081722_drop_not_null_constraints_on_v1_columns/up.sql b/v2_migrations/2024-08-28-081722_drop_not_null_constraints_on_v1_columns/up.sql index 886cb0bf583..e348f2e1cbb 100644 --- a/v2_migrations/2024-08-28-081722_drop_not_null_constraints_on_v1_columns/up.sql +++ b/v2_migrations/2024-08-28-081722_drop_not_null_constraints_on_v1_columns/up.sql @@ -1,3 +1,39 @@ --- Drop not null constraint on org_id in orgnaization table -ALTER TABLE organization DROP CONSTRAINT organization_pkey; -ALTER TABLE organization ALTER COLUMN org_id DROP NOT NULL; \ No newline at end of file +-- Drop not null constraint on org_id in organization table +-- Drop not null constraint on org_id in organization table +ALTER TABLE organization + DROP CONSTRAINT organization_pkey, + ALTER COLUMN org_id DROP NOT NULL; + +-- Drop not null in merchant_account table for v1 columns that are dropped in v2 +ALTER TABLE merchant_account + DROP CONSTRAINT merchant_account_pkey, + ALTER COLUMN merchant_id DROP NOT NULL, + ALTER COLUMN primary_business_details DROP NOT NULL, + ALTER COLUMN is_recon_enabled DROP NOT NULL; + +ALTER TABLE business_profile + DROP CONSTRAINT business_profile_pkey, + ALTER COLUMN profile_id DROP NOT NULL; + +ALTER TABLE merchant_connector_account + DROP CONSTRAINT merchant_connector_account_pkey, + ALTER COLUMN merchant_connector_id DROP NOT NULL; + +ALTER TABLE customers + DROP CONSTRAINT customers_pkey, + ALTER COLUMN customer_id DROP NOT NULL; + +ALTER TABLE payment_intent + DROP 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; + +ALTER TABLE payment_attempt + DROP CONSTRAINT payment_attempt_pkey, + ALTER COLUMN attempt_id DROP NOT NULL, + ALTER COLUMN amount DROP NOT NULL; + +ALTER TABLE payment_methods + DROP CONSTRAINT payment_methods_pkey, + ALTER COLUMN payment_method_id DROP NOT NULL; diff --git a/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sql b/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sql index 6315fe7f799..93126bc847f 100644 --- a/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sql +++ b/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sql @@ -1,26 +1,21 @@ -- 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_account DROP id; - -ALTER TABLE merchant_account -ADD COLUMN IF NOT EXISTS id SERIAL; - ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS id; -ALTER TABLE merchant_connector_account -ADD COLUMN IF NOT EXISTS id SERIAL; + +ALTER TABLE business_profile DROP COLUMN IF EXISTS id; ALTER TABLE customers DROP COLUMN IF EXISTS id; -ALTER TABLE customers -ADD COLUMN IF NOT EXISTS id SERIAL; + ALTER TABLE payment_intent DROP COLUMN IF EXISTS id; -ALTER TABLE payment_intent -ADD id SERIAL; + ALTER TABLE payment_attempt DROP COLUMN IF EXISTS id; -ALTER TABLE payment_attempt -ADD id SERIAL; + +------------------------ Payment Methods ----------------------- +ALTER TABLE payment_methods DROP COLUMN IF EXISTS id; + diff --git a/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sql b/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sql index daaf5976618..b831f900eeb 100644 --- a/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sql +++ b/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sql @@ -1,35 +1,39 @@ -- This file contains queries to re-create the `id` column as a `VARCHAR` column instead of `SERIAL` column for tables that already have it. -- 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 Account ----------------------- -ALTER TABLE merchant_account DROP COLUMN IF EXISTS id; - --- Adding a new column called `id` which will be the new primary key for v2 --- Note that even though this will be the new primary key, the v1 application would still fill in null values -ALTER TABLE merchant_account -ADD COLUMN id VARCHAR(64); ------------------------ 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 DROP COLUMN IF EXISTS id; 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 ----------------------- -ALTER TABLE customers DROP COLUMN IF EXISTS id; + ALTER TABLE customers ADD COLUMN IF NOT EXISTS id VARCHAR(64); ------------------------ Payment Intent ----------------------- -ALTER TABLE payment_intent DROP COLUMN id; + ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS id VARCHAR(64); ------------------------ Payment Attempt ----------------------- -ALTER TABLE payment_attempt DROP COLUMN id; + ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS id VARCHAR(64); + +------------------------ Payment Methods ----------------------- + + +ALTER TABLE payment_methods +ADD COLUMN IF NOT EXISTS id VARCHAR(64); + diff --git a/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/down.sql b/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/down.sql index 5903aea89ff..9b04dd6d3f5 100644 --- a/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/down.sql +++ b/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/down.sql @@ -5,105 +5,63 @@ SET org_id = id WHERE org_id IS NULL; ALTER TABLE ORGANIZATION DROP CONSTRAINT organization_pkey_id; - ALTER TABLE ORGANIZATION DROP CONSTRAINT organization_organization_name_key; --- back fill +-- Backfill UPDATE ORGANIZATION SET org_name = organization_name -WHERE org_name IS NULL - AND organization_name IS NOT NULL; +WHERE org_name IS NULL AND organization_name IS NOT NULL; ------------------------ Merchant Account ----------------------- -- The new primary key for v2 merchant account will be `id` ALTER TABLE merchant_account DROP CONSTRAINT merchant_account_pkey; +ALTER TABLE merchant_account ALTER COLUMN id DROP NOT NULL; --- In order to run this query, the merchant_id column should be unique and not null --- We need to backfill the id, a simple strategy will be to copy the values of id to merchant_id --- Query to update the merchant_id column with values of id +-- Backfill the id, a simple strategy will be to copy the values of id to merchant_id UPDATE merchant_account SET merchant_id = id WHERE merchant_id IS NULL; --- Note: This command might not run successfully for the existing table --- This is because there will be some rows ( which are created via v2 application ) which will have id as empty --- A backfill might be required to run this query --- However if this is being run on a fresh database, this should succeed -ALTER TABLE merchant_account -ADD PRIMARY KEY (merchant_id); - ------------------------ Business Profile ----------------------- +ALTER TABLE business_profile DROP CONSTRAINT business_profile_pkey; +ALTER TABLE business_profile ALTER COLUMN id DROP NOT NULL; + UPDATE business_profile SET profile_id = id WHERE profile_id IS NULL; -ALTER TABLE business_profile DROP COLUMN id; - -ALTER TABLE business_profile -ADD PRIMARY KEY (profile_id); - ------------------------ Merchant Connector Account ----------------------- ALTER TABLE merchant_connector_account DROP CONSTRAINT merchant_connector_account_pkey; +ALTER TABLE merchant_connector_account ALTER COLUMN id DROP NOT NULL; UPDATE merchant_connector_account SET merchant_connector_id = id WHERE merchant_connector_id IS NULL; -ALTER TABLE merchant_connector_account -ADD PRIMARY KEY (merchant_connector_id); - -ALTER TABLE merchant_connector_account -ALTER COLUMN profile_id DROP NOT NULL; - DROP INDEX IF EXISTS merchant_connector_account_profile_id_index; ------------------------ Customers ----------------------- -- Run this query only when V1 is deprecated ALTER TABLE customers DROP CONSTRAINT customers_pkey; +ALTER TABLE customers ALTER COLUMN id DROP NOT NULL; --- Back filling before making it primary key +-- Backfill before making it primary key UPDATE customers SET customer_id = id WHERE customer_id IS NULL; -ALTER TABLE customers -ADD PRIMARY KEY (merchant_id, customer_id); - ------------------------ Payment Intent ----------------------- ALTER TABLE payment_intent DROP CONSTRAINT payment_intent_pkey; +ALTER TABLE payment_intent ALTER COLUMN id DROP NOT NULL; UPDATE payment_intent SET payment_id = id WHERE payment_id IS NULL; -ALTER TABLE payment_intent -ADD PRIMARY KEY (payment_id, merchant_id); - -ALTER TABLE payment_intent -ALTER COLUMN currency DROP NOT NULL, - ALTER COLUMN client_secret DROP NOT NULL, - ALTER COLUMN profile_id DROP NOT NULL; - -ALTER TABLE payment_intent -ALTER COLUMN active_attempt_id -SET NOT NULL; - -ALTER TABLE payment_intent -ALTER COLUMN session_expiry DROP NOT NULL; - -ALTER TABLE payment_intent -ALTER COLUMN active_attempt_id -SET DEFAULT 'xxx'; - ------------------------ Payment Attempt ----------------------- ALTER TABLE payment_attempt DROP CONSTRAINT payment_attempt_pkey; +ALTER TABLE payment_attempt ALTER COLUMN id DROP NOT NULL; -UPDATE payment_attempt -SET attempt_id = id -WHERE attempt_id IS NULL; - -ALTER TABLE payment_attempt -ALTER COLUMN net_amount DROP NOT NULL; - -ALTER TABLE payment_attempt -ADD PRIMARY KEY (attempt_id, merchant_id); +------------------------ Payment Methods ----------------------- +ALTER TABLE payment_methods DROP CONSTRAINT payment_methods_pkey; +ALTER TABLE payment_methods ALTER COLUMN id DROP NOT NULL; diff --git a/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/up.sql b/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/up.sql index 0f5bd32e102..3b155115119 100644 --- a/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/up.sql +++ b/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/up.sql @@ -1,14 +1,15 @@ -- This file contains queries to update the primary key constraints suitable to the v2 application. -- This also has queries to update other constraints and indexes on tables where applicable. + ------------------------ Organization ----------------------- +-- Update null id and organization_name fields UPDATE ORGANIZATION SET id = org_id WHERE id IS NULL; UPDATE ORGANIZATION SET organization_name = org_name -WHERE organization_name IS NULL - AND org_name IS NOT NULL; +WHERE organization_name IS NULL AND org_name IS NOT NULL; -- Alter queries for organization table ALTER TABLE ORGANIZATION @@ -18,119 +19,60 @@ ALTER TABLE ORGANIZATION ADD CONSTRAINT organization_organization_name_key UNIQUE (organization_name); ------------------------ Merchant Account ----------------------- --- The new primary key for v2 merchant account will be `id` -ALTER TABLE merchant_account DROP CONSTRAINT merchant_account_pkey; - --- In order to make id as primary key, it should be unique and not null --- We need to backfill the id, a simple strategy will be to copy the values of merchant_id to id --- Query to update the id column with values of merchant_id --- Note: This query will lock the table, so it should be run when there is no traffic +-- Backfill id column with merchant_id values UPDATE merchant_account SET id = merchant_id WHERE id IS NULL; --- Note: This command might not run successfully for the existing table --- This is because there will be some rows ( which are created via v1 application ) which will have id as empty --- A backfill might be required to run this query --- However if this is being run on a fresh database, this should succeed +-- Add primary key constraint ALTER TABLE merchant_account ADD PRIMARY KEY (id); ------------------------ 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); - --- Backfill the id column with the profile_id to prevent null values +-- Backfill id column with profile_id values UPDATE business_profile SET id = profile_id WHERE id IS NULL; -ALTER TABLE business_profile DROP CONSTRAINT business_profile_pkey; - +-- Add primary key constraint ALTER TABLE business_profile ADD PRIMARY KEY (id); ------------------------ Merchant Connector Account ----------------------- --- Backfill the id column with the merchant_connector_id to prevent null values +-- Backfill id column with merchant_connector_id values UPDATE merchant_connector_account SET id = merchant_connector_id WHERE id IS NULL; -ALTER TABLE merchant_connector_account DROP CONSTRAINT merchant_connector_account_pkey; - +-- Add primary key constraint ALTER TABLE merchant_connector_account ADD PRIMARY KEY (id); --- This migration is to make profile_id mandatory in mca table -ALTER TABLE merchant_connector_account -ALTER COLUMN profile_id -SET NOT NULL; - -CREATE INDEX IF NOT EXISTS merchant_connector_account_profile_id_index ON merchant_connector_account (profile_id); +-- Create index on profile_id +CREATE INDEX IF NOT EXISTS merchant_connector_account_profile_id_index +ON merchant_connector_account (profile_id); ------------------------ Customers ----------------------- --- Run this query only when V1 is deprecated -ALTER TABLE customers DROP CONSTRAINT IF EXISTS customers_pkey; - --- Back filling before making it primary key --- This will fail when making `id` as primary key, if the `customer_id` column has duplicate values. --- Another option is to use a randomly generated ID instead. +-- Backfill id column with customer_id values UPDATE customers SET id = customer_id WHERE id IS NULL; +-- Add primary key constraint ALTER TABLE customers ADD PRIMARY KEY (id); ------------------------ Payment Intent ----------------------- -ALTER TABLE payment_intent DROP CONSTRAINT payment_intent_pkey; - +-- Add primary key constraint ALTER TABLE payment_intent ADD PRIMARY KEY (id); ------------------------ Payment Attempt ----------------------- -ALTER TABLE payment_attempt DROP CONSTRAINT payment_attempt_pkey; - +-- Add primary key constraint ALTER TABLE payment_attempt ADD PRIMARY KEY (id); --- This migration is to make fields mandatory in payment_intent table -ALTER TABLE payment_intent -ALTER COLUMN profile_id -SET NOT NULL, - ALTER COLUMN currency -SET NOT NULL, - ALTER COLUMN client_secret -SET NOT NULL, - ALTER COLUMN session_expiry -SET NOT NULL, - ALTER COLUMN active_attempt_id DROP NOT NULL; - ------------------------- Payment Attempt ----------------------- -ALTER TABLE payment_attempt DROP CONSTRAINT payment_attempt_pkey; - -ALTER TABLE payment_attempt +------------------------ Payment Methods ----------------------- +-- Add primary key constraint +ALTER TABLE payment_methods ADD PRIMARY KEY (id); - --- This migration is to make fields mandatory in payment_attempt table -ALTER TABLE payment_attempt -ALTER COLUMN net_amount -SET NOT NULL, - ALTER COLUMN authentication_type -SET NOT NULL, - ALTER COLUMN payment_method_type_v2 -SET NOT NULL, - ALTER COLUMN payment_method_subtype -SET NOT NULL; - -ALTER TABLE payment_intent -ALTER COLUMN session_expiry -SET NOT NULL; - --- This migration is to make fields optional in payment_intent table -ALTER TABLE payment_intent -ALTER COLUMN active_attempt_id DROP NOT NULL; - -ALTER TABLE payment_intent -ALTER COLUMN active_attempt_id DROP DEFAULT; diff --git a/v2_migrations/2024-08-28-081839_add_not_null_constraints_to_v2_columns/down.sql b/v2_migrations/2024-08-28-081839_add_not_null_constraints_to_v2_columns/down.sql new file mode 100644 index 00000000000..1941d9c1b8e --- /dev/null +++ b/v2_migrations/2024-08-28-081839_add_not_null_constraints_to_v2_columns/down.sql @@ -0,0 +1,27 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE customers + ALTER COLUMN status DROP NOT NULL, + ALTER COLUMN status DROP DEFAULT; + +---------------------business_profile--------------------- +ALTER TABLE business_profile ALTER COLUMN should_collect_cvv_during_payment DROP NOT NULL; + + +ALTER TABLE merchant_connector_account + ALTER COLUMN profile_id DROP NOT NULL; + +ALTER TABLE payment_intent + ALTER COLUMN profile_id DROP NOT NULL, + ALTER COLUMN currency DROP NOT NULL, + ALTER COLUMN client_secret DROP NOT NULL, + ALTER COLUMN session_expiry DROP NOT NULL; + +ALTER TABLE payment_attempt + ALTER COLUMN net_amount DROP NOT NULL; + +-- This migration is to make fields mandatory in payment_attempt table +ALTER TABLE payment_attempt + ALTER COLUMN net_amount DROP NOT NULL, + ALTER COLUMN authentication_type DROP NOT NULL, + ALTER COLUMN payment_method_type_v2 DROP NOT NULL, + ALTER COLUMN payment_method_subtype DROP NOT NULL; \ No newline at end of file diff --git a/v2_migrations/2024-08-28-081839_add_not_null_constraints_to_v2_columns/up.sql b/v2_migrations/2024-08-28-081839_add_not_null_constraints_to_v2_columns/up.sql new file mode 100644 index 00000000000..36fc7d2893d --- /dev/null +++ b/v2_migrations/2024-08-28-081839_add_not_null_constraints_to_v2_columns/up.sql @@ -0,0 +1,26 @@ +-- Your SQL goes here + +ALTER TABLE customers + ALTER COLUMN status SET NOT NULL, + ALTER COLUMN status SET DEFAULT 'active'; + +---------------------business_profile--------------------- +ALTER TABLE business_profile ALTER COLUMN should_collect_cvv_during_payment SET NOT NULL; + +-- This migration is to make profile_id mandatory in mca table +ALTER TABLE merchant_connector_account + ALTER COLUMN profile_id SET NOT NULL; + +-- This migration is to make fields mandatory in payment_intent table +ALTER TABLE payment_intent + ALTER COLUMN profile_id SET NOT NULL, + ALTER COLUMN currency SET NOT NULL, + ALTER COLUMN client_secret SET NOT NULL, + ALTER COLUMN session_expiry SET NOT NULL; + +-- This migration is to make fields mandatory in payment_attempt table +ALTER TABLE payment_attempt + ALTER COLUMN net_amount SET NOT NULL, + ALTER COLUMN authentication_type SET NOT NULL, + ALTER COLUMN payment_method_type_v2 SET NOT NULL, + ALTER COLUMN payment_method_subtype SET NOT NULL; \ No newline at end of file diff --git a/v2_migrations/2025-01-13-081847_drop_v1_columns/down.sql b/v2_migrations/2025-01-13-081847_drop_v1_columns/down.sql index 8d0fedce089..efcb56101f9 100644 --- a/v2_migrations/2025-01-13-081847_drop_v1_columns/down.sql +++ b/v2_migrations/2025-01-13-081847_drop_v1_columns/down.sql @@ -1,9 +1,9 @@ ALTER TABLE ORGANIZATION -ADD COLUMN org_id VARCHAR(32), + ADD COLUMN org_id VARCHAR(32), ADD COLUMN org_name TEXT; ALTER TABLE merchant_account -ADD COLUMN merchant_id VARCHAR(64), + ADD COLUMN merchant_id VARCHAR(64), ADD COLUMN return_url VARCHAR(255), ADD COLUMN enable_payment_response_hash BOOLEAN DEFAULT FALSE, ADD COLUMN payment_response_hash_key VARCHAR(255), @@ -15,45 +15,42 @@ ADD COLUMN merchant_id VARCHAR(64), ADD COLUMN default_profile VARCHAR(64), ADD COLUMN payment_link_config JSONB NULL, ADD COLUMN pm_collect_link_config JSONB NULL, - ADD COLUMN is_recon_enabled BOOLEAN NOT NULL DEFAULT FALSE, - ADD COLUMN webhook_details JSONB NULL, + ADD COLUMN is_recon_enabled BOOLEAN, + ADD COLUMN webhook_details JSON NULL, ADD COLUMN routing_algorithm JSON, ADD COLUMN frm_routing_algorithm JSONB, ADD COLUMN payout_routing_algorithm JSONB; -- The default value is for temporary purpose only ALTER TABLE merchant_account -ADD COLUMN primary_business_details JSON NOT NULL DEFAULT '[{"country": "US", "business": "default"}]'; - -ALTER TABLE merchant_account -ALTER COLUMN primary_business_details DROP DEFAULT; + ADD COLUMN primary_business_details JSON; ALTER TABLE business_profile -ADD COLUMN profile_id VARCHAR(64), + ADD COLUMN profile_id VARCHAR(64), ADD COLUMN routing_algorithm JSON DEFAULT NULL, ADD COLUMN intent_fulfillment_time BIGINT DEFAULT NULL, ADD COLUMN frm_routing_algorithm JSONB DEFAULT NULL, ADD COLUMN payout_routing_algorithm JSONB DEFAULT NULL; ALTER TABLE merchant_connector_account -ADD COLUMN IF NOT EXISTS business_country "CountryAlpha2", + ADD COLUMN IF NOT EXISTS business_country "CountryAlpha2", ADD COLUMN IF NOT EXISTS business_label VARCHAR(255), ADD COLUMN IF NOT EXISTS business_sub_label VARCHAR(64), ADD COLUMN IF NOT EXISTS test_mode BOOLEAN, ADD COLUMN IF NOT EXISTS frm_configs jsonb, - ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(32); + ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(128); ALTER TABLE customers -ADD COLUMN customer_id VARCHAR(64), + ADD COLUMN customer_id VARCHAR(64), ADD COLUMN address_id VARCHAR(64); ALTER TABLE payment_intent -ADD COLUMN IF NOT EXISTS payment_id VARCHAR(64) NOT NULL, + ADD COLUMN IF NOT EXISTS payment_id VARCHAR(64), ADD COLUMN connector_id VARCHAR(64), ADD COLUMN shipping_address_id VARCHAR(64), ADD COLUMN billing_address_id VARCHAR(64), - ADD COLUMN shipping_details VARCHAR(64), - ADD COLUMN billing_details VARCHAR(64), + ADD COLUMN shipping_details BYTEA, + ADD COLUMN billing_details BYTEA, ADD COLUMN statement_descriptor_suffix VARCHAR(255), ADD COLUMN business_country "CountryAlpha2", ADD COLUMN business_label VARCHAR(64), @@ -69,14 +66,15 @@ ADD COLUMN IF NOT EXISTS payment_id VARCHAR(64) NOT NULL, ADD COLUMN charges jsonb; ALTER TABLE payment_attempt -ADD COLUMN IF NOT EXISTS attempt_id VARCHAR(64) NOT NULL, - ADD COLUMN amount bigint NOT NULL, + ADD COLUMN IF NOT EXISTS attempt_id VARCHAR(64), + ADD COLUMN amount bigint, ADD COLUMN currency "Currency", ADD COLUMN save_to_locker BOOLEAN, ADD COLUMN offer_amount bigint, ADD COLUMN payment_method VARCHAR, - ADD COLUMN connector_transaction_id VARCHAR(64), - ADD COLUMN connector_transaction_data TEXT, + ADD COLUMN connector_transaction_id VARCHAR(128), + ADD COLUMN connector_transaction_data VARCHAR(512), + ADD COLUMN processor_transaction_data text, ADD COLUMN capture_method "CaptureMethod", ADD COLUMN capture_on TIMESTAMP, ADD COLUMN mandate_id VARCHAR(64), @@ -87,7 +85,7 @@ ADD COLUMN IF NOT EXISTS attempt_id VARCHAR(64) NOT NULL, ADD COLUMN tax_amount bigint, ADD COLUMN straight_through_algorithm JSONB, ADD COLUMN confirm BOOLEAN, - ADD COLUMN authentication_data JSONB, + ADD COLUMN authentication_data JSON, ADD COLUMN payment_method_billing_address_id VARCHAR(64), ADD COLUMN connector_mandate_detail JSONB, ADD COLUMN charge_id VARCHAR(64); @@ -96,3 +94,40 @@ ADD COLUMN IF NOT EXISTS attempt_id VARCHAR(64) NOT NULL, CREATE INDEX payment_attempt_connector_transaction_id_merchant_id_index ON payment_attempt (connector_transaction_id, merchant_id); CREATE UNIQUE INDEX payment_attempt_payment_id_merchant_id_attempt_id_index ON payment_attempt (payment_id, merchant_id, attempt_id); + +-- Payment Methods +CREATE TYPE "PaymentMethodIssuerCode" AS ENUM ( + 'jp_hdfc', + 'jp_icici', + 'jp_googlepay', + 'jp_applepay', + 'jp_phonepe', + 'jp_wechat', + 'jp_sofort', + 'jp_giropay', + 'jp_sepa', + 'jp_bacs' +); + +ALTER TABLE payment_methods + ADD COLUMN IF NOT EXISTS payment_method_id VARCHAR(64), + ADD COLUMN IF NOT EXISTS accepted_currency "Currency" [ ], + ADD COLUMN IF NOT EXISTS scheme VARCHAR(32), + ADD COLUMN IF NOT EXISTS token VARCHAR(128), + ADD COLUMN IF NOT EXISTS cardholder_name VARCHAR(255), + ADD COLUMN IF NOT EXISTS issuer_name VARCHAR(64), + ADD COLUMN IF NOT EXISTS issuer_country VARCHAR(64), + ADD COLUMN IF NOT EXISTS payer_country TEXT [ ], + ADD COLUMN IF NOT EXISTS is_stored BOOLEAN, + ADD COLUMN IF NOT EXISTS direct_debit_token VARCHAR(128), + ADD COLUMN IF NOT EXISTS swift_code VARCHAR(32), + ADD COLUMN IF NOT EXISTS payment_method_issuer VARCHAR(128), + ADD COLUMN IF NOT EXISTS metadata JSON, + ADD COLUMN IF NOT EXISTS payment_method VARCHAR, + ADD COLUMN IF NOT EXISTS payment_method_type VARCHAR(64), + ADD COLUMN IF NOT EXISTS payment_method_issuer_code "PaymentMethodIssuerCode"; + +ALTER TABLE refund ADD COLUMN connector_refund_data VARCHAR(512), + ADD COLUMN connector_transaction_data VARCHAR(512); + +ALTER TABLE captures ADD COLUMN connector_capture_data VARCHAR(512); \ No newline at end of file diff --git a/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql b/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql index caac00abd0f..b0a3f007eee 100644 --- a/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql +++ b/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql @@ -91,6 +91,26 @@ ALTER TABLE payment_attempt DROP COLUMN attempt_id, DROP COLUMN connector_mandate_detail, DROP COLUMN charge_id; + +ALTER TABLE payment_methods + DROP COLUMN IF EXISTS payment_method_id, + DROP COLUMN IF EXISTS accepted_currency, + DROP COLUMN IF EXISTS scheme, + DROP COLUMN IF EXISTS token, + DROP COLUMN IF EXISTS cardholder_name, + DROP COLUMN IF EXISTS issuer_name, + DROP COLUMN IF EXISTS issuer_country, + DROP COLUMN IF EXISTS payer_country, + DROP COLUMN IF EXISTS is_stored, + DROP COLUMN IF EXISTS direct_debit_token, + DROP COLUMN IF EXISTS swift_code, + DROP COLUMN IF EXISTS payment_method_issuer, + DROP COLUMN IF EXISTS payment_method_issuer_code, + DROP COLUMN IF EXISTS metadata, + DROP COLUMN IF EXISTS payment_method, + DROP COLUMN IF EXISTS payment_method_type; +DROP TYPE IF EXISTS "PaymentMethodIssuerCode"; + -- Run below queries only when V1 is deprecated ALTER TABLE refund DROP COLUMN connector_refund_data, DROP COLUMN connector_transaction_data; diff --git a/v2_migrations/2025-01-13-081848_alter_column_types_for_v2/down.sql b/v2_migrations/2025-01-13-081848_alter_column_types_for_v2/down.sql new file mode 100644 index 00000000000..2899b740ddc --- /dev/null +++ b/v2_migrations/2025-01-13-081848_alter_column_types_for_v2/down.sql @@ -0,0 +1,3 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE merchant_connector_account + ALTER COLUMN payment_methods_enabled TYPE JSON [ ]; \ No newline at end of file diff --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.sql new file mode 100644 index 00000000000..11c9e9447ea --- /dev/null +++ b/v2_migrations/2025-01-13-081848_alter_column_types_for_v2/up.sql @@ -0,0 +1,3 @@ +-- Your SQL goes here +ALTER TABLE merchant_connector_account + ALTER COLUMN payment_methods_enabled TYPE JSONB [ ]; \ No newline at end of file diff --git a/v2_migrations/2025-01-13-181842_add_three_ds_decision_manager_config_in_profile/down.sql b/v2_migrations/2025-01-13-181842_add_three_ds_decision_manager_config_in_profile/down.sql deleted file mode 100644 index a5295472f12..00000000000 --- a/v2_migrations/2025-01-13-181842_add_three_ds_decision_manager_config_in_profile/down.sql +++ /dev/null @@ -1,3 +0,0 @@ --- This file should undo anything in `up.sql` -ALTER TABLE business_profile -DROP COLUMN IF EXISTS three_ds_decision_manager_config; \ No newline at end of file diff --git a/v2_migrations/2025-01-13-181842_add_three_ds_decision_manager_config_in_profile/up.sql b/v2_migrations/2025-01-13-181842_add_three_ds_decision_manager_config_in_profile/up.sql deleted file mode 100644 index e329a39f1a9..00000000000 --- a/v2_migrations/2025-01-13-181842_add_three_ds_decision_manager_config_in_profile/up.sql +++ /dev/null @@ -1,3 +0,0 @@ --- Your SQL goes here -ALTER TABLE business_profile -ADD COLUMN IF NOT EXISTS three_ds_decision_manager_config jsonb; \ No newline at end of file diff --git a/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/down.sql b/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/down.sql deleted file mode 100644 index 2e343c15ada..00000000000 --- a/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE merchant_connector_account -DROP COLUMN IF EXISTS feature_metadata; \ No newline at end of file diff --git a/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/up.sql b/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/up.sql deleted file mode 100644 index 24ceb8bd423..00000000000 --- a/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE merchant_connector_account -ADD COLUMN feature_metadata JSONB; \ No newline at end of file