Skip to content

Commit

Permalink
added migrations and updated by field
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay S authored and Akshay S committed May 14, 2024
1 parent 8ea23dc commit e1bf5ff
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 80 deletions.
8 changes: 4 additions & 4 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ diesel::table! {
address_id -> Nullable<Varchar>,
#[max_length = 64]
default_payment_method_id -> Nullable<Varchar>,
#[max_length = 255]
#[max_length = 64]
updated_by -> Nullable<Varchar>,
}
}
Expand Down Expand Up @@ -591,8 +591,8 @@ diesel::table! {
original_payment_id -> Nullable<Varchar>,
#[max_length = 32]
merchant_connector_id -> Nullable<Varchar>,
#[max_length = 32]
updated_by -> Nullable<Varchar>
#[max_length = 64]
updated_by -> Nullable<Varchar>,
}
}

Expand Down Expand Up @@ -930,7 +930,7 @@ diesel::table! {
network_transaction_id -> Nullable<Varchar>,
#[max_length = 128]
client_secret -> Nullable<Varchar>,
#[max_length = 32]
#[max_length = 64]
updated_by -> Nullable<Varchar>,
payment_method_billing_address -> Nullable<Bytea>,
}
Expand Down
6 changes: 1 addition & 5 deletions crates/router/src/db/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ mod storage {
payment_id: &payment_id,
};
let field = format!("add_{}", address.address_id);
let storage_scheme = decide_storage_scheme::<_,storage_types::Address>(&self,storage_scheme, Op::Update(key, &field, Some((&address).updated_by.as_str()))).await;
let storage_scheme = decide_storage_scheme::<_,storage_types::Address>(&self,storage_scheme, Op::Update(key.clone(), &field, Some((&address).updated_by.as_str()))).await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
address
Expand All @@ -417,10 +417,6 @@ mod storage {
.await
}
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdPaymentId {
merchant_id: &merchant_id,
payment_id: &payment_id,
};
let updated_address = AddressUpdateInternal::from(address_update.clone())
.create_address(address.clone());
let redis_value = serde_json::to_string(&updated_address)
Expand Down
6 changes: 1 addition & 5 deletions crates/router/src/db/customers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,10 @@ mod storage {
customer_id: customer_id.as_str(),
};
let field = format!("cust_{}", customer_id);
let storage_scheme = decide_storage_scheme::<_,diesel_models::Customer>(&self,storage_scheme, Op::Update(key, &field, (&customer).updated_by.as_ref().map(|x| x.as_str()))).await;
let storage_scheme = decide_storage_scheme::<_,diesel_models::Customer>(&self,storage_scheme, Op::Update(key.clone(), &field, (&customer).updated_by.as_ref().map(|x| x.as_str()))).await;
let updated_object = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdCustomerId {
merchant_id: merchant_id.as_str(),
customer_id: customer_id.as_str(),
};
let updated_customer =
diesel_models::CustomerUpdateInternal::from(customer_update.clone())
.apply_changeset(customer.clone());
Expand Down
6 changes: 1 addition & 5 deletions crates/router/src/db/mandate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ mod storage {
mandate_id,
};
let field = format!("mandate_{}", mandate_id);
let storage_scheme = decide_storage_scheme::<_,diesel_models::Mandate>(&self,storage_scheme, Op::Update(key, &field,None)).await;
let storage_scheme = decide_storage_scheme::<_,diesel_models::Mandate>(&self,storage_scheme, Op::Update(key.clone(), &field,(&mandate).updated_by.as_ref().map(|x| x.as_str()))).await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
storage_types::Mandate::update_by_merchant_id_mandate_id(
Expand All @@ -205,10 +205,6 @@ mod storage {
.map_err(|error| report!(errors::StorageError::from(error)))
}
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdMandateId {
merchant_id,
mandate_id,
};
let key_str = key.to_string();

if let diesel_models::MandateUpdate::ConnectorMandateIdUpdate {
Expand Down
6 changes: 1 addition & 5 deletions crates/router/src/db/payment_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ mod storage {
customer_id: &customer_id,
};
let field = format!("payment_method_id_{}", payment_method.payment_method_id);
let storage_scheme = decide_storage_scheme::<_,storage_types::PaymentMethod>(&self,storage_scheme, Op::Update(key, &field, None)).await;
let storage_scheme = decide_storage_scheme::<_,storage_types::PaymentMethod>(&self,storage_scheme, Op::Update(key.clone(), &field, (&payment_method).updated_by.as_ref().map(|x| x.as_str()))).await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
let conn = connection::pg_connection_write(self).await?;
Expand All @@ -297,10 +297,6 @@ mod storage {
.map_err(|error| report!(errors::StorageError::from(error)))
}
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdCustomerId {
merchant_id: &merchant_id,
customer_id: &customer_id,
};
let key_str = key.to_string();

let p_update: PaymentMethodUpdateInternal = payment_method_update.convert_to_payment_method_update(storage_scheme);
Expand Down
6 changes: 1 addition & 5 deletions crates/router/src/db/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ mod storage {
payment_id: &payment_id,
};
let field = format!("pa_{}_ref_{}", &this.attempt_id, &this.refund_id);
let storage_scheme = decide_storage_scheme::<_,storage_types::Refund>(&self,storage_scheme, Op::Update(key, &field,Some(&this.updated_by))).await;
let storage_scheme = decide_storage_scheme::<_,storage_types::Refund>(&self,storage_scheme, Op::Update(key.clone(), &field,Some(&this.updated_by))).await;
match storage_scheme {
enums::MerchantStorageScheme::PostgresOnly => {
let conn = connection::pg_connection_write(self).await?;
Expand All @@ -545,10 +545,6 @@ mod storage {
.map_err(|error| report!(errors::StorageError::from(error)))
}
enums::MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdPaymentId {
merchant_id: &merchant_id,
payment_id: &payment_id,
};
let key_str = key.to_string();
let updated_refund = refund.clone().apply_changeset(this.clone());

Expand Down
6 changes: 1 addition & 5 deletions crates/storage_impl/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,18 +474,14 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
payment_id: &this.payment_id,
};
let field = format!("pa_{}", this.attempt_id);
let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(&self,storage_scheme, Op::Update(key, &field, Some(&this.updated_by))).await;
let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(&self,storage_scheme, Op::Update(key.clone(), &field, Some(&this.updated_by))).await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
.update_payment_attempt_with_attempt_id(this, payment_attempt, storage_scheme)
.await
}
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdPaymentId {
merchant_id: &this.merchant_id,
payment_id: &this.payment_id,
};
let key_str = key.to_string();
let old_connector_transaction_id = &this.connector_transaction_id;
let old_preprocessing_id = &this.preprocessing_step_id;
Expand Down
6 changes: 1 addition & 5 deletions crates/storage_impl/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,14 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
payment_id: &payment_id,
};
let field = format!("pi_{}", this.payment_id);
let storage_scheme = decide_storage_scheme::<_,DieselPaymentIntent>(&self,storage_scheme, Op::Update(key, &field, Some(&this.updated_by))).await;
let storage_scheme = decide_storage_scheme::<_,DieselPaymentIntent>(&self,storage_scheme, Op::Update(key.clone(), &field, Some(&this.updated_by))).await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
.update_payment_intent(this, payment_intent_update, storage_scheme)
.await
}
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdPaymentId {
merchant_id: &merchant_id,
payment_id: &payment_id,
};
let key_str = key.to_string();

