Skip to content

rerefactor(miniapp): Miniapp V2 db schema#13468

Open
chengcheng84 wants to merge 1 commit intoCherryHQ:v2from
chengcheng84:v2-miniapps
Open

rerefactor(miniapp): Miniapp V2 db schema#13468
chengcheng84 wants to merge 1 commit intoCherryHQ:v2from
chengcheng84:v2-miniapps

Conversation

@chengcheng84
Copy link

@chengcheng84 chengcheng84 commented Mar 14, 2026

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.

Release note

None

@chengcheng84 chengcheng84 requested a review from a team March 14, 2026 13:50
@chengcheng84
Copy link
Author

chengcheng84 commented Mar 14, 2026

@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

@EurFelux EurFelux requested a review from GeorgeDong32 March 14, 2026 13:58
@chengcheng84 chengcheng84 changed the title renderer(miniapp): Miniapp V2 db schema rerefactor(miniapp): Miniapp V2 db schema Mar 14, 2026
@DeJeune
Copy link
Collaborator

DeJeune commented Mar 14, 2026

Note

This issue/comment/review was translated by Claude.

We also need to migrate the template data and user data.


Original Content

还需要迁移一下模板数据和用户数据

@DeJeune DeJeune added the v2 label Mar 16, 2026
@DeJeune DeJeune added this to the v2.0.0 milestone Mar 16, 2026
Copy link
Collaborator

@GeorgeDong32 GeorgeDong32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

总体评价

本 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/customminiapp_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.tsconfiguration 字段使用 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_idx
  • miniapp_app_id_idx
  • miniapp_type_idx
  • miniapp_status_type_idx

But the migration has 5 indexes with this additional one. This causes schema-migration inconsistency.

Options:

  1. If this index is needed for pinned-app queries, add it to the schema definition
  2. If it was auto-generated incorrectly, remove it from the migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants