refactor(db)!: adopt project-routed pooled databases

Reorganize WNDB by responsibility and remove legacy scheme endpoints.\n\nRoute analysis and time-series access through project pools, preserve transactional realtime replacement, and refresh GIS materialized views after writes.\n\nAdd database architecture documentation, live pooling coverage, API contract updates, and executable container verification.\n\nBREAKING CHANGE: legacy scheme APIs and flat app.native.wndb module imports are removed.
This commit is contained in:
2026-08-25 18:35:05 +08:00
parent fdbcc5c033
commit fa188af0b1
181 changed files with 8446 additions and 33546 deletions
+4 -15
View File
@@ -8,10 +8,10 @@ from datetime import datetime
import app.services.project_info as project_info
from app.api.problem_details import install_problem_details_handlers
from app.api.v1.rest_router import api_router
from app.infra.db.timescaledb.database import db as tsdb
from app.infra.db.postgresql.database import db as pgdb
from app.infra.db.dynamic_manager import project_connection_manager
from app.infra.db.metadb.database import close_metadata_engine
from app.infra.db.timescaledb.sync_pool import close_all_timescale_pools
from app.native.wndb.core.connection import close_all_project_pools
from app.services.tjnetwork import open_project
from app.core.config import settings
@@ -30,26 +30,15 @@ async def lifespan(app: FastAPI):
logger.info("TJWater CloudService is starting...")
logger.info("**********************************************************")
# 初始化数据库连接池
tsdb.init_pool()
pgdb.init_pool()
await tsdb.open()
await pgdb.open()
# 将数据库实例存储到 app.state,供依赖项使用
app.state.db = pgdb
logger.info("Database connection pool initialized and stored in app.state")
if project_info.name:
print(project_info.name)
open_project(project_info.name)
yield
# 清理资源
await tsdb.close()
await pgdb.close()
await project_connection_manager.close_all()
close_all_timescale_pools()
close_all_project_pools()
await close_metadata_engine()
logger.info("Database connections closed")