let diesel_intent_update = payment_intent_update.to_storage_model();
Expand Down
6 changes: 1 addition & 5 deletions crates/storage_impl/src/payouts/payout_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,14 @@ impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {
payout_attempt_id: &this.payout_id,
};
let field = format!("poa_{}", this.payout_attempt_id);
let storage_scheme = decide_storage_scheme::<_,DieselPayoutAttempt>(&self,storage_scheme, Op::Update(key, &field, None)).await;
let storage_scheme = decide_storage_scheme::<_,DieselPayoutAttempt>(&self,storage_scheme, Op::Update(key.clone(), &field, None)).await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
.update_payout_attempt(this, payout_update, payouts, storage_scheme)
.await
}
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdPayoutAttemptId {
merchant_id: &this.merchant_id,
payout_attempt_id: &this.payout_id,
};
let key_str = key.to_string();

let diesel_payout_update = payout_update.to_storage_model();
Expand Down
6 changes: 1 addition & 5 deletions crates/storage_impl/src/payouts/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,14 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
payout_id: &this.payout_id,
};
let field = format!("po_{}", this.payout_id);
let storage_scheme = decide_storage_scheme::<_,DieselPayouts>(&self,storage_scheme, Op::Update(key, &field,None)).await;
let storage_scheme = decide_storage_scheme::<_,DieselPayouts>(&self,storage_scheme, Op::Update(key.clone(), &field,None)).await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
.update_payout(this, payout_update, payout_attempt, storage_scheme)
.await
}
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdPayoutId {
merchant_id: &this.merchant_id,
payout_id: &this.payout_id,
};
let key_str = key.to_string();

