refactor: align backend layout and supabase infra
Consolidate backend modules/tests under the backend package while syncing Supabase compose/env config and related plans.
This commit is contained in:
@@ -74,21 +74,21 @@
|
||||
|
||||
| File | Changes |
|
||||
|------|---------|
|
||||
| api/src/core/config/settings.py | 扩展日志相关配置模型 |
|
||||
| backend/src/core/config/settings.py | 扩展日志相关配置模型 |
|
||||
|
||||
## Files to Create
|
||||
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| api/src/core/logging/__init__.py | 模块导出与初始化入口 |
|
||||
| api/src/core/logging/config.py | dictConfig 构建与环境配置 |
|
||||
| api/src/core/logging/formatters.py | JSON formatter 与字段规范 |
|
||||
| api/src/core/logging/handlers.py | 文件、控制台、错误 handler |
|
||||
| api/src/core/logging/filters.py | 等级过滤、敏感字段脱敏 |
|
||||
| api/src/core/logging/context.py | contextvars 绑定与获取 |
|
||||
| api/src/core/logging/middleware.py | FastAPI 请求中间件 |
|
||||
| api/src/core/logging/celery.py | Celery 日志信号集成 |
|
||||
| api/src/core/logging/examples.py | 使用示例(可选) |
|
||||
| backend/src/core/logging/__init__.py | 模块导出与初始化入口 |
|
||||
| backend/src/core/logging/config.py | dictConfig 构建与环境配置 |
|
||||
| backend/src/core/logging/formatters.py | JSON formatter 与字段规范 |
|
||||
| backend/src/core/logging/handlers.py | 文件、控制台、错误 handler |
|
||||
| backend/src/core/logging/filters.py | 等级过滤、敏感字段脱敏 |
|
||||
| backend/src/core/logging/context.py | contextvars 绑定与获取 |
|
||||
| backend/src/core/logging/middleware.py | FastAPI 请求中间件 |
|
||||
| backend/src/core/logging/celery.py | Celery 日志信号集成 |
|
||||
| backend/src/core/logging/examples.py | 使用示例(可选) |
|
||||
|
||||
## Dependencies
|
||||
|
||||
@@ -126,6 +126,35 @@ logger.info("user login", extra={"user_id": "u_123"})
|
||||
- **Integration Tests:** FastAPI 中间件注入的 request_id 与错误分离写入
|
||||
- **E2E Tests:** 关键流程触发错误,验证 error 日志输出与轮转
|
||||
|
||||
## Test Database 约定
|
||||
|
||||
### Supabase 组件能力范围
|
||||
|
||||
- Supabase 的 Auth/Storage/Realtime 等组件是独立服务,默认指向同一个主数据库。
|
||||
- 单独创建一个“测试数据库”(Postgres database)并不会自动获得这些组件的能力,除非显式为这些服务配置新的数据库连接。
|
||||
- 因此,“测试数据库”默认只具备纯 Postgres 能力;Supabase 组件能力仍然作用在主数据库上。
|
||||
|
||||
### 对测试的影响
|
||||
|
||||
- **只走直连数据库的测试**(如通过 SQLAlchemy/psycopg 直连)不会受影响。
|
||||
- **依赖 Supabase 组件的测试**(例如通过 Auth/Storage/Realtime API)会仍然落到主数据库,可能导致:
|
||||
- 测试数据污染主库
|
||||
- 并发测试互相干扰
|
||||
- 若需要 Supabase 组件也“指向测试数据库”,需要启动一套独立 Supabase 栈或重新配置各服务连接(通常不建议在同一栈内动态切换)。
|
||||
|
||||
### 环境变量与自动创建
|
||||
|
||||
- 建议为“测试数据库”提供独立环境变量(仅测试环境读取),例如:
|
||||
- `SOCIAL_TEST_DATABASE__HOST`
|
||||
- `SOCIAL_TEST_DATABASE__PORT`
|
||||
- `SOCIAL_TEST_DATABASE__NAME`
|
||||
- `SOCIAL_TEST_DATABASE__USER`
|
||||
- `SOCIAL_TEST_DATABASE__PASSWORD`
|
||||
- 若使用 Docker 启动 Postgres,建议在容器初始化阶段自动创建测试数据库(避免手动创建):
|
||||
- 通过 `docker-entrypoint-initdb.d` 的 init SQL 脚本创建测试数据库与权限
|
||||
- 保证容器重建后自动恢复测试数据库
|
||||
- 若使用独立 Supabase 栈做测试,测试环境变量应指向该栈的数据库与服务端口。
|
||||
|
||||
## Risks & Mitigations
|
||||
|
||||
| Risk | Impact | Likelihood | Mitigation |
|
||||
|
||||
Reference in New Issue
Block a user