ent-schema-generator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEnt Schema Generator
Ent Schema Generator
将需求输入整理成可直接落地到 的 DB schema 方案,强调可执行性与可审查性。
sphere-layoutConsolidate requirement inputs into a DB schema solution that can be directly implemented in , emphasizing executability and auditability.
sphere-layoutAI-First Workflow
AI-First Workflow
- Gather inputs from all available sources.
- 读取提示词、需求文档()、接口定义(
.md)、现有 schema、service/dao/render 代码。.proto - 如有 demo 行为,先抽取对象、状态流转、关键动作。
- Extract entities and lifecycle.
- 从业务名词与 API 资源抽候选实体。
- 每个实体明确:status/state、关键时间点、关键约束。
- 仅在明确必要时拆表(可选字段组、低频大字段、写热点冲突)。
- Design fields and null strategy.
- schema 与关键字段必须有业务注释。
- 每个字段必须明确 Optional/Nillable/Unique/Immutable/Default。
- 状态字段使用 Ent 原生 ,并设置默认值。
field.Enum - 统一 ;仅在需要软删时添加
created_at/updated_at。deleted_at - 缺失语义优先 ,避免空字符串哨兵。
NULL
- Apply ID policy.
- 默认不在 schema 手写 。
id - 优先使用 ent generator 集中 ID 配置。
- 仅在业务明确需要时手写自定义 ,并说明对 bind/proto 的影响。
id
- Choose relation strategy.
- 关系字段优先弱关联 ID(如 /
user_id)。order_id - many-to-many 优先级固定:relation-entity > array(确认方言支持) > join table > JSON(最后兜底)。
- JSON 不是常规方案,必须写明 typed/array/join table 不可行原因。
- Plan indexes from real query paths.
- 基于真实 list/filter/sort/query 使用路径设计索引。
- 优先主键/唯一、高选择性过滤、分页排序复合索引。
- 避免仅建低基数 status 单列索引(除非有明确收益)。
- Produce Ent + Go implementation guidance.
- Ent 侧优先 ID 字段表达关系,不强制 edge。
- Go 侧给出批量查询方案:收集 IDs -> 去重 -> -> map 回填。
IDIn(...) - IDs 很大时给出 chunk 策略与跨服务 建议。
BatchGet*
- Add evolution and consistency safeguards.
- 读优化可加快照冗余字段(如 name/price snapshot)。
- 优先 typed/array 结构;JSON 只作例外。
- 弱关联场景必须给出 dangling refs 校验点。
- Gather inputs from all available sources.
- Read prompts, requirement documents (), interface definitions (
.md), existing schemas, service/dao/render code..proto - If there is demo behavior, first extract objects, state transitions, and key actions.
- Extract entities and lifecycle.
- Extract candidate entities from business nouns and API resources.
- For each entity, clearly define: status/state, key time points, key constraints.
- Split tables only when clearly necessary (optional field groups, low-frequency large fields, write hot spot conflicts).
- Design fields and null strategy.
- Schemas and key fields must have business comments.
- Each field must clearly specify Optional/Nillable/Unique/Immutable/Default.
- Use Ent's native for status fields and set default values.
field.Enum - Unify ; add
created_at/updated_atonly when soft deletion is required.deleted_at - Prioritize for missing semantics, avoid empty string sentinels.
NULL
- Apply ID policy.
- Do not manually write in the schema by default.
id - Prioritize using the ent generator for centralized ID configuration.
- Manually write custom only when explicitly required by the business, and explain the impact on bind/proto.
id
- Choose relation strategy.
- Prioritize weak association IDs (e.g., /
user_id) for relation fields.order_id - Fixed priority for many-to-many: relation-entity > array (confirm dialect support) > join table > JSON (last resort).
- JSON is not a regular solution; must explain why typed/array/join table is not feasible.
- Plan indexes from real query paths.
- Design indexes based on real list/filter/sort/query usage paths.
- Prioritize primary key/unique, high-selectivity filtering, and composite indexes for pagination and sorting.
- Avoid creating single-column indexes for low-cardinality status unless there is a clear benefit.
- Produce Ent + Go implementation guidance.
- On the Ent side, prioritize expressing relationships with ID fields, do not enforce edges.
- On the Go side, provide batch query solutions: collect IDs -> deduplicate -> -> map backfill.
IDIn(...) - Provide chunking strategies and cross-service recommendations when IDs are large.
BatchGet*
- Add evolution and consistency safeguards.
- For read optimization, allow redundant fields (e.g., name/price snapshot).
- Prioritize typed/array structures; JSON is only an exception.
- For weak association scenarios, must provide dangling refs checkpoints.
Repository Contract (sphere-layout)
Repository Contract (sphere-layout)
必须显式对齐以下生成链路与接入点:
- Ent 生成入口:
cmd/tools/ent/main.go - Bind/Mapper 生成入口:
cmd/tools/bind/main.go - 统一后置命令:
make gen/proto
输出中必须判断并说明:
- :
ent tool config impact/ ent features / autoproto 影响。IDType - :是否需要更新
bind registration impact。createFilesConf - :哪些层要补代码。
render/dao/service touchpoints
Must explicitly align with the following generation links and access points:
- Ent generation entry:
cmd/tools/ent/main.go - Bind/Mapper generation entry:
cmd/tools/bind/main.go - Unified post-command:
make gen/proto
The output must include judgments and explanations for:
- : Impact on
ent tool config impact/ ent features / autoproto.IDType - : Whether
bind registration impactneeds to be updated.createFilesConf - : Which layers need code supplements.
render/dao/service touchpoints
新增实体必改清单
New Entity Mandatory Modification Checklist
如果方案引入新实体,必须逐项检查并在输出中写明:
- 新 schema 文件与字段/索引。
- 中
cmd/tools/bind/main.go注册。createFilesConf - render 层(/
entmap消费点)接入。entbind - DAO 层批量查询 helper 与去重策略。
- service 层分页/查询/映射接入。
- 生成命令执行与变更 diff 消费(entpb/proto/bind/map)。
If the scheme introduces new entities, must check each item and specify in the output:
- New schema files and fields/indexes.
- Registration in in
createFilesConf.cmd/tools/bind/main.go - Integration with the render layer (consumption points for /
entmap).entbind - DAO layer batch query helpers and deduplication strategies.
- Service layer pagination/query/mapping integration.
- Execution of generation commands and consumption of change diffs (entpb/proto/bind/map).
失败处理约束
Failure Handling Constraints
以下情况不允许视为完成:
- 只改 schema,未评估或未说明 bind 注册影响。
- 涉及绑定字段但未补 影响说明(例如
WithIgnoreFields或敏感字段)。created_at/updated_at - 输出缺少 post-change commands 或 generation diff checklist。
The following cases are not considered complete:
- Only modifying the schema without evaluating or explaining the impact on bind registration.
- Not supplementing the impact explanation of when involving bound fields (e.g.,
WithIgnoreFieldsor sensitive fields).created_at/updated_at - Output lacks post-change commands or generation diff checklists.
Output Format
Output Format
使用 。
references/output-template.md最终输出必须包含:
- 11 段结构化内容。
- sphere-layout 生成链路影响说明。
- post-change commands(至少 与测试命令)。
make gen/proto - generation diff checklist。
Use .
references/output-template.mdThe final output must include:
- 11 sections of structured content.
- Explanation of impacts on the sphere-layout generation link.
- Post-change commands (at least and test commands).
make gen/proto - Generation diff checklist.
Resources
Resources
references/best-practices.mdreferences/output-template.mdreferences/go-ent-service-patterns.mdreferences/ent-schema-examples.md
references/best-practices.mdreferences/output-template.mdreferences/go-ent-service-patterns.mdreferences/ent-schema-examples.md
Notes
Notes
- 本 skill 是 AI 推理驱动,不依赖本地脚本自动生成草稿。
- 语言默认中文说明 + 英文技术关键词(命令/类型/API 名不翻译)。
- This skill is driven by AI reasoning and does not rely on local scripts to automatically generate drafts.
- The default language is Chinese explanations + English technical keywords (commands/types/API names are not translated).