Skip to content

Commit ff3b9a2

Browse files
prajjwalkumar17Narayanbhat166hyperswitch-bot[bot]
authored
refactor(core): patch file for removal of id from schema (#5398)
Co-authored-by: Narayan Bhat <[email protected]> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Narayan Bhat <[email protected]>
1 parent 8e7de90 commit ff3b9a2

37 files changed

+127
-97
lines changed

crates/common_utils/src/id_type.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ fn get_invalid_input_character(input_string: Cow<'static, str>) -> Option<char>
3636
.find(|char| !is_valid_id_character(char))
3737
}
3838

39-
#[derive(Debug, PartialEq, Serialize, Clone, Eq, Hash)]
39+
#[derive(Debug, PartialEq, Hash, Serialize, Clone, Eq)]
4040
/// A type for alphanumeric ids
4141
pub(crate) struct AlphaNumericId(String);
4242

43-
#[derive(Debug, Deserialize, Serialize, Error, Eq, PartialEq)]
43+
#[derive(Debug, Deserialize, Hash, Serialize, Error, Eq, PartialEq)]
4444
#[error("value `{0}` contains invalid character `{1}`")]
4545
/// The error type for alphanumeric id
4646
pub(crate) struct AlphaNumericIdError(String, char);
@@ -82,7 +82,7 @@ impl AlphaNumericId {
8282
}
8383

8484
/// A common type of id that can be used for reference ids with length constraint
85-
#[derive(Debug, Clone, Serialize, PartialEq, Eq, AsExpression, Hash)]
85+
#[derive(Debug, Clone, Serialize, Hash, PartialEq, Eq, AsExpression)]
8686
#[diesel(sql_type = sql_types::Text)]
8787
pub(crate) struct LengthId<const MAX_LENGTH: u8, const MIN_LENGTH: u8>(AlphaNumericId);
8888

crates/common_utils/src/id_type/customer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
};
1818

