rerefactor(miniapp): Miniapp V2 db schema#13468
rerefactor(miniapp): Miniapp V2 db schema#13468chengcheng84 wants to merge 1 commit intoCherryHQ:v2from
Conversation
|
@0xfullex I've completed the initial design for the miniapp data layer. Could you please take a look and see if the direction is correct?Thanks |
13fe4d9 to
70fd062
Compare
|
Note This issue/comment/review was translated by Claude. We also need to migrate the template data and user data. Original Content还需要迁移一下模板数据和用户数据 |
GeorgeDong32
left a comment
There was a problem hiding this comment.
总体评价
本 PR 的数据层架构设计符合 V2 设计文档要求,为后续的 Handler/Service 层实现奠定了良好基础。
✅ 符合 V2 设计文档
| 项目 | 状态 | 说明 |
|---|---|---|
| 数据系统选择 | ✅ | DataApiService 正确 - 用户创建的业务数据,数据丢失影响严重 |
| Schema 命名 | ✅ | 使用 uuidPrimaryKey() 和 createUpdateDeleteTimestamps helpers |
| 软删除模式 | ✅ | deletedAt 字段支持软删除 |
| RESTful API | ✅ | 端点设计合理,包含专用的 /status 端点用于高频操作 |
| Row-to-Entity 转换 | ✅ | 时间戳类型设计正确(DB integer → Entity ISO string,在 Service 层转换) |
✅ 固定/排序/自定义小程序功能支持
- 排序:
sortOrder字段 +miniapp_status_sort_idx索引支持高效排序查询 - 固定:
status字段包含pinned状态,结合索引支持快速筛选 - 自定义:
type字段区分default/custom,miniapp_type_idx支持类型筛选 - 复合查询:
miniapp_status_type_idx支持 status + type 组合查询
⚠️ 建议确认
Schema 与迁移不同步 (见内联评论): miniapp_pinned_idx 出现在迁移文件中但未在 schema 中定义,请确认是否需要同步。
📝 待后续 PR 处理
- Handler 层实现 (API 路由处理)
- Service 层实现 (业务逻辑 + Row-to-Entity 转换)
- Repository 层实现 (数据库操作封装)
类型安全建议
packages/shared/data/types/miniapp.ts 中 configuration 字段使用 Record<string, any>,建议改为 unknown 以获得更严格的类型检查,在 Service 层进行类型验证。
| CREATE INDEX `miniapp_status_sort_idx` ON `miniapp` (`status`,`sort_order`);--> statement-breakpoint | ||
| CREATE INDEX `miniapp_app_id_idx` ON `miniapp` (`app_id`);--> statement-breakpoint | ||
| CREATE INDEX `miniapp_type_idx` ON `miniapp` (`type`);--> statement-breakpoint | ||
| CREATE INDEX `miniapp_pinned_idx` ON `miniapp` (`status`,`sort_order`);--> statement-breakpoint |
There was a problem hiding this comment.
This index (miniapp_pinned_idx) is present in the migration but not defined in the schema (src/main/data/db/schemas/miniapp.ts).
The schema defines 4 indexes:
miniapp_status_sort_idxminiapp_app_id_idxminiapp_type_idxminiapp_status_type_idx
But the migration has 5 indexes with this additional one. This causes schema-migration inconsistency.
Options:
- If this index is needed for pinned-app queries, add it to the schema definition
- If it was auto-generated incorrectly, remove it from the migration
What this PR does
Before this PR:
No unified data layer exists for miniapps
After this PR:
Adds the complete v2 foundation for the miniapp management system
Why we need it and why it was done in this way
This is the data layer foundation that Phase 2 (services, handlers, UI) builds on. Splitting into phases keeps PRs reviewable and allows early validation of the schema design.
Breaking changes
None. This is purely additive — new tables, new types, no changes to existing functionality.
Special notes for your reviewer
None
Checklist
This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.
/gh-pr-review,gh pr diff, or GitHub UI) before requesting review from othersRelease note