diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index a2912e73c45..e5dedad8cbf 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -7989,6 +7989,7 @@ pub enum UIWidgetFormLayout { Clone, Copy, Debug, + Default, Eq, PartialEq, serde::Deserialize, @@ -8001,6 +8002,7 @@ pub enum UIWidgetFormLayout { #[strum(serialize_all = "snake_case")] #[serde(rename_all = "snake_case")] pub enum DeleteStatus { + #[default] Active, Redacted, } diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs index bbb76b53f40..e36eb305c45 100644 --- a/crates/diesel_models/src/business_profile.rs +++ b/crates/diesel_models/src/business_profile.rs @@ -402,10 +402,10 @@ pub struct Profile { pub three_ds_decision_manager_config: Option, pub should_collect_cvv_during_payment: Option, - pub is_external_vault_enabled: Option, - pub external_vault_connector_details: Option, pub revenue_recovery_retry_algorithm_type: Option, pub revenue_recovery_retry_algorithm_data: Option, + pub is_external_vault_enabled: Option, + pub external_vault_connector_details: Option, } impl Profile { diff --git a/crates/diesel_models/src/customers.rs b/crates/diesel_models/src/customers.rs index ae6ff49d106..88fcd667f17 100644 --- a/crates/diesel_models/src/customers.rs +++ b/crates/diesel_models/src/customers.rs @@ -6,7 +6,9 @@ use time::PrimitiveDateTime; #[cfg(feature = "v1")] use crate::schema::customers; #[cfg(feature = "v2")] -use crate::{enums::DeleteStatus, schema_v2::customers}; +use crate::{ + diesel_impl::RequiredFromNullableWithDefault, enums::DeleteStatus, schema_v2::customers, +}; #[cfg(feature = "v1")] #[derive( @@ -164,6 +166,7 @@ pub struct Customer { pub merchant_reference_id: Option, pub default_billing_address: Option, pub default_shipping_address: Option, + #[diesel(deserialize_as = RequiredFromNullableWithDefault)] pub status: DeleteStatus, pub id: common_utils::id_type::GlobalCustomerId, } diff --git a/crates/diesel_models/src/lib.rs b/crates/diesel_models/src/lib.rs index e34e7e552d8..246807a041a 100644 --- a/crates/diesel_models/src/lib.rs +++ b/crates/diesel_models/src/lib.rs @@ -61,6 +61,8 @@ pub mod user_key_store; pub mod user_role; use diesel_impl::{DieselArray, OptionalDieselArray}; +#[cfg(feature = "v2")] +use diesel_impl::{RequiredFromNullable, RequiredFromNullableWithDefault}; pub type StorageResult = error_stack::Result; pub type PgPooledConn = async_bb8_diesel::Connection; @@ -71,7 +73,6 @@ pub use self::{ payment_intent::*, payment_method::*, payout_attempt::*, payouts::*, process_tracker::*, refund::*, reverse_lookup::*, user_authentication_method::*, }; - /// The types and implementations provided by this module are required for the schema generated by /// `diesel_cli` 2.0 to work with the types defined in Rust code. This is because /// [`diesel`][diesel] 2.0 [changed the nullability of array elements][diesel-2.0-array-nullability], @@ -83,6 +84,8 @@ pub use self::{ /// [diesel-2.0-array-nullability]: https://diesel.rs/guides/migration_guide.html#2-0-0-nullability-of-array-elements #[doc(hidden)] pub(crate) mod diesel_impl { + #[cfg(feature = "v2")] + use common_utils::{id_type, types}; use diesel::{ deserialize::FromSql, pg::Pg, @@ -90,6 +93,9 @@ pub(crate) mod diesel_impl { Queryable, }; + #[cfg(feature = "v2")] + use crate::enums; + pub struct DieselArray(Vec>); impl From> for Vec { @@ -130,6 +136,119 @@ pub(crate) mod diesel_impl { Ok(Self(row)) } } + #[cfg(feature = "v2")] + /// If the DB value is null, this wrapper will return an error when deserializing. + /// + /// This is useful when you want to ensure that a field is always present, even if the database + /// value is NULL. If the database column contains a NULL value, an error will be returned. + pub struct RequiredFromNullable(T); + + #[cfg(feature = "v2")] + impl RequiredFromNullable { + /// Extracts the inner value from the wrapper + pub fn into_inner(self) -> T { + self.0 + } + } + + #[cfg(feature = "v2")] + impl Queryable, DB> for RequiredFromNullable + where + DB: diesel::backend::Backend, + T: Queryable, + Option: FromSql, DB>, + ST: diesel::sql_types::SingleValue, + { + type Row = Option; + + fn build(row: Self::Row) -> diesel::deserialize::Result { + match row { + Some(inner_row) => { + let value = T::build(inner_row)?; + Ok(Self(value)) + } + None => Err("Cannot deserialize NULL value for required field. Check if the database column that should not be NULL contains a NULL value.".into()), + } + } + } + + #[cfg(feature = "v2")] + /// If the DB value is null, this wrapper will provide a default value for the type `T`. + /// + /// This is useful when you want to ensure that a field is always present, even if the database + /// value is NULL. The default value is provided by the `Default` trait implementation of `T`. + pub struct RequiredFromNullableWithDefault(T); + #[cfg(feature = "v2")] + impl RequiredFromNullableWithDefault { + /// Extracts the inner value from the wrapper + pub fn into_inner(self) -> T { + self.0 + } + } + #[cfg(feature = "v2")] + impl Queryable, DB> for RequiredFromNullableWithDefault + where + DB: diesel::backend::Backend, + T: Queryable, + T: Default, + Option: FromSql, DB>, + ST: diesel::sql_types::SingleValue, + { + type Row = Option; + + fn build(row: Self::Row) -> diesel::deserialize::Result { + match row { + Some(inner_row) => { + let value = T::build(inner_row)?; + Ok(Self(value)) + } + None => Ok(Self(T::default())), + } + } + } + + #[cfg(feature = "v2")] + /// Macro to implement From trait for types wrapped in RequiredFromNullable + #[macro_export] + macro_rules! impl_from_required_from_nullable { + ($($type:ty),* $(,)?) => { + $( + impl From<$crate::RequiredFromNullable<$type>> for $type { + fn from(wrapper: $crate::RequiredFromNullable<$type>) -> Self { + wrapper.into_inner() + } + } + )* + }; + } + + #[cfg(feature = "v2")] + /// Macro to implement From trait for types wrapped in RequiredFromNullableWithDefault + #[macro_export] + macro_rules! impl_from_required_from_nullable_with_default { + ($($type:ty),* $(,)?) => { + $( + impl From<$crate::RequiredFromNullableWithDefault<$type>> for $type { + fn from(wrapper: $crate::RequiredFromNullableWithDefault<$type>) -> Self { + wrapper.into_inner() + } + } + )* + }; + } + #[cfg(feature = "v2")] + crate::impl_from_required_from_nullable_with_default!(enums::DeleteStatus); + + #[cfg(feature = "v2")] + crate::impl_from_required_from_nullable!( + enums::AuthenticationType, + types::MinorUnit, + enums::PaymentMethod, + enums::Currency, + id_type::ProfileId, + time::PrimitiveDateTime, + id_type::RefundReferenceId, + ); } pub(crate) mod metrics { diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rs index be7f1b7ebeb..958466acb17 100644 --- a/crates/diesel_models/src/merchant_connector_account.rs +++ b/crates/diesel_models/src/merchant_connector_account.rs @@ -64,6 +64,9 @@ impl MerchantConnectorAccount { } } +#[cfg(feature = "v2")] +use crate::RequiredFromNullable; + #[cfg(feature = "v2")] #[derive( Clone, @@ -91,6 +94,7 @@ pub struct MerchantConnectorAccount { pub connector_webhook_details: Option, #[diesel(deserialize_as = super::OptionalDieselArray)] pub frm_config: Option>, + #[diesel(deserialize_as = RequiredFromNullable)] pub profile_id: id_type::ProfileId, #[diesel(deserialize_as = super::OptionalDieselArray)] pub applepay_verified_domains: Option>, diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 361db5f1353..41f4debb165 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -15,7 +15,7 @@ use crate::enums as storage_enums; #[cfg(feature = "v1")] use crate::schema::payment_attempt; #[cfg(feature = "v2")] -use crate::schema_v2::payment_attempt; +use crate::{schema_v2::payment_attempt, RequiredFromNullable}; common_utils::impl_to_sql_from_sql_json!(ConnectorMandateReferenceId); #[derive( @@ -48,6 +48,7 @@ pub struct PaymentAttempt { pub error_message: Option, pub surcharge_amount: Option, pub payment_method_id: Option, + #[diesel(deserialize_as = RequiredFromNullable)] pub authentication_type: storage_enums::AuthenticationType, #[serde(with = "common_utils::custom_serde::iso8601")] pub created_at: PrimitiveDateTime, @@ -73,6 +74,7 @@ pub struct PaymentAttempt { pub encoded_data: Option>, pub unified_code: Option, pub unified_message: Option, + #[diesel(deserialize_as = RequiredFromNullable)] pub net_amount: MinorUnit, pub external_three_ds_authentication_attempted: Option, pub authentication_connector: Option, @@ -93,6 +95,8 @@ pub struct PaymentAttempt { pub charges: Option, pub processor_merchant_id: Option, pub created_by: Option, + pub connector_request_reference_id: Option, + #[diesel(deserialize_as = RequiredFromNullable)] pub payment_method_type_v2: storage_enums::PaymentMethod, pub connector_payment_id: Option, pub payment_method_subtype: storage_enums::PaymentMethodType, @@ -114,7 +118,6 @@ pub struct PaymentAttempt { pub network_decline_code: Option, /// A string indicating how to proceed with an network error if payment gateway provide one. This is used to understand the network error code better. pub network_error_message: Option, - pub connector_request_reference_id: Option, } #[cfg(feature = "v1")] diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs index 72ee13a95be..4e67ddcc4f8 100644 --- a/crates/diesel_models/src/payment_intent.rs +++ b/crates/diesel_models/src/payment_intent.rs @@ -11,6 +11,8 @@ use crate::schema::payment_intent; use crate::schema_v2::payment_intent; #[cfg(feature = "v2")] use crate::types::{FeatureMetadata, OrderDetailsWithAmount}; +#[cfg(feature = "v2")] +use crate::RequiredFromNullable; use crate::{business_profile::PaymentLinkBackgroundImageConfig, enums as storage_enums}; #[cfg(feature = "v2")] @@ -20,6 +22,7 @@ pub struct PaymentIntent { pub merchant_id: common_utils::id_type::MerchantId, pub status: storage_enums::IntentStatus, pub amount: MinorUnit, + #[diesel(deserialize_as = RequiredFromNullable)] pub currency: storage_enums::Currency, pub amount_captured: Option, pub customer_id: Option, @@ -40,12 +43,14 @@ pub struct PaymentIntent { pub connector_metadata: Option, pub feature_metadata: Option, pub attempt_count: i16, + #[diesel(deserialize_as = RequiredFromNullable)] pub profile_id: common_utils::id_type::ProfileId, pub payment_link_id: Option, pub updated_by: String, pub surcharge_applicable: Option, pub request_incremental_authorization: Option, pub authorization_count: Option, + #[diesel(deserialize_as = RequiredFromNullable)] pub session_expiry: PrimitiveDateTime, pub request_external_three_ds_authentication: Option, pub frm_metadata: Option, diff --git a/crates/diesel_models/src/refund.rs b/crates/diesel_models/src/refund.rs index f7cb1c595e6..a3657e6a4d5 100644 --- a/crates/diesel_models/src/refund.rs +++ b/crates/diesel_models/src/refund.rs @@ -1,5 +1,5 @@ use common_utils::{ - pii, + id_type, pii, types::{ChargeRefunds, ConnectorTransactionId, ConnectorTransactionIdTrait, MinorUnit}, }; use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable}; @@ -10,7 +10,8 @@ use crate::enums as storage_enums; #[cfg(feature = "v1")] use crate::schema::refund; #[cfg(feature = "v2")] -use crate::schema_v2::refund; +use crate::{schema_v2::refund, RequiredFromNullable}; + #[cfg(feature = "v1")] #[derive( Clone, @@ -27,8 +28,8 @@ use crate::schema_v2::refund; pub struct Refund { pub internal_reference_id: String, pub refund_id: String, //merchant_reference id - pub payment_id: common_utils::id_type::PaymentId, - pub merchant_id: common_utils::id_type::MerchantId, + pub payment_id: id_type::PaymentId, + pub merchant_id: id_type::MerchantId, pub connector_transaction_id: ConnectorTransactionId, pub connector: String, pub connector_refund_id: Option, @@ -50,11 +51,11 @@ pub struct Refund { pub attempt_id: String, pub refund_reason: Option, pub refund_error_code: Option, - pub profile_id: Option, + pub profile_id: Option, pub updated_by: String, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub charges: Option, - pub organization_id: common_utils::id_type::OrganizationId, + pub organization_id: id_type::OrganizationId, /// INFO: This field is deprecated and replaced by processor_refund_data pub connector_refund_data: Option, /// INFO: This field is deprecated and replaced by processor_transaction_data @@ -82,8 +83,8 @@ pub struct Refund { )] #[diesel(table_name = refund, primary_key(id), check_for_backend(diesel::pg::Pg))] pub struct Refund { - pub payment_id: common_utils::id_type::GlobalPaymentId, - pub merchant_id: common_utils::id_type::MerchantId, + pub payment_id: id_type::GlobalPaymentId, + pub merchant_id: id_type::MerchantId, pub connector_transaction_id: ConnectorTransactionId, pub connector: String, pub connector_refund_id: Option, @@ -102,21 +103,22 @@ pub struct Refund { #[serde(with = "common_utils::custom_serde::iso8601")] pub modified_at: PrimitiveDateTime, pub description: Option, - pub attempt_id: common_utils::id_type::GlobalAttemptId, + pub attempt_id: id_type::GlobalAttemptId, pub refund_reason: Option, pub refund_error_code: Option, - pub profile_id: Option, + pub profile_id: Option, pub updated_by: String, pub charges: Option, - pub organization_id: common_utils::id_type::OrganizationId, + pub organization_id: id_type::OrganizationId, pub split_refunds: Option, pub unified_code: Option, pub unified_message: Option, pub processor_refund_data: Option, pub processor_transaction_data: Option, - pub id: common_utils::id_type::GlobalRefundId, - pub merchant_reference_id: common_utils::id_type::RefundReferenceId, - pub connector_id: Option, + pub id: id_type::GlobalRefundId, + #[diesel(deserialize_as = RequiredFromNullable)] + pub merchant_reference_id: id_type::RefundReferenceId, + pub connector_id: Option, } #[cfg(feature = "v1")] @@ -134,8 +136,8 @@ pub struct Refund { #[diesel(table_name = refund)] pub struct RefundNew { pub refund_id: String, - pub payment_id: common_utils::id_type::PaymentId, - pub merchant_id: common_utils::id_type::MerchantId, + pub payment_id: id_type::PaymentId, + pub merchant_id: id_type::MerchantId, pub internal_reference_id: String, pub external_reference_id: Option, pub connector_transaction_id: ConnectorTransactionId, @@ -156,11 +158,11 @@ pub struct RefundNew { pub description: Option, pub attempt_id: String, pub refund_reason: Option, - pub profile_id: Option, + pub profile_id: Option, pub updated_by: String, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub charges: Option, - pub organization_id: common_utils::id_type::OrganizationId, + pub organization_id: id_type::OrganizationId, pub split_refunds: Option, pub processor_refund_data: Option, pub processor_transaction_data: Option, @@ -180,10 +182,10 @@ pub struct RefundNew { )] #[diesel(table_name = refund)] pub struct RefundNew { - pub merchant_reference_id: common_utils::id_type::RefundReferenceId, - pub payment_id: common_utils::id_type::GlobalPaymentId, - pub merchant_id: common_utils::id_type::MerchantId, - pub id: common_utils::id_type::GlobalRefundId, + pub merchant_reference_id: id_type::RefundReferenceId, + pub payment_id: id_type::GlobalPaymentId, + pub merchant_id: id_type::MerchantId, + pub id: id_type::GlobalRefundId, pub external_reference_id: Option, pub connector_transaction_id: ConnectorTransactionId, pub connector: String, @@ -201,13 +203,13 @@ pub struct RefundNew { #[serde(with = "common_utils::custom_serde::iso8601")] pub modified_at: PrimitiveDateTime, pub description: Option, - pub attempt_id: common_utils::id_type::GlobalAttemptId, + pub attempt_id: id_type::GlobalAttemptId, pub refund_reason: Option, - pub profile_id: Option, + pub profile_id: Option, pub updated_by: String, - pub connector_id: Option, + pub connector_id: Option, pub charges: Option, - pub organization_id: common_utils::id_type::OrganizationId, + pub organization_id: id_type::OrganizationId, pub split_refunds: Option, pub processor_refund_data: Option, pub processor_transaction_data: Option, @@ -781,18 +783,18 @@ impl RefundUpdate { pub struct RefundCoreWorkflow { pub refund_internal_reference_id: String, pub connector_transaction_id: ConnectorTransactionId, - pub merchant_id: common_utils::id_type::MerchantId, - pub payment_id: common_utils::id_type::PaymentId, + pub merchant_id: id_type::MerchantId, + pub payment_id: id_type::PaymentId, pub processor_transaction_data: Option, } #[cfg(feature = "v2")] #[derive(Debug, Eq, PartialEq, Deserialize, Serialize)] pub struct RefundCoreWorkflow { - pub refund_id: common_utils::id_type::GlobalRefundId, + pub refund_id: id_type::GlobalRefundId, pub connector_transaction_id: ConnectorTransactionId, - pub merchant_id: common_utils::id_type::MerchantId, - pub payment_id: common_utils::id_type::GlobalPaymentId, + pub merchant_id: id_type::MerchantId, + pub payment_id: id_type::GlobalPaymentId, pub processor_transaction_data: Option, } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index c5579b6c67b..fa67e356374 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -253,10 +253,10 @@ diesel::table! { default_fallback_routing -> Nullable, three_ds_decision_manager_config -> Nullable, should_collect_cvv_during_payment -> Nullable, - is_external_vault_enabled -> Nullable, - external_vault_connector_details -> Nullable, revenue_recovery_retry_algorithm_type -> Nullable, revenue_recovery_retry_algorithm_data -> Nullable, + is_external_vault_enabled -> Nullable, + external_vault_connector_details -> Nullable, } } @@ -375,7 +375,7 @@ diesel::table! { merchant_reference_id -> Nullable, default_billing_address -> Nullable, default_shipping_address -> Nullable, - status -> DeleteStatus, + status -> Nullable, #[max_length = 64] id -> Varchar, } @@ -789,7 +789,7 @@ diesel::table! { connector_webhook_details -> Nullable, frm_config -> Nullable>>, #[max_length = 64] - profile_id -> Varchar, + profile_id -> Nullable, applepay_verified_domains -> Nullable>>, pm_auth_config -> Nullable, status -> ConnectorStatus, @@ -850,7 +850,7 @@ diesel::table! { surcharge_amount -> Nullable, #[max_length = 64] payment_method_id -> Nullable, - authentication_type -> AuthenticationType, + authentication_type -> Nullable, created_at -> Timestamp, modified_at -> Timestamp, last_synced -> Nullable, @@ -881,7 +881,7 @@ diesel::table! { unified_code -> Nullable, #[max_length = 1024] unified_message -> Nullable, - net_amount -> Int8, + net_amount -> Nullable, external_three_ds_authentication_attempted -> Nullable, #[max_length = 64] authentication_connector -> Nullable, @@ -911,7 +911,9 @@ diesel::table! { processor_merchant_id -> Nullable, #[max_length = 255] created_by -> Nullable, - payment_method_type_v2 -> Varchar, + #[max_length = 255] + connector_request_reference_id -> Nullable, + payment_method_type_v2 -> Nullable, #[max_length = 128] connector_payment_id -> Nullable, #[max_length = 64] @@ -933,8 +935,6 @@ diesel::table! { #[max_length = 32] network_decline_code -> Nullable, network_error_message -> Nullable, - #[max_length = 255] - connector_request_reference_id -> Nullable, } } @@ -947,7 +947,7 @@ diesel::table! { merchant_id -> Varchar, status -> IntentStatus, amount -> Int8, - currency -> Currency, + currency -> Nullable, amount_captured -> Nullable, #[max_length = 64] customer_id -> Nullable, @@ -968,7 +968,7 @@ diesel::table! { feature_metadata -> Nullable, attempt_count -> Int2, #[max_length = 64] - profile_id -> Varchar, + profile_id -> Nullable, #[max_length = 255] payment_link_id -> Nullable, #[max_length = 32] @@ -976,7 +976,7 @@ diesel::table! { surcharge_applicable -> Nullable, request_incremental_authorization -> Nullable, authorization_count -> Nullable, - session_expiry -> Timestamp, + session_expiry -> Nullable, request_external_three_ds_authentication -> Nullable, frm_metadata -> Nullable, customer_details -> Nullable, @@ -1267,7 +1267,7 @@ diesel::table! { #[max_length = 64] id -> Varchar, #[max_length = 64] - merchant_reference_id -> Varchar, + merchant_reference_id -> Nullable, #[max_length = 64] connector_id -> Nullable, } diff --git a/v2_migrations/2025-01-17-042122_add_feature_metadata_in_payment_attempt/down.sql b/v2_compatible_migrations/2025-01-17-042122_add_feature_metadata_in_payment_attempt/down.sql similarity index 100% rename from v2_migrations/2025-01-17-042122_add_feature_metadata_in_payment_attempt/down.sql rename to v2_compatible_migrations/2025-01-17-042122_add_feature_metadata_in_payment_attempt/down.sql diff --git a/v2_migrations/2025-01-17-042122_add_feature_metadata_in_payment_attempt/up.sql b/v2_compatible_migrations/2025-01-17-042122_add_feature_metadata_in_payment_attempt/up.sql similarity index 100% rename from v2_migrations/2025-01-17-042122_add_feature_metadata_in_payment_attempt/up.sql rename to v2_compatible_migrations/2025-01-17-042122_add_feature_metadata_in_payment_attempt/up.sql diff --git a/v2_compatible_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/down.sql b/v2_compatible_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/down.sql new file mode 100644 index 00000000000..6f51a37b425 --- /dev/null +++ b/v2_compatible_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP INDEX IF EXISTS payment_attempt_payment_id_index; \ No newline at end of file diff --git a/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/up.sql b/v2_compatible_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/up.sql similarity index 62% rename from v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/up.sql rename to v2_compatible_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/up.sql index 9a9a9b077cd..fec1764213a 100644 --- a/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/up.sql +++ b/v2_compatible_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/up.sql @@ -1,3 +1,2 @@ -- Your SQL goes here -DROP INDEX IF EXISTS payment_attempt_payment_id_merchant_id_index; CREATE INDEX IF NOT EXISTS payment_attempt_payment_id_index ON payment_attempt (payment_id); \ No newline at end of file diff --git a/v2_migrations/2025-02-24-053820_add_billing_processor_value_to_connector_type_enum/down.sql b/v2_compatible_migrations/2025-02-24-053820_add_billing_processor_value_to_connector_type_enum/down.sql similarity index 100% rename from v2_migrations/2025-02-24-053820_add_billing_processor_value_to_connector_type_enum/down.sql rename to v2_compatible_migrations/2025-02-24-053820_add_billing_processor_value_to_connector_type_enum/down.sql diff --git a/v2_migrations/2025-02-24-053820_add_billing_processor_value_to_connector_type_enum/up.sql b/v2_compatible_migrations/2025-02-24-053820_add_billing_processor_value_to_connector_type_enum/up.sql similarity index 100% rename from v2_migrations/2025-02-24-053820_add_billing_processor_value_to_connector_type_enum/up.sql rename to v2_compatible_migrations/2025-02-24-053820_add_billing_processor_value_to_connector_type_enum/up.sql diff --git a/v2_migrations/2025-03-19-080705_payment-method-subtype-optional/down.sql b/v2_compatible_migrations/2025-03-19-080705_payment-method-subtype-optional/down.sql similarity index 100% rename from v2_migrations/2025-03-19-080705_payment-method-subtype-optional/down.sql rename to v2_compatible_migrations/2025-03-19-080705_payment-method-subtype-optional/down.sql diff --git a/v2_migrations/2025-03-19-080705_payment-method-subtype-optional/up.sql b/v2_compatible_migrations/2025-03-19-080705_payment-method-subtype-optional/up.sql similarity index 100% rename from v2_migrations/2025-03-19-080705_payment-method-subtype-optional/up.sql rename to v2_compatible_migrations/2025-03-19-080705_payment-method-subtype-optional/up.sql diff --git a/v2_migrations/2025-03-25-074512_payment-method-subtype-mandatory/down.sql b/v2_compatible_migrations/2025-03-25-074512_payment-method-subtype-mandatory/down.sql similarity index 100% rename from v2_migrations/2025-03-25-074512_payment-method-subtype-mandatory/down.sql rename to v2_compatible_migrations/2025-03-25-074512_payment-method-subtype-mandatory/down.sql diff --git a/v2_migrations/2025-03-25-074512_payment-method-subtype-mandatory/up.sql b/v2_compatible_migrations/2025-03-25-074512_payment-method-subtype-mandatory/up.sql similarity index 100% rename from v2_migrations/2025-03-25-074512_payment-method-subtype-mandatory/up.sql rename to v2_compatible_migrations/2025-03-25-074512_payment-method-subtype-mandatory/up.sql diff --git a/v2_migrations/2025-04-02-051959_add_network_error_info_in_payment_attempt/down.sql b/v2_compatible_migrations/2025-04-02-051959_add_network_error_info_in_payment_attempt/down.sql similarity index 100% rename from v2_migrations/2025-04-02-051959_add_network_error_info_in_payment_attempt/down.sql rename to v2_compatible_migrations/2025-04-02-051959_add_network_error_info_in_payment_attempt/down.sql diff --git a/v2_migrations/2025-04-02-051959_add_network_error_info_in_payment_attempt/up.sql b/v2_compatible_migrations/2025-04-02-051959_add_network_error_info_in_payment_attempt/up.sql similarity index 100% rename from v2_migrations/2025-04-02-051959_add_network_error_info_in_payment_attempt/up.sql rename to v2_compatible_migrations/2025-04-02-051959_add_network_error_info_in_payment_attempt/up.sql diff --git a/v2_migrations/2025-04-08-101702_add_recovery_algorithm_column_in_business_profile/down.sql b/v2_compatible_migrations/2025-04-08-101702_add_recovery_algorithm_column_in_business_profile/down.sql similarity index 100% rename from v2_migrations/2025-04-08-101702_add_recovery_algorithm_column_in_business_profile/down.sql rename to v2_compatible_migrations/2025-04-08-101702_add_recovery_algorithm_column_in_business_profile/down.sql diff --git a/v2_migrations/2025-04-08-101702_add_recovery_algorithm_column_in_business_profile/up.sql b/v2_compatible_migrations/2025-04-08-101702_add_recovery_algorithm_column_in_business_profile/up.sql similarity index 100% rename from v2_migrations/2025-04-08-101702_add_recovery_algorithm_column_in_business_profile/up.sql rename to v2_compatible_migrations/2025-04-08-101702_add_recovery_algorithm_column_in_business_profile/up.sql diff --git a/v2_migrations/2025-04-25-105138_tokenization_service_creation/down.sql b/v2_compatible_migrations/2025-04-25-105138_tokenization_service_creation/down.sql similarity index 100% rename from v2_migrations/2025-04-25-105138_tokenization_service_creation/down.sql rename to v2_compatible_migrations/2025-04-25-105138_tokenization_service_creation/down.sql diff --git a/v2_migrations/2025-04-25-105138_tokenization_service_creation/up.sql b/v2_compatible_migrations/2025-04-25-105138_tokenization_service_creation/up.sql similarity index 100% rename from v2_migrations/2025-04-25-105138_tokenization_service_creation/up.sql rename to v2_compatible_migrations/2025-04-25-105138_tokenization_service_creation/up.sql diff --git a/v2_compatible_migrations/2025-07-16-035805_add_index_on_mca_for_profile_id/down.sql b/v2_compatible_migrations/2025-07-16-035805_add_index_on_mca_for_profile_id/down.sql new file mode 100644 index 00000000000..a50f4cc4a5b --- /dev/null +++ b/v2_compatible_migrations/2025-07-16-035805_add_index_on_mca_for_profile_id/down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS merchant_connector_account_profile_id_index; \ No newline at end of file diff --git a/v2_compatible_migrations/2025-07-16-035805_add_index_on_mca_for_profile_id/up.sql b/v2_compatible_migrations/2025-07-16-035805_add_index_on_mca_for_profile_id/up.sql new file mode 100644 index 00000000000..f5cd252fab3 --- /dev/null +++ b/v2_compatible_migrations/2025-07-16-035805_add_index_on_mca_for_profile_id/up.sql @@ -0,0 +1,3 @@ +-- Create index on profile_id +CREATE INDEX IF NOT EXISTS merchant_connector_account_profile_id_index +ON merchant_connector_account (profile_id); diff --git a/v2_migrations/2024-08-28-081837_add_not_null_constraints_to_v2_columns/down.sql b/v2_migrations/2024-08-28-081837_add_not_null_constraints_to_v2_columns/down.sql deleted file mode 100644 index 6a10d16c5c1..00000000000 --- a/v2_migrations/2024-08-28-081837_add_not_null_constraints_to_v2_columns/down.sql +++ /dev/null @@ -1,26 +0,0 @@ --- This file should undo anything in `up.sql` -ALTER TABLE customers - ALTER COLUMN status DROP NOT NULL, - ALTER COLUMN status DROP DEFAULT; - -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; - -ALTER TABLE refund - ALTER COLUMN merchant_reference_id DROP NOT NULL; \ No newline at end of file diff --git a/v2_migrations/2024-08-28-081837_add_not_null_constraints_to_v2_columns/up.sql b/v2_migrations/2024-08-28-081837_add_not_null_constraints_to_v2_columns/up.sql deleted file mode 100644 index 83b9b97cdc1..00000000000 --- a/v2_migrations/2024-08-28-081837_add_not_null_constraints_to_v2_columns/up.sql +++ /dev/null @@ -1,27 +0,0 @@ --- Your SQL goes here - -ALTER TABLE customers - ALTER COLUMN status SET NOT NULL, - ALTER COLUMN status SET DEFAULT 'active'; - --- 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; - --- This migration is to make fields mandatory in refund table -ALTER TABLE refund - ALTER COLUMN merchant_reference_id SET NOT NULL; \ No newline at end of file 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 a48c2b660f5..268d286d900 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 @@ -38,8 +38,6 @@ UPDATE merchant_connector_account SET merchant_connector_id = id WHERE merchant_connector_id IS 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; 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 df0c434d68f..6a7ed8ecdc6 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 @@ -48,10 +48,6 @@ WHERE id IS NULL; ALTER TABLE merchant_connector_account ADD PRIMARY KEY (id); --- Create index on profile_id -CREATE INDEX IF NOT EXISTS merchant_connector_account_profile_id_index -ON merchant_connector_account (profile_id); - ------------------------ Customers ----------------------- -- Backfill id column with customer_id values UPDATE customers 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 f716de7bb0a..f28582f1868 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 @@ -136,5 +136,3 @@ ALTER TABLE refund ADD COLUMN IF NOT EXISTS internal_reference_id VARCHAR(64), ADD COLUMN IF NOT EXISTS refund_id VARCHAR(64), ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(64); - -ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS connector_request_reference_id VARCHAR(255); \ 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 be5a7b845a1..95348656f9a 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 @@ -130,8 +130,3 @@ ALTER TABLE refund DROP COLUMN IF EXISTS internal_reference_id, DROP COLUMN IF EXISTS refund_id, DROP COLUMN IF EXISTS merchant_connector_id; - --- Run below queries only when V1 is deprecated -ALTER TABLE payment_attempt DROP COLUMN IF EXISTS connector_request_reference_id; - - diff --git a/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/down.sql b/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/down.sql deleted file mode 100644 index 42c7d02ff2d..00000000000 --- a/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/down.sql +++ /dev/null @@ -1,3 +0,0 @@ --- This file should undo anything in `up.sql` -DROP INDEX IF EXISTS payment_attempt_payment_id_index; -CREATE INDEX IF NOT EXISTS payment_attempt_payment_id_merchant_id_index ON payment_attempt (payment_id, merchant_id); \ No newline at end of file diff --git a/v2_migrations/2025-05-30-103514_add_connector_request_reference_id_in_payment_attempt/down.sql b/v2_migrations/2025-05-30-103514_add_connector_request_reference_id_in_payment_attempt/down.sql deleted file mode 100644 index da0137560b9..00000000000 --- a/v2_migrations/2025-05-30-103514_add_connector_request_reference_id_in_payment_attempt/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -ALTER TABLE payment_attempt DROP COLUMN IF EXISTS connector_request_reference_id; \ No newline at end of file diff --git a/v2_migrations/2025-05-30-103514_add_connector_request_reference_id_in_payment_attempt/up.sql b/v2_migrations/2025-05-30-103514_add_connector_request_reference_id_in_payment_attempt/up.sql deleted file mode 100644 index cda71f826fc..00000000000 --- a/v2_migrations/2025-05-30-103514_add_connector_request_reference_id_in_payment_attempt/up.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Your SQL goes here -ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS connector_request_reference_id VARCHAR(255); \ No newline at end of file