Skip to content

Commit d187bc9

Browse files
committed
chore: update diesel models
1 parent 2bc494a commit d187bc9

File tree

8 files changed

+83
-20
lines changed

8 files changed

+83
-20
lines changed

crates/common_enums/src/enums.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7942,6 +7942,7 @@ pub enum UIWidgetFormLayout {
79427942
Clone,
79437943
Copy,
79447944
Debug,
7945+
Default,
79457946
Eq,
79467947
PartialEq,
79477948
serde::Deserialize,
@@ -7954,6 +7955,7 @@ pub enum UIWidgetFormLayout {
79547955
#[strum(serialize_all = "snake_case")]
79557956
#[serde(rename_all = "snake_case")]
79567957
pub enum DeleteStatus {
7958+
#[default]
79577959
Active,
79587960
Redacted,
79597961
}

crates/diesel_models/src/customers.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ use time::PrimitiveDateTime;
66
#[cfg(feature = "v1")]
77
use crate::schema::customers;
88
#[cfg(feature = "v2")]
9-
use crate::{enums::DeleteStatus, schema_v2::customers};
10-
9+
use crate::{
10+
diesel_impl::RequiredFromNullableWithDefault, enums::DeleteStatus, schema_v2::customers,
11+
};
12+
#[cfg(feature = "v2")]
13+
crate::impl_from_required_from_nullable_with_default!(DeleteStatus);
1114
#[cfg(feature = "v1")]
1215
#[derive(
1316
Clone, Debug, router_derive::DebugAsDisplay, serde::Deserialize, serde::Serialize, Insertable,
@@ -164,6 +167,7 @@ pub struct Customer {
164167
pub merchant_reference_id: Option<common_utils::id_type::CustomerId>,
165168
pub default_billing_address: Option<Encryption>,
166169
pub default_shipping_address: Option<Encryption>,
170+
#[diesel(deserialize_as = RequiredFromNullableWithDefault<DeleteStatus>)]
167171
pub status: DeleteStatus,
168172
pub id: common_utils::id_type::GlobalCustomerId,
169173
}

crates/diesel_models/src/lib.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ pub mod user_authentication_method;
6060
pub mod user_key_store;
6161
pub mod user_role;
6262

63-
use diesel_impl::{DieselArray, OptionalDieselArray, RequiredFromNullable};
63+
use diesel_impl::{DieselArray, OptionalDieselArray};
64+
pub use diesel_impl::{RequiredFromNullable, RequiredFromNullableWithDefault};
6465

6566
pub type StorageResult<T> = error_stack::Result<T, errors::DatabaseError>;
6667
pub type PgPooledConn = async_bb8_diesel::Connection<diesel::PgConnection>;
@@ -162,6 +163,13 @@ pub(crate) mod diesel_impl {
162163

163164
pub struct RequiredFromNullableWithDefault<T>(T);
164165

166+
impl<T> RequiredFromNullableWithDefault<T> {
167+
/// Extracts the inner value from the wrapper
168+
pub fn into_inner(self) -> T {
169+
self.0
170+
}
171+
}
172+
165173
impl<T, ST, DB> Queryable<Nullable<ST>, DB> for RequiredFromNullableWithDefault<T>
166174
where
167175
DB: diesel::backend::Backend,
@@ -184,6 +192,34 @@ pub(crate) mod diesel_impl {
184192
}
185193
}
186194

195+
/// Macro to implement From trait for types wrapped in RequiredFromNullable
196+
#[macro_export]
197+
macro_rules! impl_from_required_from_nullable {
198+
($($type:ty),* $(,)?) => {
199+
$(
200+
impl From<$crate::RequiredFromNullable<$type>> for $type {
201+
fn from(wrapper: $crate::RequiredFromNullable<$type>) -> Self {
202+
wrapper.into_inner()
203+
}
204+
}
205+
)*
206+
};
207+
}
208+
209+
/// Macro to implement From trait for types wrapped in RequiredFromNullableWithDefault
210+
#[macro_export]
211+
macro_rules! impl_from_required_from_nullable_with_default {
212+
($($type:ty),* $(,)?) => {
213+
$(
214+
impl From<$crate::RequiredFromNullableWithDefault<$type>> for $type {
215+
fn from(wrapper: $crate::RequiredFromNullableWithDefault<$type>) -> Self {
216+
wrapper.into_inner()
217+
}
218+
}
219+
)*
220+
};
221+
}
222+
187223
pub(crate) mod metrics {
188224
use router_env::{counter_metric, global_meter, histogram_metric_f64};
189225

crates/diesel_models/src/merchant_connector_account.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ impl MerchantConnectorAccount {
6464
}
6565
}
6666

67+
#[cfg(feature = "v2")]
68+
use crate::RequiredFromNullable;
69+
#[cfg(feature = "v2")]
70+
impl From<RequiredFromNullable<id_type::ProfileId>> for id_type::ProfileId {
71+
fn from(wrapper: RequiredFromNullable<id_type::ProfileId>) -> Self {
72+
wrapper.into_inner()
73+
}
74+
}
75+
6776
#[cfg(feature = "v2")]
6877
#[derive(
6978
Clone,
@@ -91,6 +100,7 @@ pub struct MerchantConnectorAccount {
91100
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
92101
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
93102
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
103+
#[diesel(deserialize_as = RequiredFromNullable<id_type::ProfileId>)]
94104
pub profile_id: id_type::ProfileId,
95105
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
96106
pub applepay_verified_domains: Option<Vec<String>>,

crates/diesel_models/src/payment_attempt.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ use crate::enums as storage_enums;
1616
use crate::schema::payment_attempt;
1717
#[cfg(feature = "v2")]
1818
use crate::schema_v2::payment_attempt;
19-
19+
crate::impl_from_required_from_nullable!(
20+
storage_enums::AuthenticationType,
21+
MinorUnit,
22+
storage_enums::PaymentMethod
23+
);
2024
common_utils::impl_to_sql_from_sql_json!(ConnectorMandateReferenceId);
2125
#[derive(
2226
Clone, Debug, serde::Deserialize, serde::Serialize, Eq, PartialEq, diesel::AsExpression,
@@ -35,6 +39,8 @@ impl ConnectorMandateReferenceId {
3539
}
3640
}
3741

42+
use crate::RequiredFromNullable;
43+
3844
#[cfg(feature = "v2")]
3945
#[derive(
4046
Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable,
@@ -48,6 +54,7 @@ pub struct PaymentAttempt {
4854
pub error_message: Option<String>,
4955
pub surcharge_amount: Option<MinorUnit>,
5056
pub payment_method_id: Option<id_type::GlobalPaymentMethodId>,
57+
#[diesel(deserialize_as = RequiredFromNullable<storage_enums::AuthenticationType>)]
5158
pub authentication_type: storage_enums::AuthenticationType,
5259
#[serde(with = "common_utils::custom_serde::iso8601")]
5360
pub created_at: PrimitiveDateTime,
@@ -73,6 +80,7 @@ pub struct PaymentAttempt {
7380
pub encoded_data: Option<masking::Secret<String>>,
7481
pub unified_code: Option<String>,
7582
pub unified_message: Option<String>,
83+
#[diesel(deserialize_as = RequiredFromNullable<MinorUnit>)]
7684
pub net_amount: MinorUnit,
7785
pub external_three_ds_authentication_attempted: Option<bool>,
7886
pub authentication_connector: Option<String>,
@@ -94,6 +102,7 @@ pub struct PaymentAttempt {
94102
pub processor_merchant_id: Option<id_type::MerchantId>,
95103
pub created_by: Option<String>,
96104
pub connector_request_reference_id: Option<String>,
105+
#[diesel(deserialize_as = RequiredFromNullable<storage_enums::PaymentMethod>)]
97106
pub payment_method_type_v2: storage_enums::PaymentMethod,
98107
pub connector_payment_id: Option<ConnectorTransactionId>,
99108
pub payment_method_subtype: storage_enums::PaymentMethodType,

crates/diesel_models/src/payment_intent.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ use crate::schema::payment_intent;
1111
use crate::schema_v2::payment_intent;
1212
#[cfg(feature = "v2")]
1313
use crate::types::{FeatureMetadata, OrderDetailsWithAmount};
14-
use crate::{business_profile::PaymentLinkBackgroundImageConfig, enums as storage_enums};
15-
14+
use crate::{
15+
business_profile::PaymentLinkBackgroundImageConfig, enums as storage_enums,
16+
RequiredFromNullable,
17+
};
18+
crate::impl_from_required_from_nullable!(storage_enums::Currency, PrimitiveDateTime);
1619
#[cfg(feature = "v2")]
1720
#[derive(Clone, Debug, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable)]
1821
#[diesel(table_name = payment_intent, primary_key(id), check_for_backend(diesel::pg::Pg))]
1922
pub struct PaymentIntent {
2023
pub merchant_id: common_utils::id_type::MerchantId,
2124
pub status: storage_enums::IntentStatus,
2225
pub amount: MinorUnit,
26+
#[diesel(deserialize_as = RequiredFromNullable<storage_enums::Currency>)]
2327
pub currency: storage_enums::Currency,
2428
pub amount_captured: Option<MinorUnit>,
2529
pub customer_id: Option<common_utils::id_type::GlobalCustomerId>,
@@ -40,12 +44,14 @@ pub struct PaymentIntent {
4044
pub connector_metadata: Option<pii::SecretSerdeValue>,
4145
pub feature_metadata: Option<FeatureMetadata>,
4246
pub attempt_count: i16,
47+
#[diesel(deserialize_as = RequiredFromNullable<common_utils::id_type::ProfileId>)]
4348
pub profile_id: common_utils::id_type::ProfileId,
4449
pub payment_link_id: Option<String>,
4550
pub updated_by: String,
4651
pub surcharge_applicable: Option<bool>,
4752
pub request_incremental_authorization: Option<RequestIncrementalAuthorization>,
4853
pub authorization_count: Option<i32>,
54+
#[diesel(deserialize_as = RequiredFromNullable<PrimitiveDateTime>)]
4955
pub session_expiry: PrimitiveDateTime,
5056
pub request_external_three_ds_authentication: Option<bool>,
5157
pub frm_metadata: Option<pii::SecretSerdeValue>,

crates/diesel_models/src/refund.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ use crate::schema_v2::refund;
1414
#[cfg(feature = "v2")]
1515
use crate::RequiredFromNullable;
1616
#[cfg(feature = "v2")]
17-
impl From<RequiredFromNullable<id_type::RefundReferenceId>> for id_type::RefundReferenceId {
18-
fn from(wrapper: RequiredFromNullable<id_type::RefundReferenceId>) -> Self {
19-
wrapper.into_inner()
20-
}
21-
}
17+
crate::impl_from_required_from_nullable!(id_type::RefundReferenceId);
2218
#[cfg(feature = "v1")]
2319
#[derive(
2420
Clone,

crates/diesel_models/src/schema_v2.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ diesel::table! {
369369
merchant_reference_id -> Nullable<Varchar>,
370370
default_billing_address -> Nullable<Bytea>,
371371
default_shipping_address -> Nullable<Bytea>,
372-
status -> DeleteStatus,
372+
status -> Nullable<DeleteStatus>,
373373
#[max_length = 64]
374374
id -> Varchar,
375375
}
@@ -781,7 +781,7 @@ diesel::table! {
781781
connector_webhook_details -> Nullable<Jsonb>,
782782
frm_config -> Nullable<Array<Nullable<Jsonb>>>,
783783
#[max_length = 64]
784-
profile_id -> Varchar,
784+
profile_id -> Nullable<Varchar>,
785785
applepay_verified_domains -> Nullable<Array<Nullable<Text>>>,
786786
pm_auth_config -> Nullable<Jsonb>,
787787
status -> ConnectorStatus,
@@ -842,7 +842,7 @@ diesel::table! {
842842
surcharge_amount -> Nullable<Int8>,
843843
#[max_length = 64]
844844
payment_method_id -> Nullable<Varchar>,
845-
authentication_type -> AuthenticationType,
845+
authentication_type -> Nullable<AuthenticationType>,
846846
created_at -> Timestamp,
847847
modified_at -> Timestamp,
848848
last_synced -> Nullable<Timestamp>,
@@ -873,7 +873,7 @@ diesel::table! {
873873
unified_code -> Nullable<Varchar>,
874874
#[max_length = 1024]
875875
unified_message -> Nullable<Varchar>,
876-
net_amount -> Int8,
876+
net_amount -> Nullable<Int8>,
877877
external_three_ds_authentication_attempted -> Nullable<Bool>,
878878
#[max_length = 64]
879879
authentication_connector -> Nullable<Varchar>,
@@ -905,7 +905,7 @@ diesel::table! {
905905
created_by -> Nullable<Varchar>,
906906
#[max_length = 255]
907907
connector_request_reference_id -> Nullable<Varchar>,
908-
payment_method_type_v2 -> Varchar,
908+
payment_method_type_v2 -> Nullable<Varchar>,
909909
#[max_length = 128]
910910
connector_payment_id -> Nullable<Varchar>,
911911
#[max_length = 64]
@@ -939,7 +939,7 @@ diesel::table! {
939939
merchant_id -> Varchar,
940940
status -> IntentStatus,
941941
amount -> Int8,
942-
currency -> Currency,
942+
currency -> Nullable<Currency>,
943943
amount_captured -> Nullable<Int8>,
944944
#[max_length = 64]
945945
customer_id -> Nullable<Varchar>,
@@ -960,15 +960,15 @@ diesel::table! {
960960
feature_metadata -> Nullable<Json>,
961961
attempt_count -> Int2,
962962
#[max_length = 64]
963-
profile_id -> Varchar,
963+
profile_id -> Nullable<Varchar>,
964964
#[max_length = 255]
965965
payment_link_id -> Nullable<Varchar>,
966966
#[max_length = 32]
967967
updated_by -> Varchar,
968968
surcharge_applicable -> Nullable<Bool>,
969969
request_incremental_authorization -> Nullable<RequestIncrementalAuthorization>,
970970
authorization_count -> Nullable<Int4>,
971-
session_expiry -> Timestamp,
971+
session_expiry -> Nullable<Timestamp>,
972972
request_external_three_ds_authentication -> Nullable<Bool>,
973973
frm_metadata -> Nullable<Jsonb>,
974974
customer_details -> Nullable<Bytea>,
@@ -1259,7 +1259,7 @@ diesel::table! {
12591259
#[max_length = 64]
12601260
id -> Varchar,
12611261
#[max_length = 64]
1262-
merchant_reference_id -> Varchar,
1262+
merchant_reference_id -> Nullable<Varchar>,
12631263
#[max_length = 64]
12641264
connector_id -> Nullable<Varchar>,
12651265
}

0 commit comments

Comments
 (0)