feat(ai-studio): add image studio persistence layer

This commit is contained in:
chengma
2026-07-11 12:15:58 +08:00
parent 5c01377173
commit 5ada8af2b5
4 changed files with 985 additions and 2 deletions
+6 -2
View File
@@ -3,7 +3,7 @@ id: T-586
title: AI工场数据地基:项目、图片资产、异步任务与终选顺序 SQLite 模型
phase: 7
deps: [T-538]
status: TODO
status: DONE
created: 2026-07-11
---
@@ -40,4 +40,8 @@ created: 2026-07-11
## 执行记录
(完成后记录实现文件、迁移决策与验证结果。)
- 2026-07-11:完成 AI工场 SQLite 数据地基。
- `app/db.py` 增加 `image_studio_projects`、`image_studio_assets`、`image_studio_jobs`、`image_studio_selections` 四张表与索引;沿用现有 `CREATE TABLE IF NOT EXISTS` ad-hoc 迁移风格,历史 DB 启动时自动补表,不影响 `batches/accounts/tasks`。
- 新增 `app/image_studio.py` service 层,封装项目创建/软删除恢复、图片目录计算、资产 CRUD、cmhub job task key/task_id 生命周期、可续查任务列表、主图/详情图终选排序替换;校验 job/终选引用的资产必须属于同一项目。
- 新增 `tests/test_image_studio.py` 覆盖 schema 初始化、项目唯一性、软删除恢复、路径隔离、资产父子关系、任务状态转换、续查查询、终选连续排序与错误路径。
- 验证:在只套用 T-586 diff 的 clean worktree 中运行 `python -m ruff check app tests main.py`、`py -3.10 -m compileall app main.py`、`py -3.10 -m unittest discover -s tests`(343 tests)和 `git diff --check`,全部通过。