From 9933c0739afda7edbe343223b75d82887bf8ee97 Mon Sep 17 00:00:00 2001 From: Lxy Date: Sat, 4 Jul 2026 15:48:44 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=88=9B=E5=BB=BA=E5=AE=9E=E6=96=BD?= =?UTF-8?q?=E8=AE=A1=E5=88=92=EF=BC=8C=E6=9A=82=E5=81=9C=E5=9C=A8=20plan-r?= =?UTF-8?q?eady?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-07-04-analysis-storage-refactor.md | 102 ++++++++++++++++++ .../analysis-storage-refactor/.comet.yaml | 4 +- 2 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 docs/superpowers/plans/2026-07-04-analysis-storage-refactor.md diff --git a/docs/superpowers/plans/2026-07-04-analysis-storage-refactor.md b/docs/superpowers/plans/2026-07-04-analysis-storage-refactor.md new file mode 100644 index 0000000..006c55c --- /dev/null +++ b/docs/superpowers/plans/2026-07-04-analysis-storage-refactor.md @@ -0,0 +1,102 @@ +--- +change: analysis-storage-refactor +design-doc: docs/superpowers/specs/2026-07-04-analysis-storage-refactor-design.md +base-ref: 82de2f9 +--- + +# Analysis Storage Refactor - 实施计划 + +> 基于 [Design Doc](docs/superpowers/specs/2026-07-04-analysis-storage-refactor-design.md) 拆分的可执行任务。 +> 目标:将 `futures_analysis.db`(14 张表)迁移到 MySQL,并引入 Redis 缓存层,与行情数据存储策略保持一致。 + +--- + +## 任务总览 + +| # | 任务 | 依赖 | +|---|------|------| +| T1 | 扩展 StorageManager 支持 analysis 表 | - | +| T2 | 创建 analysis_migration.py 迁移脚本 | T1 | +| T3 | 修改 analysis_db.py 使用 StorageManager | T1 | +| T4 | 在 main.py lifespan 中集成迁移和表初始化 | T2, T3 | +| T5 | 编写测试用例 | T1-T4 | + +--- + +## T1: 扩展 StorageManager 支持 analysis 表 + +**文件**: `app/storage_manager.py` + +**任务**: +1. 新增 `get_analysis_record(table_name, record_id)` 方法 +2. 新增 `get_analysis_list(table_name, filters, limit)` 方法 +3. 新增 `save_analysis_record(table_name, data)` 方法 +4. 新增 `delete_analysis_record(table_name, record_id)` 方法 +5. 实现 Redis 缓存逻辑(TTL 根据表类型配置) + +**验收**: +- 方法支持 Redis→MySQL→SQLite 三级降级 +- 缓存键格式:`analysis:{table_name}:{id}` + +--- + +## T2: 创建 analysis_migration.py 迁移脚本 + +**文件**: `app/analysis_migration.py` + +**任务**: +1. 实现 `migrate_analysis_sqlite_to_mysql()` 函数 +2. 检测 MySQL analysis 表是否已有数据 +3. 从 SQLite 读取全部数据 +4. 批量写入 MySQL +5. 记录迁移日志 + +**验收**: +- 幂等性:MySQL 有数据时跳过迁移 +- 迁移失败不影响应用启动 + +--- + +## T3: 修改 analysis_db.py 使用 StorageManager + +**文件**: `app/analysis_db.py` + +**任务**: +1. 修改 `get_analysis_db()` 使用 StorageManager +2. 实现 MySQL 不可用时降级到 SQLite +3. 保持 API 接口不变 + +**验收**: +- API 调用透明切换存储后端 +- 降级时功能正常 + +--- + +## T4: 在 main.py lifespan 中集成 + +**文件**: `app/main.py` + +**任务**: +1. 在 lifespan 中创建 analysis 表(MySQL) +2. 调用迁移函数 +3. 记录启动日志 + +**验收**: +- 启动时自动创建 14 张表 +- 自动迁移 SQLite 数据 + +--- + +## T5: 编写测试用例 + +**文件**: `tests/test_analysis_storage.py` + +**任务**: +1. 测试 Redis 缓存命中场景 +2. 测试 Redis 缓存未命中回源 MySQL +3. 测试 MySQL 不可用降级到 SQLite +4. 测试数据迁移完整性 + +**验收**: +- 所有测试通过 +- 覆盖三级降级场景 diff --git a/openspec/changes/analysis-storage-refactor/.comet.yaml b/openspec/changes/analysis-storage-refactor/.comet.yaml index 5d8ccf1..41e6e04 100644 --- a/openspec/changes/analysis-storage-refactor/.comet.yaml +++ b/openspec/changes/analysis-storage-refactor/.comet.yaml @@ -2,7 +2,7 @@ workflow: full phase: build context_compression: off build_mode: null -build_pause: null +build_pause: plan-ready subagent_dispatch: null tdd_mode: null review_mode: thorough @@ -11,7 +11,7 @@ verify_mode: null auto_transition: true base_ref: 62a95ca design_doc: docs/superpowers/specs/2026-07-04-analysis-storage-refactor-design.md -plan: null +plan: docs/superpowers/plans/2026-07-04-analysis-storage-refactor.md verify_result: null verification_report: null branch_status: null