提交了假数据,不需要

This commit is contained in:
侯欢 2025-12-07 22:07:35 +08:00
parent 04d70ace99
commit 616fe10b02
5 changed files with 8 additions and 31 deletions

View File

@ -16,7 +16,6 @@ RUN python -m pip install --no-cache-dir --upgrade pip -i $PIP_INDEX_URL && \
COPY backend/ ./backend/
COPY frontend/ ./frontend/
COPY config.json ./config.json
COPY seed/ /app/init/
RUN mkdir -p /app/data
VOLUME ["/app/data"]
EXPOSE 57778

View File

@ -27,7 +27,6 @@ docker-compose up -d
.
├── backend/ # Flask API + APScheduler
├── frontend/ # 单页 HTMLTailwind+Chart.js
├── seed/ # 预置数据CSVrevenue.sample.csv构建时复制到 /app/init/
├── data/ # SQLite 数据卷(自动创建/挂载)
├── Dockerfile # 生产镜像(已适配腾讯云)
├── docker-compose.yml # 一键部署
@ -50,9 +49,8 @@ curl -X PUT http://localhost:5000/api/admin/turnover \
```
## 数据预置与迁移
- 首次启动自动导入DB为空时
1. 如果存在 `/app/data/import.csv`,优先导入该文件
2. 否则导入镜像内 `/app/init/revenue.csv`(可将 `seed/revenue.sample.csv` 重命名为 `revenue.csv`
- 首次启动自动导入(开启 `AUTO_IMPORT_ON_START=1` 且 DB为空
- 如果存在 `/app/data/import.csv`(宿主机 `./data/import.csv`),自动导入该文件
- CSV格式
```
date,amount
@ -70,9 +68,7 @@ curl -X PUT http://localhost:5000/api/admin/turnover \
- 基础镜像切换为 `python:3.11-alpine`,构建更快、体积更小
- 依赖安装走腾讯云 PyPI 镜像:`PIP_INDEX_URL=https://mirrors.cloud.tencent.com/pypi/simple`
- 自动数据导入:环境变量 `AUTO_IMPORT_ON_START=1`,启动时按顺序导入
1. `/app/data/import.csv`(宿主机 `./data/import.csv`
2. `/app/init/revenue.csv`(仓库 `seed/revenue.csv`
3. `/app/init/revenue.sample.csv`
- `/app/data/import.csv`(宿主机 `./data/import.csv`
## 生产建议
- 建议使用反向代理Nginx暴露 `5000` 端口,并开启 gzip

View File

@ -321,17 +321,11 @@ def auto_import_csv_on_start():
flag = os.getenv('AUTO_IMPORT_ON_START', '1')
if str(flag) == '0':
return
paths = [
os.path.join("/app", "data", "import.csv"),
os.path.join(os.path.dirname(__file__), "..", "init", "revenue.csv"),
os.path.join(os.path.dirname(__file__), "..", "init", "revenue.sample.csv"),
]
for p in paths:
if os.path.exists(p):
with open(p, "r", encoding="utf-8") as f:
text = f.read()
import_csv_text(text, actor='bootstrap')
break
p = os.path.join("/app", "data", "import.csv")
if os.path.exists(p):
with open(p, "r", encoding="utf-8") as f:
text = f.read()
import_csv_text(text, actor='bootstrap')
def sync_log_to_db():
"""启动时将 app.log 中缺失的数据同步到 DB只同步今天之前"""

View File

@ -1,6 +0,0 @@
date,amount
2025-12-01,12345.67
2025-12-02,11890.12
2025-12-03,13200.00
2025-12-04,11110.50
2025-12-05,14005.88
1 date amount
2 2025-12-01 12345.67
3 2025-12-02 11890.12
4 2025-12-03 13200.00
5 2025-12-04 11110.50
6 2025-12-05 14005.88

View File

@ -1,6 +0,0 @@
date,amount
2025-12-01,12345.67
2025-12-02,11890.12
2025-12-03,13200.00
2025-12-04,11110.50
2025-12-05,14005.88
1 date amount
2 2025-12-01 12345.67
3 2025-12-02 11890.12
4 2025-12-03 13200.00
5 2025-12-04 11110.50
6 2025-12-05 14005.88