let diesel_payout_update = payout_update.to_storage_model();
Expand Down
62 changes: 31 additions & 31 deletions crates/storage_impl/src/redis/kv_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub trait KvStorePartition {
}

#[allow(unused)]
#[derive(Clone)]
pub enum PartitionKey<'a> {
MerchantIdPaymentId {
merchant_id: &'a str,
Expand Down Expand Up @@ -247,37 +248,36 @@ where
D : de::DeserializeOwned + serde::Serialize + Debug + KvStorePartition + UniqueConstraints + Sync,
T : crate::database::store::DatabaseStore,
{
match operation{
Op::Insert => if store.soft_kill_mode {
MerchantStorageScheme::PostgresOnly
} else{
storage_scheme
},
Op::Find => if store.soft_kill_mode {
MerchantStorageScheme::RedisKv
} else{
storage_scheme
},
Op::Update(partition_key, field, Some(updated_by)) if updated_by == "redis_kv" => if store.soft_kill_mode{
match kv_wrapper::<D,_,_>(
store,
KvOperation::<D>::HGet(field),
partition_key,
)
.await
if store.soft_kill_mode {
let updated_scheme = match operation
{
Ok(_) => MerchantStorageScheme::RedisKv,
Err(_) => MerchantStorageScheme::PostgresOnly
}

} else{
storage_scheme
},
Op::Update(_,_,None) => if store.soft_kill_mode {
MerchantStorageScheme::PostgresOnly
} else{
storage_scheme
},
_ => storage_scheme
Op::Insert => MerchantStorageScheme::PostgresOnly,
Op::Find => MerchantStorageScheme::RedisKv,
Op::Update(partition_key, field, Some(updated_by)) if updated_by == "redis_kv" =>
match kv_wrapper::<D,_,_>(
store,
KvOperation::<D>::HGet(field),
partition_key,
)
.await
{
Ok(_) => MerchantStorageScheme::RedisKv,
Err(_) => MerchantStorageScheme::PostgresOnly
}

,
Op::Update(_,_,None) => MerchantStorageScheme::PostgresOnly, //
_ => storage_scheme
};
if updated_scheme != storage_scheme {
let type_name = std::any::type_name::<D>();
println!("[decide_storage_scheme] output: {} for entity {}", updated_scheme, type_name);
}
updated_scheme
}
else {
storage_scheme
}


}
6 changes: 6 additions & 0 deletions migrations/2024-05-14-092623_add_updated_by_column/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This file should undo anything in `up.sql`
ALTER TABLE payment_method DROP COLUMN IF NOT EXISTS updated_by;

ALTER TABLE mandate DROP COLUMN IF NOT EXISTS updated_by;

ALTER TABLE customers DROP COLUMN IF NOT EXISTS updated_by;
6 changes: 6 additions & 0 deletions migrations/2024-05-14-092623_add_updated_by_column/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Your SQL goes here
ALTER TABLE payment_methods ADD COLUMN IF NOT EXISTS updated_by VARCHAR(64);

ALTER TABLE mandate ADD COLUMN IF NOT EXISTS updated_by VARCHAR(64);

ALTER TABLE customers ADD COLUMN IF NOT EXISTS updated_by VARCHAR(64);

0 comments on commit e1bf5ff

Please sign in to comment.