Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): diesel models, domain models and db interface changes for callback_mapper table #6571

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c774c2a
add call_back_mapper table
prasunna09 Nov 14, 2024
c41e062
chore: run formatter
hyperswitch-bot[bot] Nov 14, 2024
e3ed4a7
remove launch json
prasunna09 Nov 14, 2024
9b1056b
Merge branch 'add-call-back-mapper-table' of github.com:juspay/hypers…
prasunna09 Nov 14, 2024
0c4ef49
Merge branch 'main' into add-call-back-mapper-table
prasunna09 Nov 14, 2024
baf137e
fix migration check
prasunna09 Nov 14, 2024
df0e757
fix migration check
prasunna09 Nov 14, 2024
c5b7164
resolve pr comments
prasunna09 Nov 15, 2024
75d929b
chore: run formatter
hyperswitch-bot[bot] Nov 15, 2024
14d20cd
code refactoring
prasunna09 Nov 20, 2024
00545fd
Merge branch 'add-call-back-mapper-table' of github.com:juspay/hypers…
prasunna09 Nov 20, 2024
38ba137
chore: run formatter
hyperswitch-bot[bot] Nov 20, 2024
d7883e6
code refactoring
prasunna09 Nov 20, 2024
a520ad9
Merge main
prasunna09 Nov 20, 2024
92ea722
chore: run formatter
hyperswitch-bot[bot] Nov 20, 2024
401a44b
fix failing checks
prasunna09 Nov 20, 2024
89d675b
Merge branch 'add-call-back-mapper-table' of github.com:juspay/hypers…
prasunna09 Nov 20, 2024
90ea3bd
resolve pr comments
prasunna09 Dec 1, 2024
60d19e0
fix migration schema
prasunna09 Dec 2, 2024
946bac6
Merge branch 'main' into add-call-back-mapper-table
prasunna09 Dec 3, 2024
890373e
resolve pr comments
prasunna09 Dec 4, 2024
610b416
chore: run formatter
hyperswitch-bot[bot] Dec 4, 2024
ea91e56
Merge main
prasunna09 Dec 20, 2024
1fb183f
chore: run formatter
hyperswitch-bot[bot] Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions crates/diesel_models/src/call_back_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use diesel::{Identifiable, Insertable, Queryable, Selectable};
use serde::{self, Deserialize, Serialize};
use serde_json;

use crate::schema::call_back_mapper;

#[derive(
Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Selectable, Serialize, Deserialize,
)]
#[diesel(table_name = call_back_mapper, primary_key(id), check_for_backend(diesel::pg::Pg))]

pub struct CallBackMapper {
pub id: String,
#[serde(rename = "type")]
pub id_type: String,
pub data: serde_json::Value,
prasunna09 marked this conversation as resolved.
Show resolved Hide resolved
pub created_at: time::PrimitiveDateTime,
pub last_modified_at: time::PrimitiveDateTime,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Insertable)]
#[diesel(table_name = call_back_mapper)]
pub struct CallBackMapperNew {
pub id: String,
#[serde(rename = "type")]
pub id_type: String,
pub data: serde_json::Value,
}
1 change: 1 addition & 0 deletions crates/diesel_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod authentication;
pub mod authorization;
pub mod blocklist;
pub mod blocklist_fingerprint;
pub mod call_back_mapper;
pub mod customers;
pub mod dispute;
pub mod enums;
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod authentication;
pub mod authorization;
pub mod blocklist;
pub mod blocklist_fingerprint;
pub mod call_back_mapper;
pub mod customers;
pub mod dashboard_metadata;
pub mod dispute;
Expand Down
24 changes: 24 additions & 0 deletions crates/diesel_models/src/query/call_back_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use diesel::{associations::HasTable, ExpressionMethods};

use super::generics;
use crate::{
call_back_mapper::{CallBackMapper, CallBackMapperNew},
schema::call_back_mapper::dsl,
PgPooledConn, StorageResult,
};

impl CallBackMapperNew {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<CallBackMapper> {
generics::generic_insert(conn, self).await
}
}

impl CallBackMapper {
pub async fn find_by_id(conn: &PgPooledConn, id: String) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::id.eq(id.to_owned()),
)
.await
}
}
17 changes: 17 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ diesel::table! {
}
}

diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

call_back_mapper (id) {
#[max_length = 128]
id -> Varchar,
#[sql_name = "type"]
#[max_length = 64]
id_type -> Varchar,
data -> Jsonb,
created_at -> Timestamp,
last_modified_at -> Timestamp,
}
}

diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;
Expand Down Expand Up @@ -1379,6 +1395,7 @@ diesel::allow_tables_to_appear_in_same_query!(
blocklist_fingerprint,
blocklist_lookup,
business_profile,
call_back_mapper,
captures,
cards_info,
configs,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod blocklist;
pub mod blocklist_fingerprint;
pub mod blocklist_lookup;
pub mod business_profile;
pub mod call_back_mapper;
pub mod capture;
pub mod cards_info;
pub mod configs;
Expand Down
48 changes: 48 additions & 0 deletions crates/router/src/db/call_back_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use error_stack::report;
// use diesel_models::call_back_mapper;
prasunna09 marked this conversation as resolved.
Show resolved Hide resolved
use router_env::{instrument, tracing};

use super::Store;
use crate::{
connection,
core::errors::{self, CustomResult},
types::storage,
};

#[async_trait::async_trait]
pub trait CallBackMapperInterface {
prasunna09 marked this conversation as resolved.
Show resolved Hide resolved
async fn insert_call_back_mapper(
&self,
call_back_mapper: storage::CallBackMapperNew,
) -> CustomResult<storage::CallBackMapper, errors::StorageError>;

async fn find_call_back_mapper_by_id(
&self,
id: String,
) -> CustomResult<storage::CallBackMapper, errors::StorageError>;
}

#[async_trait::async_trait]
impl CallBackMapperInterface for Store {
#[instrument(skip_all)]
async fn insert_call_back_mapper(
&self,
call_back_mapper: storage::CallBackMapperNew,
) -> CustomResult<storage::CallBackMapper, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
call_back_mapper
.insert(&conn)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
}

async fn find_call_back_mapper_by_id(
&self,
id: String,
) -> CustomResult<storage::CallBackMapper, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
storage::CallBackMapper::find_by_id(&conn, id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
}
}
15 changes: 8 additions & 7 deletions crates/router/src/types/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod blocklist;
pub mod blocklist_fingerprint;
pub mod blocklist_lookup;
pub mod business_profile;
pub mod call_back_mapper;
pub mod capture;
pub mod cards_info;
pub mod configs;
Expand Down Expand Up @@ -62,13 +63,13 @@ pub use scheduler::db::process_tracker;

pub use self::{
address::*, api_keys::*, authentication::*, authorization::*, blocklist::*,
blocklist_fingerprint::*, blocklist_lookup::*, business_profile::*, capture::*, cards_info::*,
configs::*, customers::*, dashboard_metadata::*, dispute::*, ephemeral_key::*, events::*,
file::*, fraud_check::*, generic_link::*, gsm::*, locker_mock_up::*, mandate::*,
merchant_account::*, merchant_connector_account::*, merchant_key_store::*, payment_link::*,
payment_method::*, process_tracker::*, refund::*, reverse_lookup::*, role::*,
routing_algorithm::*, unified_translations::*, user::*, user_authentication_method::*,
user_role::*,
blocklist_fingerprint::*, blocklist_lookup::*, business_profile::*, call_back_mapper::*,
capture::*, cards_info::*, configs::*, customers::*, dashboard_metadata::*, dispute::*,
ephemeral_key::*, events::*, file::*, fraud_check::*, generic_link::*, gsm::*,
locker_mock_up::*, mandate::*, merchant_account::*, merchant_connector_account::*,
merchant_key_store::*, payment_link::*, payment_method::*, process_tracker::*, refund::*,
reverse_lookup::*, role::*, routing_algorithm::*, unified_translations::*, user::*,
user_authentication_method::*, user_role::*,
};
use crate::types::api::routing;

Expand Down
1 change: 1 addition & 0 deletions crates/router/src/types/storage/call_back_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use diesel_models::call_back_mapper::{CallBackMapper, CallBackMapperNew};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE IF EXISTS call_back_mapper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Your SQL goes here
CREATE TABLE IF NOT EXISTS call_back_mapper (
prasunna09 marked this conversation as resolved.
Show resolved Hide resolved
id VARCHAR(128) NOT NULL PRIMARY KEY,
type VARCHAR(64) NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What values are stored in the id column: are we generating them or is it being provided from third-party sources?

    1. If it's being provided by third party sources, how do we handle possible collision happening due to the id field?
  2. What sort of values does the type column hold, can they be an enum on the Rust side while being a VARCHAR on the database side?

data JSONB NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now()::TIMESTAMP,
last_modified_at TIMESTAMP NOT NULL DEFAULT now()::TIMESTAMP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid the defaults on the database side, have the application provide the values for these columns always. This would help prevent issues with the timestamps being generated based on the database server's time zone configuration.

);
Loading