From 492fd871a14e60e02f17fe073544bc40e79a7220 Mon Sep 17 00:00:00 2001 From: Prajjwal Kumar Date: Fri, 20 Dec 2024 13:27:23 +0530 Subject: [PATCH] refactor(dynamic_routing): add col payment_method_type in dynamic_routing_stats (#6853) --- crates/diesel_models/src/dynamic_routing_stats.rs | 2 ++ crates/diesel_models/src/schema.rs | 2 ++ crates/diesel_models/src/schema_v2.rs | 2 ++ crates/router/src/core/routing/helpers.rs | 1 + .../down.sql | 3 +++ .../up.sql | 3 +++ 6 files changed, 13 insertions(+) create mode 100644 migrations/2024-12-16-111228_add_new_col_payment_method_type_in_dynamic_routing_stats/down.sql create mode 100644 migrations/2024-12-16-111228_add_new_col_payment_method_type_in_dynamic_routing_stats/up.sql diff --git a/crates/diesel_models/src/dynamic_routing_stats.rs b/crates/diesel_models/src/dynamic_routing_stats.rs index 168699d7f566..c055359d8b03 100644 --- a/crates/diesel_models/src/dynamic_routing_stats.rs +++ b/crates/diesel_models/src/dynamic_routing_stats.rs @@ -19,6 +19,7 @@ pub struct DynamicRoutingStatsNew { pub payment_status: common_enums::AttemptStatus, pub conclusive_classification: common_enums::SuccessBasedRoutingConclusiveState, pub created_at: time::PrimitiveDateTime, + pub payment_method_type: Option, } #[derive(Clone, Debug, Eq, PartialEq, Queryable, Selectable, Insertable)] @@ -38,4 +39,5 @@ pub struct DynamicRoutingStats { pub payment_status: common_enums::AttemptStatus, pub conclusive_classification: common_enums::SuccessBasedRoutingConclusiveState, pub created_at: time::PrimitiveDateTime, + pub payment_method_type: Option, } diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index 178f5600542a..61a8a7e19b9e 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -417,6 +417,8 @@ diesel::table! { payment_status -> AttemptStatus, conclusive_classification -> SuccessBasedRoutingConclusiveState, created_at -> Timestamp, + #[max_length = 64] + payment_method_type -> Nullable, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index da2298d934bb..6569c0353654 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -429,6 +429,8 @@ diesel::table! { payment_status -> AttemptStatus, conclusive_classification -> SuccessBasedRoutingConclusiveState, created_at -> Timestamp, + #[max_length = 64] + payment_method_type -> Nullable, } } diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rs index b3c951f0964f..2abb5e64cd4b 100644 --- a/crates/router/src/core/routing/helpers.rs +++ b/crates/router/src/core/routing/helpers.rs @@ -761,6 +761,7 @@ pub async fn push_metrics_with_update_window_for_success_based_routing( amount: payment_attempt.get_total_amount(), success_based_routing_connector: first_success_based_connector.to_string(), payment_connector: payment_connector.to_string(), + payment_method_type: payment_attempt.payment_method_type, currency: payment_attempt.currency, payment_method: payment_attempt.payment_method, capture_method: payment_attempt.capture_method, diff --git a/migrations/2024-12-16-111228_add_new_col_payment_method_type_in_dynamic_routing_stats/down.sql b/migrations/2024-12-16-111228_add_new_col_payment_method_type_in_dynamic_routing_stats/down.sql new file mode 100644 index 000000000000..bc2f40c91d21 --- /dev/null +++ b/migrations/2024-12-16-111228_add_new_col_payment_method_type_in_dynamic_routing_stats/down.sql @@ -0,0 +1,3 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE dynamic_routing_stats +DROP COLUMN IF EXISTS payment_method_type; diff --git a/migrations/2024-12-16-111228_add_new_col_payment_method_type_in_dynamic_routing_stats/up.sql b/migrations/2024-12-16-111228_add_new_col_payment_method_type_in_dynamic_routing_stats/up.sql new file mode 100644 index 000000000000..2b5af8090f0d --- /dev/null +++ b/migrations/2024-12-16-111228_add_new_col_payment_method_type_in_dynamic_routing_stats/up.sql @@ -0,0 +1,3 @@ +-- Your SQL goes here +ALTER TABLE dynamic_routing_stats +ADD COLUMN IF NOT EXISTS payment_method_type VARCHAR(64);