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:
Hrithikesh
2025-02-14 18:11:06 +05:30
committed by GitHub
parent 0b972e38ab
commit 0ba4ccfc8b
26 changed files with 308 additions and 56 deletions

View File

@ -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;
}

View File

@ -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(

View File

@ -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> {