Data Model First
Changing the interface takes minutes; changing the data model means migrating everything already stored against it. It's the most expensive rework on the whole chain.
- 某个信息在两个页面显示得不一致,因为它存了两份
- 想加个筛选,发现这个字段当初是拼在一个文本里的
- 界面怎么调都别扭,改了半天发现是数据关系不对
Let the AI build pages directly and it derives data from the surface: if the page shows a customer name, it adds a customer-name field to the project table. Looks fine on one page — until a second page also needs customer info, and the data starts forking.
How to Define It
| 步骤 | 具体做什么 |
|---|---|
| 找名词 | 把内容清单和场景描述里的名词圈出来:项目、客户、改稿记录、对账单 |
| 判断实体 | 能被单独列出来、单独增删改的,就是实体;只是某个实体的属性的,就是字段 |
| 定关系 | 两两问一遍:一个 A 能对应几个 B,一个 B 能对应几个 A |
| 查重复 | 同一个信息如果出现在两个表里,多半该抽成独立实体 |
Signals You Got It Wrong
- The same thing is stored in multiple places. Changing one means syncing several, and sooner or later you miss one. This is the most typical signal.
- Structured content stuffed into a single field. Store "Zhang Ming 138xxxx" as one string, and when you need to search by phone you have to re-parse it.
- A table has a bunch of empty fields nobody uses. It means you forced two different things into one table in the first place.
- Deleting one row triggers a cascade of problems. The relationships weren't defined clearly; after deleting a customer, the projects become orphans.
Soft delete deserves a note here: add a deletion flag to the table instead of actually deleting. Users can recover from mistakes, and linked data won't suddenly snap.
Note for the AI
基于下面这份内容清单和使用场景,先设计数据模型,不要写界面。 内容清单:[粘贴清单] 场景:[谁、在什么时候、做什么] 请输出: 1. 实体列表。每个实体的字段、类型、是否必填、默认值。 2. 实体之间的关系,标明一对一、一对多还是多对多。 多对多请明确指出需要中间表。 3. 逐条检查有没有重复存储:同一个信息是否出现在多个实体里。 有的话说明为什么,或者建议怎么抽出来。 4. 列出你不确定的地方,比如某个字段该属于哪个实体、 某个关系的多少端。逐条问我,不要自己决定。 5. 哪些字段将来可能需要被搜索或筛选,据此说明为什么 不能把它们塞进一个大文本字段里。 另外:所有实体都加 created_at 和软删除标记。 我确认之后再写代码。
Point five prevents a common pitfall. To make the interface easier to write, the AI happily crams several pieces of information into a single field — and you only find out you can't split them apart when you need to filter.
