mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(core): introduce accounts schema for accounts related tables (#7113)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use common_utils::DbConnectionParams;
|
||||
use common_utils::{id_type, DbConnectionParams};
|
||||
use masking::Secret;
|
||||
|
||||
#[derive(Debug, Clone, serde::Deserialize)]
|
||||
@ -34,7 +34,9 @@ impl DbConnectionParams for Database {
|
||||
}
|
||||
|
||||
pub trait TenantConfig: Send + Sync {
|
||||
fn get_tenant_id(&self) -> &id_type::TenantId;
|
||||
fn get_schema(&self) -> &str;
|
||||
fn get_accounts_schema(&self) -> &str;
|
||||
fn get_redis_key_prefix(&self) -> &str;
|
||||
fn get_clickhouse_database(&self) -> &str;
|
||||
}
|
||||
|
||||
@ -20,11 +20,14 @@ pub trait DatabaseStore: Clone + Send + Sync {
|
||||
) -> StorageResult<Self>;
|
||||
fn get_master_pool(&self) -> &PgPool;
|
||||
fn get_replica_pool(&self) -> &PgPool;
|
||||
fn get_accounts_master_pool(&self) -> &PgPool;
|
||||
fn get_accounts_replica_pool(&self) -> &PgPool;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Store {
|
||||
pub master_pool: PgPool,
|
||||
pub accounts_pool: PgPool,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@ -38,6 +41,12 @@ impl DatabaseStore for Store {
|
||||
Ok(Self {
|
||||
master_pool: diesel_make_pg_pool(&config, tenant_config.get_schema(), test_transaction)
|
||||
.await?,
|
||||
accounts_pool: diesel_make_pg_pool(
|
||||
&config,
|
||||
tenant_config.get_accounts_schema(),
|
||||
test_transaction,
|
||||
)
|
||||
.await?,
|
||||
})
|
||||
}
|
||||
|
||||
@ -48,12 +57,22 @@ impl DatabaseStore for Store {
|
||||
fn get_replica_pool(&self) -> &PgPool {
|
||||
&self.master_pool
|
||||
}
|
||||
|
||||
fn get_accounts_master_pool(&self) -> &PgPool {
|
||||
&self.accounts_pool
|
||||
}
|
||||
|
||||
fn get_accounts_replica_pool(&self) -> &PgPool {
|
||||
&self.accounts_pool
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ReplicaStore {
|
||||
pub master_pool: PgPool,
|
||||
pub replica_pool: PgPool,
|
||||
pub accounts_master_pool: PgPool,
|
||||
pub accounts_replica_pool: PgPool,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@ -69,6 +88,13 @@ impl DatabaseStore for ReplicaStore {
|
||||
diesel_make_pg_pool(&master_config, tenant_config.get_schema(), test_transaction)
|
||||
.await
|
||||
.attach_printable("failed to create master pool")?;
|
||||
let accounts_master_pool = diesel_make_pg_pool(
|
||||
&master_config,
|
||||
tenant_config.get_accounts_schema(),
|
||||
test_transaction,
|
||||
)
|
||||
.await
|
||||
.attach_printable("failed to create accounts master pool")?;
|
||||
let replica_pool = diesel_make_pg_pool(
|
||||
&replica_config,
|
||||
tenant_config.get_schema(),
|
||||
@ -76,9 +102,19 @@ impl DatabaseStore for ReplicaStore {
|
||||
)
|
||||
.await
|
||||
.attach_printable("failed to create replica pool")?;
|
||||
|
||||
let accounts_replica_pool = diesel_make_pg_pool(
|
||||
&replica_config,
|
||||
tenant_config.get_accounts_schema(),
|
||||
test_transaction,
|
||||
)
|
||||
.await
|
||||
.attach_printable("failed to create accounts pool")?;
|
||||
Ok(Self {
|
||||
master_pool,
|
||||
replica_pool,
|
||||
accounts_master_pool,
|
||||
accounts_replica_pool,
|
||||
})
|
||||
}
|
||||
|
||||
@ -89,6 +125,14 @@ impl DatabaseStore for ReplicaStore {
|
||||
fn get_replica_pool(&self) -> &PgPool {
|
||||
&self.replica_pool
|
||||
}
|
||||
|
||||
fn get_accounts_master_pool(&self) -> &PgPool {
|
||||
&self.accounts_master_pool
|
||||
}
|
||||
|
||||
fn get_accounts_replica_pool(&self) -> &PgPool {
|
||||
&self.accounts_replica_pool
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn diesel_make_pg_pool(
|
||||
|
||||
@ -86,6 +86,14 @@ where
|
||||
fn get_replica_pool(&self) -> &PgPool {
|
||||
self.db_store.get_replica_pool()
|
||||
}
|
||||
|
||||
fn get_accounts_master_pool(&self) -> &PgPool {
|
||||
self.db_store.get_accounts_master_pool()
|
||||
}
|
||||
|
||||
fn get_accounts_replica_pool(&self) -> &PgPool {
|
||||
self.db_store.get_accounts_replica_pool()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: DatabaseStore> RedisConnInterface for RouterStore<T> {
|
||||
@ -203,6 +211,14 @@ where
|
||||
fn get_replica_pool(&self) -> &PgPool {
|
||||
self.router_store.get_replica_pool()
|
||||
}
|
||||
|
||||
fn get_accounts_master_pool(&self) -> &PgPool {
|
||||
self.router_store.get_accounts_master_pool()
|
||||
}
|
||||
|
||||
fn get_accounts_replica_pool(&self) -> &PgPool {
|
||||
self.router_store.get_accounts_replica_pool()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: DatabaseStore> RedisConnInterface for KVRouterStore<T> {
|
||||
|
||||
Reference in New Issue
Block a user