小程序后端接入 talkingq 共享库并新增消息与定位能力

This commit is contained in:
stu2not
2026-04-20 20:07:35 +08:00
parent e7fe92b863
commit 24b1d1025b
22 changed files with 3469 additions and 762 deletions

View File

@@ -12,17 +12,25 @@ if __package__ in (None, ""):
if project_root_str not in sys.path:
sys.path.insert(0, project_root_str)
from app.db import check_db_connection, close_db_engine, init_db_tables
from app.db import (
check_db_connection,
check_shared_schema_tables,
close_db_engine,
init_db_tables,
)
from app.logging_setup import configure_logging
from app.middleware.auth import install_auth_middleware
from app.middleware.request_log import install_request_logging_middleware
from app.routers.auth import router as auth_router
from app.routers.wechat_auth import router as wechat_auth_router
from app.routers.health import router as health_router
from app.routers.messages import router as messages_router
from app.routers.parents import router as parents_router
from app.routers.children import router as children_router
from app.routers.bindings import router as bindings_router
from app.routers.devices import router as devices_router
from app.routers.device_im import router as device_im_router
from app.routers.device_location import router as device_location_router
from app.routers.im import router as im_router
from app.settings import settings
@@ -40,7 +48,25 @@ def create_app() -> FastAPI:
@app.on_event("startup")
def on_startup() -> None:
check_db_connection()
init_db_tables()
if settings.db_auto_init_tables:
init_db_tables()
if settings.uses_shared_talkingq_db:
logger.warning(
"database auto init only creates mini-program tables; shared deployments should use the shared schema migration script",
extra={
"event": "db_shared_auto_init_warning",
"db_name": settings.db_name,
},
)
else:
check_shared_schema_tables()
logger.info(
"database auto init disabled",
extra={
"event": "db_init_skipped",
"db_name": settings.db_name,
},
)
logger.info("application started", extra={"event": "app_start"})
@app.on_event("shutdown")
@@ -52,10 +78,13 @@ def create_app() -> FastAPI:
install_request_logging_middleware(app)
app.include_router(wechat_auth_router)
app.include_router(health_router)
app.include_router(messages_router)
app.include_router(parents_router)
app.include_router(children_router)
app.include_router(bindings_router)
app.include_router(devices_router)
app.include_router(device_im_router)
app.include_router(device_location_router)
app.include_router(im_router)
return app