Files
ccdi/docs/reports/implementation/2026-03-23-lsfx-mock-db-env-fix-implementation.md

34 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LSFX Mock 数据库环境变量修复记录
## 本次改动
- 修复 NAS 部署后 `lsfx-mock-server` 未注入员工库连接参数的问题。
- 在根目录 `docker-compose.yml``lsfx-mock-server` 服务中补充:
- `CCDI_DB_HOST`
- `CCDI_DB_PORT`
- `CCDI_DB_NAME`
- `CCDI_DB_USERNAME`
- `CCDI_DB_PASSWORD`
- 在根目录 `.env.example` 中补充对应示例值,便于后续按环境覆盖。
- 新增部署配置测试,保证 Mock 容器必须携带上述数据库参数默认值。
## 根因说明
- `lsfx-mock-server` 在容器内启动时没有 `CCDI_DB_*` 环境变量。
- `config/settings.py` 在容器内无法从主项目配置路径解析出数据库默认值,最终得到空字符串主机名。
- `PyMySQL` 在主机名为空时退化为按 `localhost` 建连,容器内没有本地 MySQL因此上传接口调用员工库时报 `Can't connect to MySQL server on 'localhost'`
## 变更文件
- `docker-compose.yml`
- `.env.example`
- `tests/deploy/test_lsfx_mock_deploy_config.py`
## 验证结果
- `python3 -m pytest tests/deploy -q`
- 重新执行 `bash deploy/deploy-to-nas.sh`
- 容器内读取 `settings.CCDI_DB_HOST`,结果为 `192.168.0.111`
- 容器内执行数据库 `SELECT 1` 成功
- 调用 `POST /watson/api/project/remoteUploadSplitFile` 返回 `200 OK`