Skip to content

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

feat(process_tracker): Add a version column in process tracker table (#7389)

Amisha Prabhatdbecdcf1cfae
diff --git a/crates/diesel_models/src/process_tracker.rs b/crates/diesel_models/src/process_tracker.rs
index f998ca5d23..64b9a66afb 100644
--- a/crates/diesel_models/src/process_tracker.rs
+++ b/crates/diesel_models/src/process_tracker.rs
@@ -1,3 +1,4 @@
+use common_enums::ApiVersion;
use common_utils::ext_traits::Encode;
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use error_stack::ResultExt;
@@ -38,6 +39,7 @@ pub struct ProcessTracker {
pub created_at: PrimitiveDateTime,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub updated_at: PrimitiveDateTime,
+ pub version: ApiVersion,
}
impl ProcessTracker {
@@ -63,6 +65,7 @@ pub struct ProcessTrackerNew {
pub event: Vec<String>,
pub created_at: PrimitiveDateTime,
pub updated_at: PrimitiveDateTime,
+ pub version: ApiVersion,
}
impl ProcessTrackerNew {
@@ -73,6 +76,7 @@ impl ProcessTrackerNew {
tag: impl IntoIterator<Item = impl Into<String>>,
tracking_data: T,
schedule_time: PrimitiveDateTime,
+ api_version: ApiVersion,
) -> StorageResult<Self>
where
T: Serialize + std::fmt::Debug,
@@ -95,6 +99,7 @@ impl ProcessTrackerNew {
event: vec![],
created_at: current_time,
updated_at: current_time,
+ version: api_version,
})
}
}
diff --git a/crates/diesel_models/src/query/process_tracker.rs b/crates/diesel_models/src/query/process_tracker.rs
index 74f23ac0bf..1abc8b0edd 100644
--- a/crates/diesel_models/src/query/process_tracker.rs
+++ b/crates/diesel_models/src/query/process_tracker.rs
@@ -71,6 +71,7 @@ impl ProcessTracker {
time_upper_limit: PrimitiveDateTime,
status: enums::ProcessTrackerStatus,
limit: Option<i64>,
+ version: enums::ApiVersion,
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<
<Self as HasTable>::Table,
@@ -81,7 +82,8 @@ impl ProcessTracker {
conn,
dsl::schedule_time
.between(time_lower_limit, time_upper_limit)
- .and(dsl::status.eq(status)),
+ .and(dsl::status.eq(status))
+ .and(dsl::version.eq(version)),
limit,
None,
None,
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index ce29165ee7..ae01a54bd4 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -1212,6 +1212,7 @@ diesel::table! {
event -> Array<Nullable<Text>>,
created_at -> Timestamp,
updated_at -> Timestamp,
+ version -> ApiVersion,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 36b38f64a7..5d028ad521 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -1152,6 +1152,7 @@ diesel::table! {
event -> Array<Nullable<Text>>,
created_at -> Timestamp,
updated_at -> Timestamp,
+ version -> ApiVersion,
}
}
diff --git a/crates/hyperswitch_domain_models/src/consts.rs b/crates/hyperswitch_domain_models/src/consts.rs
index 4a87c35b5c..b1d9229951 100644
--- a/crates/hyperswitch_domain_models/src/consts.rs
+++ b/crates/hyperswitch_domain_models/src/consts.rs
@@ -1,9 +1,9 @@
//! Constants that are used in the domain models.
-#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
+#[cfg(feature = "v1")]
pub const API_VERSION: common_enums::ApiVersion = common_enums::ApiVersion::V1;
-#[cfg(all(feature = "v2", feature = "customer_v2"))]
+#[cfg(feature = "v2")]
pub const API_VERSION: common_enums::ApiVersion = common_enums::ApiVersion::V2;
/// Length of the unique reference ID generated for connector mandate requests
diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml
index 1e45219597..8ca5333847 100644
--- a/crates/router/Cargo.toml
+++ b/crates/router/Cargo.toml
@@ -33,8 +33,8 @@ payouts = ["api_models/payouts", "common_enums/payouts", "hyperswitch_connectors
payout_retry = ["payouts"]
recon = ["email", "api_models/recon"]
retry = []
-v2 = ["customer_v2", "payment_methods_v2", "common_default", "api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2", "storage_impl/v2", "kgraph_utils/v2", "common_utils/v2", "hyperswitch_connectors/v2","hyperswitch_interfaces/v2", "common_types/v2","revenue_recovery"]
-v1 = ["common_default", "api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1", "hyperswitch_interfaces/v1", "kgraph_utils/v1", "common_utils/v1", "hyperswitch_connectors/v1", "common_types/v1"]
+v2 = ["customer_v2", "payment_methods_v2", "common_default", "api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2", "storage_impl/v2", "kgraph_utils/v2", "common_utils/v2", "hyperswitch_connectors/v2","hyperswitch_interfaces/v2", "common_types/v2","revenue_recovery","scheduler/v2"]
+v1 = ["common_default", "api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1", "hyperswitch_interfaces/v1", "kgraph_utils/v1", "common_utils/v1", "hyperswitch_connectors/v1", "common_types/v1","scheduler/v1"]
customer_v2 = ["api_models/customer_v2", "diesel_models/customer_v2", "hyperswitch_domain_models/customer_v2", "storage_impl/customer_v2"]
payment_methods_v2 = ["api_models/payment_methods_v2", "diesel_models/payment_methods_v2", "hyperswitch_domain_models/payment_methods_v2", "storage_impl/payment_methods_v2", "common_utils/payment_methods_v2"]
dynamic_routing = ["external_services/dynamic_routing", "storage_impl/dynamic_routing", "api_models/dynamic_routing"]
diff --git a/crates/router/src/core/api_keys.rs b/crates/router/src/core/api_keys.rs
index 4d3f3df9a5..fc87a490b6 100644
--- a/crates/router/src/core/api_keys.rs
+++ b/crates/router/src/core/api_keys.rs
@@ -229,6 +229,7 @@ pub async fn add_api_key_expiry_task(
[API_KEY_EXPIRY_TAG],
api_key_expiry_tracker,
schedule_time,
+ hyperswitch_domain_models::consts::API_VERSION,
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to construct API key expiry process tracker task")?;
diff --git a/crates/router/src/core/passive_churn_recovery.rs b/crates/router/src/core/passive_churn_recovery.rs
index 3c77de98e7..958baeee3f 100644
--- a/crates/router/src/core/passive_churn_recovery.rs
+++ b/crates/router/src/core/passive_churn_recovery.rs
@@ -143,6 +143,7 @@ async fn insert_psync_pcr_task(
tag,
psync_workflow_tracking_data,
schedule_time,
+ hyperswitch_domain_models::consts::API_VERSION,
)
.change_context(api_error_response::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to construct delete tokenized data process tracker task")?;
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index 2ba5197e04..efc987ec3d 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -494,6 +494,7 @@ pub async fn add_payment_method_status_update_task(
tag,
tracking_data,
schedule_time,
+ hyperswitch_domain_models::consts::API_VERSION,
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to construct PAYMENT_METHOD_STATUS_UPDATE process tracker task")?;
diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rs
index 93461c6315..f65f048885 100644
--- a/crates/router/src/core/payment_methods/vault.rs
+++ b/crates/router/src/core/payment_methods/vault.rs
@@ -1402,6 +1402,7 @@ pub async fn add_delete_tokenized_data_task(
tag,
tracking_data,
schedule_time,
+ hyperswitch_domain_models::consts::API_VERSION,
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to construct delete tokenized data process tracker task")?;
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index d92d9b1fa0..d072463020 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -5942,6 +5942,7 @@ pub async fn add_process_sync_task(
tag,
tracking_data,
schedule_time,
+ hyperswitch_domain_models::consts::API_VERSION,
)
.map_err(errors::StorageError::from)?;
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index 450714b2b8..f1c8d29ca6 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -3093,6 +3093,7 @@ pub async fn add_external_account_addition_task(
tag,
tracking_data,
schedule_time,
+ hyperswitch_domain_models::consts::API_VERSION,
)
.map_err(errors::StorageError::from)?;
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index 938bf1a836..1057f47b4c 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -1606,6 +1606,7 @@ pub async fn add_refund_sync_task(
tag,
refund_workflow_tracking_data,
schedule_time,
+ hyperswitch_domain_models::consts::API_VERSION,
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to construct refund sync process tracker task")?;
@@ -1643,6 +1644,7 @@ pub async fn add_refund_execute_task(
tag,
refund_workflow_tracking_data,
schedule_time,
+ hyperswitch_domain_models::consts::API_VERSION,
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to construct refund execute process tracker task")?;
diff --git a/crates/router/src/core/webhooks/outgoing.rs b/crates/router/src/core/webhooks/outgoing.rs
index 4bb45327d8..595171114f 100644
--- a/crates/router/src/core/webhooks/outgoing.rs
+++ b/crates/router/src/core/webhooks/outgoing.rs
@@ -554,6 +554,7 @@ pub(crate) async fn add_outgoing_webhook_retry_task_to_process_tracker(
tag,
tracking_data,
schedule_time,
+ hyperswitch_domain_models::consts::API_VERSION,
)
.map_err(errors::StorageError::from)?;
diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs
index 461c9fb46a..84a90b2b99 100644
--- a/crates/router/src/db/kafka_store.rs
+++ b/crates/router/src/db/kafka_store.rs
@@ -2580,7 +2580,6 @@ impl ProcessTrackerInterface for KafkaStore {
.finish_process_with_business_status(this, business_status)
.await
}
-
async fn find_processes_by_time_status(
&self,
time_lower_limit: PrimitiveDateTime,
diff --git a/crates/scheduler/Cargo.toml b/crates/scheduler/Cargo.toml
index 24e8c63f95..176a4a99b2 100644
--- a/crates/scheduler/Cargo.toml
+++ b/crates/scheduler/Cargo.toml
@@ -11,6 +11,7 @@ olap = ["storage_impl/olap", "hyperswitch_domain_models/olap"]
kv_store = []
email = ["external_services/email"]
v1 = ["diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1", "common_utils/v1"]
+v2 = ["diesel_models/v2", "hyperswitch_domain_models/v2", "storage_impl/v2", "common_utils/v2"]
[dependencies]
# Third party crates
diff --git a/crates/scheduler/src/db/process_tracker.rs b/crates/scheduler/src/db/process_tracker.rs
index 1b23ff1b55..4cf516faa1 100644
--- a/crates/scheduler/src/db/process_tracker.rs
+++ b/crates/scheduler/src/db/process_tracker.rs
@@ -101,6 +101,7 @@ impl ProcessTrackerInterface for Store {
time_upper_limit,
status,
limit,
+ hyperswitch_domain_models::consts::API_VERSION,
)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
@@ -229,7 +230,6 @@ impl ProcessTrackerInterface for MockDb {
// [#172]: Implement function for `MockDb`
Err(errors::StorageError::MockDbError)?
}
-
async fn insert_process(
&self,
new: storage::ProcessTrackerNew,
@@ -249,6 +249,7 @@ impl ProcessTrackerInterface for MockDb {
event: new.event,
created_at: new.created_at,
updated_at: new.updated_at,
+ version: new.version,
};
processes.push(process.clone());
Ok(process)
diff --git a/migrations/2025-02-18-091645_add_api_version_for_process_tracker/down.sql b/migrations/2025-02-18-091645_add_api_version_for_process_tracker/down.sql
new file mode 100644
index 0000000000..9e7da8c120
--- /dev/null
+++ b/migrations/2025-02-18-091645_add_api_version_for_process_tracker/down.sql
@@ -0,0 +1,3 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE
+ process_tracker DROP COLUMN version;
\ No newline at end of file
diff --git a/migrations/2025-02-18-091645_add_api_version_for_process_tracker/up.sql b/migrations/2025-02-18-091645_add_api_version_for_process_tracker/up.sql
new file mode 100644
index 0000000000..0483d6642a
--- /dev/null
+++ b/migrations/2025-02-18-091645_add_api_version_for_process_tracker/up.sql
@@ -0,0 +1,5 @@
+-- Your SQL goes here
+ALTER TABLE
+ process_tracker
+ADD
+ COLUMN IF NOT EXISTS version "ApiVersion" NOT NULL DEFAULT 'v1';
\ No newline at end of file