HOWTO.md 2.26 KB

4-database-schema 使用说明

此目录存放数据库表结构文档。

🚀 快速开始(新人必读)

1. 创建 JSON 数据文件

在 data/ 目录下创建或编辑 JSON 文件(参考下方 schema):

  • common.json — 项目基本信息(project / version / date / allCategories)
  • overview.json — 总览数据(如 ER 图 SVG)
  • M-01.json、M-02.json ... — 每个数据库表一个文件

2. 执行渲染

cd 4-database-schema
python render.py

3. 查看结果

  • overview.html — 数据库表结构总览页
  • M-01-users.html 等 — 各表详情页(含字段、索引、关联关系)

4. 常见工作流

操作 步骤
新增一张表 1. 创建 data/M-XX.json(参考下方 schema)
2. 运行 python render.py
修改字段定义 1. 编辑对应的 M-XX.json 中的 field_rows
2. 运行 python render.py
新增变更记录 1. 在 changelogs[] 追加一条
2. 运行 python render.py

5. 注意事项

  • field_rows / index_rows / relation_rows / relation_svg 需要手写 HTML 表格行
  • changelog_html 由 render.py 自动从 changelogs[] 生成,不需要手写

data/overview.json Schema

{
  "table_count": 4,
  "table_rows": "<tr><td>M-01</td><td>users</td><td>用户表</td><td>存储用户基本信息</td><td>5</td><td>2</td><td><a href=\"M-01-users.html\" class=\"detail-link\">详情 →</a></td></tr>",
  "er_svg": "<svg>...ER 关系图 SVG...</svg>"
}

data/M-XX.json Schema

{
  "id": "M-01",
  "name": "users",
  "fileKey": "users",
  "purpose": "存储用户基本信息",
  "field_count": 5,
  "index_count": 2,
  "related_modules": "关联 F-05",
  "field_rows": "<tr class=\"row-pk\">...</tr>",
  "index_rows": "<tr>...</tr>",
  "relation_svg": "",
  "relation_rows": "",
  "changelogs": [
    {"date": "2026-06-10", "id": "#CHG-004", "type": "modify", "title": "增加 email 唯一索引", "desc": "增加 email 唯一索引", "done": false}
  ]
}

关键说明

  • changelogs[] 替代原来的 changelog_html HTML blob
  • field_rows / index_rows / relation_rows / relation_svg 保留 HTML 格式(表格行数据,非 blob)
  • render.py 自动取 changelogs 最新一条生成 changelog-bar