1919
/// A type for customer_id that can be used for customer ids
20-
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, AsExpression)]
20+
#[derive(Clone, Serialize, Deserialize, Hash, PartialEq, Eq, AsExpression)]
2121
#[diesel(sql_type = sql_types::Text)]
2222
pub struct CustomerId(
2323
LengthId<MAX_ALLOWED_MERCHANT_REFERENCE_ID_LENGTH, MIN_REQUIRED_MERCHANT_REFERENCE_ID_LENGTH>,

crates/diesel_models/remove_id.patch

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
2+
index 55f8e935b..469ad1d22 100644
3+
--- a/crates/diesel_models/src/schema.rs
4+
+++ b/crates/diesel_models/src/schema.rs
5+
@@ -5,7 +5,6 @@ diesel::table! {
6+
use crate::enums::diesel_exports::*;
7+
8+
address (address_id) {
9+
- id -> Nullable<Int4>,
10+
#[max_length = 64]
11+
address_id -> Varchar,
12+
#[max_length = 128]
13+
@@ -129,7 +128,6 @@ diesel::table! {
14+
use crate::enums::diesel_exports::*;
15+
16+
blocklist (merchant_id, fingerprint_id) {
17+
- id -> Int4,
18+
#[max_length = 64]
19+
merchant_id -> Varchar,
20+
#[max_length = 64]
21+
@@ -284,7 +282,6 @@ diesel::table! {
22+
use crate::enums::diesel_exports::*;
23+
24+
customers (customer_id, merchant_id) {
25+
- id -> Int4,
26+
#[max_length = 64]
27+
customer_id -> Varchar,
28+
#[max_length = 64]
29+
@@ -337,7 +334,6 @@ diesel::table! {
30+
use crate::enums::diesel_exports::*;
31+
32+
dispute (dispute_id) {
33+
- id -> Int4,
34+
#[max_length = 64]
35+
dispute_id -> Varchar,
36+
#[max_length = 255]
37+
@@ -588,7 +584,6 @@ diesel::table! {
38+
use crate::enums::diesel_exports::*;
39+
40+
mandate (mandate_id) {
41+
- id -> Int4,
42+
#[max_length = 64]
43+
mandate_id -> Varchar,
44+
#[max_length = 64]
45+
@@ -634,7 +629,6 @@ diesel::table! {
46+
use crate::enums::diesel_exports::*;
47+
48+
merchant_account (merchant_id) {
49+
- id -> Int4,
50+
#[max_length = 64]
51+
merchant_id -> Varchar,
52+
#[max_length = 255]
53+
@@ -678,7 +672,6 @@ diesel::table! {
54+
use crate::enums::diesel_exports::*;
55+
56+
merchant_connector_account (merchant_connector_id) {
57+
- id -> Int4,
58+
#[max_length = 64]
59+
merchant_id -> Varchar,
60+
#[max_length = 64]
61+
@@ -741,7 +734,6 @@ diesel::table! {
62+
use crate::enums::diesel_exports::*;
63+
64+
payment_attempt (attempt_id, merchant_id) {
65+
- id -> Nullable<Int4>,
66+
#[max_length = 64]
67+
payment_id -> Varchar,
68+
#[max_length = 64]
69+
@@ -832,7 +824,6 @@ diesel::table! {
70+
use crate::enums::diesel_exports::*;
71+
72+
payment_intent (payment_id, merchant_id) {
73+
- id -> Nullable<Int4>,
74+
#[max_length = 64]
75+
payment_id -> Varchar,
76+
#[max_length = 64]
77+
@@ -935,7 +926,6 @@ diesel::table! {
78+
use crate::enums::diesel_exports::*;
79+
80+
payment_methods (payment_method_id) {
81+
- id -> Int4,
82+
#[max_length = 64]
83+
customer_id -> Varchar,
84+
#[max_length = 64]
85+
@@ -1100,7 +1090,6 @@ diesel::table! {
86+
use crate::enums::diesel_exports::*;
87+
88+
refund (merchant_id, refund_id) {
89+
- id -> Int4,
90+
#[max_length = 64]
91+
internal_reference_id -> Varchar,
92+
#[max_length = 64]
93+
@@ -1169,7 +1158,6 @@ diesel::table! {
94+
use crate::enums::diesel_exports::*;
95+
96+
roles (role_id) {
97+
- id -> Int4,
98+
#[max_length = 64]
99+
role_name -> Varchar,
100+
#[max_length = 64]
101+
@@ -1276,7 +1263,6 @@ diesel::table! {
102+
use crate::enums::diesel_exports::*;
103+
104+
users (user_id) {
105+
- id -> Int4,
106+
#[max_length = 64]
107+
user_id -> Varchar,
108+
#[max_length = 255]

crates/diesel_models/src/address.rs

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub struct AddressNew {
3939
#[derive(Clone, Debug, Queryable, Identifiable, Selectable, Serialize, Deserialize)]
4040
#[diesel(table_name = address, primary_key(address_id), check_for_backend(diesel::pg::Pg))]
4141
pub struct Address {
42-
pub id: Option<i32>,
4342
pub address_id: String,
4443
pub city: Option<String>,
4544
pub country: Option<enums::CountryAlpha2>,

crates/diesel_models/src/blocklist.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ pub struct BlocklistNew {
1616
#[derive(
1717
Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Selectable, Deserialize, Serialize,
1818
)]
19-
#[diesel(table_name = blocklist, check_for_backend(diesel::pg::Pg))]
19+
#[diesel(table_name = blocklist, primary_key(merchant_id, fingerprint_id), check_for_backend(diesel::pg::Pg))]
2020
pub struct Blocklist {
21-
#[serde(skip)]
22-
pub id: i32,
2321
pub merchant_id: common_utils::id_type::MerchantId,
2422
pub fingerprint_id: String,
2523
pub data_kind: common_enums::BlocklistDataKind,

crates/diesel_models/src/customers.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ impl CustomerNew {
3333
impl From<CustomerNew> for Customer {
3434
fn from(customer_new: CustomerNew) -> Self {
3535
Self {
36-
id: 0i32,
3736
customer_id: customer_new.customer_id,
3837
merchant_id: customer_new.merchant_id,
3938
name: customer_new.name,
@@ -55,9 +54,8 @@ impl From<CustomerNew> for Customer {
5554
#[derive(
5655
Clone, Debug, Identifiable, Queryable, Selectable, serde::Deserialize, serde::Serialize,
5756
)]
58-
#[diesel(table_name = customers, check_for_backend(diesel::pg::Pg))]
57+
#[diesel(table_name = customers, primary_key(customer_id, merchant_id), check_for_backend(diesel::pg::Pg))]
5958
pub struct Customer {
60-
pub id: i32,
6159
pub customer_id: common_utils::id_type::CustomerId,
6260
pub merchant_id: common_utils::id_type::MerchantId,
6361
pub name: Option<Encryption>,

crates/diesel_models/src/dispute.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ pub struct DisputeNew {
3333
}
3434

3535
#[derive(Clone, Debug, PartialEq, Serialize, Identifiable, Queryable, Selectable)]
36-
#[diesel(table_name = dispute, check_for_backend(diesel::pg::Pg))]
36+
#[diesel(table_name = dispute, primary_key(dispute_id), check_for_backend(diesel::pg::Pg))]
3737
pub struct Dispute {
38-
#[serde(skip_serializing)]
39-
pub id: i32,
4038
pub dispute_id: String,
4139
pub amount: String,
4240
pub currency: String,

crates/diesel_models/src/mandate.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ use crate::{enums as storage_enums, schema::mandate};
99
#[derive(
1010
Clone, Debug, Identifiable, Queryable, Selectable, serde::Serialize, serde::Deserialize,
1111
)]
12-
#[diesel(table_name = mandate, check_for_backend(diesel::pg::Pg))]
12+
#[diesel(table_name = mandate, primary_key(mandate_id), check_for_backend(diesel::pg::Pg))]
1313
pub struct Mandate {
14-
pub id: i32,
1514
pub mandate_id: String,
1615
pub customer_id: common_utils::id_type::CustomerId,
1716
pub merchant_id: common_utils::id_type::MerchantId,
@@ -209,7 +208,6 @@ impl MandateUpdateInternal {
209208
impl From<&MandateNew> for Mandate {
210209
fn from(mandate_new: &MandateNew) -> Self {
211210
Self {
212-
id: 0i32,
213211
mandate_id: mandate_new.mandate_id.clone(),
214212
customer_id: mandate_new.customer_id.clone(),
215213
merchant_id: mandate_new.merchant_id.clone(),

crates/diesel_models/src/merchant_account.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use crate::schema_v2::merchant_account;
2626
)]
2727
#[diesel(table_name = merchant_account, primary_key(merchant_id), check_for_backend(diesel::pg::Pg))]
2828
pub struct MerchantAccount {
29-
pub id: i32,
3029
pub merchant_id: id_type::MerchantId,
3130
pub return_url: Option<String>,
3231
pub enable_payment_response_hash: bool,

crates/diesel_models/src/merchant_connector_account.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ use crate::{enums as storage_enums, schema::merchant_connector_account};
1616
Selectable,
1717
router_derive::DebugAsDisplay,
1818
)]
19-
#[diesel(table_name = merchant_connector_account, check_for_backend(diesel::pg::Pg))]
19+
#[diesel(table_name = merchant_connector_account, primary_key(merchant_connector_id), check_for_backend(diesel::pg::Pg))]
2020
pub struct MerchantConnectorAccount {
21-
pub id: i32,
2221
pub merchant_id: id_type::MerchantId,
2322
pub connector_name: String,
2423
pub connector_account_details: Encryption,

crates/diesel_models/src/payment_attempt.rs

-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ pub struct PaymentAttempt {
8686
)]
8787
#[diesel(table_name = payment_attempt, primary_key(attempt_id, merchant_id), check_for_backend(diesel::pg::Pg))]
8888
pub struct PaymentAttempt {
89-
pub id: Option<i32>,
9089
pub payment_id: String,
9190
pub merchant_id: common_utils::id_type::MerchantId,
9291
pub attempt_id: String,
@@ -1703,7 +1702,6 @@ mod tests {
17031702
#[test]
17041703
fn test_backwards_compatibility() {
17051704
let serialized_payment_attempt = r#"{
1706-
"id": 1,
17071705
"payment_id": "PMT123456789",
17081706
"merchant_id": "M123456789",
17091707
"attempt_id": "ATMPT123456789",

crates/diesel_models/src/payment_intent.rs

-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ pub struct PaymentIntent {
7474
#[derive(Clone, Debug, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable)]
7575
#[diesel(table_name = payment_intent, primary_key(payment_id, merchant_id), check_for_backend(diesel::pg::Pg))]
7676
pub struct PaymentIntent {
77-
pub id: Option<i32>,
7877
pub payment_id: String,
7978
pub merchant_id: common_utils::id_type::MerchantId,
8079
pub status: storage_enums::IntentStatus,
@@ -1027,7 +1026,6 @@ mod tests {
10271026
#[test]
10281027
fn test_backwards_compatibility() {
10291028
let serialized_payment_intent = r#"{
1030-
"id": 123,
10311029
"payment_id": "payment_12345",
10321030
"merchant_id": "merchant_67890",
10331031
"status": "succeeded",

crates/diesel_models/src/payment_method.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use crate::{enums as storage_enums, schema::payment_methods};
1010
#[derive(
1111
Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Selectable, Serialize, Deserialize,
1212
)]
13-
#[diesel(table_name = payment_methods, check_for_backend(diesel::pg::Pg))]
13+
#[diesel(table_name = payment_methods, primary_key(payment_method_id), check_for_backend(diesel::pg::Pg))]
1414
pub struct PaymentMethod {
15-
pub id: i32,
1615
pub customer_id: common_utils::id_type::CustomerId,
1716
pub merchant_id: common_utils::id_type::MerchantId,
1817
pub payment_method_id: String,
@@ -329,7 +328,6 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
329328
impl From<&PaymentMethodNew> for PaymentMethod {
330329
fn from(payment_method_new: &PaymentMethodNew) -> Self {
331330
Self {
332-
id: 0i32,
333331
customer_id: payment_method_new.customer_id.clone(),
334332
merchant_id: payment_method_new.merchant_id.clone(),
335333
payment_method_id: payment_method_new.payment_method_id.clone(),

crates/diesel_models/src/refund.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ use crate::{enums as storage_enums, schema::refund};
1919
serde::Serialize,
2020
serde::Deserialize,
2121
)]
22-
#[diesel(table_name = refund, check_for_backend(diesel::pg::Pg))]
22+
#[diesel(table_name = refund, primary_key(refund_id), check_for_backend(diesel::pg::Pg))]
2323
pub struct Refund {
24-
pub id: i32,
2524
pub internal_reference_id: String,
2625
pub refund_id: String, //merchant_reference id
2726
pub payment_id: String,
@@ -341,7 +340,6 @@ mod tests {
341340
#[test]
342341
fn test_backwards_compatibility() {
343342
let serialized_refund = r#"{
344-
"id": 1,
345343
"internal_reference_id": "internal_ref_123",
346344
"refund_id": "refund_456",
347345
"payment_id": "payment_789",

crates/diesel_models/src/role.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use time::PrimitiveDateTime;
55
use crate::{enums, schema::roles};
66

77
#[derive(Clone, Debug, Identifiable, Queryable, Selectable)]
8-
#[diesel(table_name = roles, check_for_backend(diesel::pg::Pg))]
8+
#[diesel(table_name = roles, primary_key(role_id), check_for_backend(diesel::pg::Pg))]
99
pub struct Role {
10-
pub id: i32,
1110
pub role_name: String,
1211
pub role_id: String,
1312
pub merchant_id: id_type::MerchantId,

0 commit comments

Comments
 (0)