refactor(storage): route project DSNs and remove legacy backends
This commit is contained in:
@@ -16,6 +16,7 @@ from app.infra.db.metadb.repositories.metadata_repository import (
|
||||
MetadataRepository,
|
||||
ProjectDbRouting,
|
||||
)
|
||||
from app.infra.db.project_routing import ActiveProjectRouting
|
||||
|
||||
DB_ROLE_BIZ_DATA = "biz_data"
|
||||
DB_ROLE_IOT_DATA = "iot_data"
|
||||
@@ -99,6 +100,62 @@ async def get_project_context(
|
||||
return await resolve_project_context(x_project_id, current_user, metadata_repo)
|
||||
|
||||
|
||||
async def get_project_business_routing(
|
||||
ctx: ProjectContext = Depends(get_project_context),
|
||||
metadata_repo: MetadataRepository = Depends(get_metadata_repository),
|
||||
) -> ActiveProjectRouting:
|
||||
return await resolve_project_business_routing(ctx, metadata_repo)
|
||||
|
||||
|
||||
async def resolve_project_business_routing(
|
||||
ctx: ProjectContext,
|
||||
metadata_repo: MetadataRepository,
|
||||
) -> ActiveProjectRouting:
|
||||
business = await _get_project_routing(
|
||||
metadata_repo,
|
||||
ctx.project_id,
|
||||
DB_ROLE_BIZ_DATA,
|
||||
DB_TYPE_POSTGRES,
|
||||
"PostgreSQL",
|
||||
)
|
||||
return ActiveProjectRouting(
|
||||
project_code=ctx.project_code,
|
||||
business_dsn=business.dsn,
|
||||
)
|
||||
|
||||
|
||||
async def get_project_simulation_routing(
|
||||
ctx: ProjectContext = Depends(get_project_context),
|
||||
metadata_repo: MetadataRepository = Depends(get_metadata_repository),
|
||||
) -> ActiveProjectRouting:
|
||||
return await resolve_project_simulation_routing(ctx, metadata_repo)
|
||||
|
||||
|
||||
async def resolve_project_simulation_routing(
|
||||
ctx: ProjectContext,
|
||||
metadata_repo: MetadataRepository,
|
||||
) -> ActiveProjectRouting:
|
||||
business = await _get_project_routing(
|
||||
metadata_repo,
|
||||
ctx.project_id,
|
||||
DB_ROLE_BIZ_DATA,
|
||||
DB_TYPE_POSTGRES,
|
||||
"PostgreSQL",
|
||||
)
|
||||
timescale = await _get_project_routing(
|
||||
metadata_repo,
|
||||
ctx.project_id,
|
||||
DB_ROLE_IOT_DATA,
|
||||
DB_TYPE_TIMESCALE,
|
||||
"TimescaleDB",
|
||||
)
|
||||
return ActiveProjectRouting(
|
||||
project_code=ctx.project_code,
|
||||
business_dsn=business.dsn,
|
||||
timescale_dsn=timescale.dsn,
|
||||
)
|
||||
|
||||
|
||||
async def _get_project_routing(
|
||||
metadata_repo: MetadataRepository,
|
||||
project_id: UUID,
|
||||
|
||||
Reference in New Issue
Block a user