Files
X-Agents/teams/web/ddl-edit.md
2026-03-11 14:26:47 +08:00

67 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 后端需求 - DDL 编辑功能
## 问题描述
前端 Database 页面的 Table Mapping 功能已从"字段映射"改为"DDL 编辑"模式。后端需要支持保存和读取 DDL 数据。
## 需求
### 1. 保存 DDL
前端保存时发送 `ddl` 字段而非 `fields` 字段。
请求结构:
```json
{
"name": "数据库名",
"sub_tables": [
{
"parent_table": "users",
"sub_table_name": "用户表",
"sub_table_comment": "用户表",
"ddl": "CREATE TABLE users (...)"
}
]
}
```
### 2. 后端处理
- `CreateSubTableRequest` 已有 `DDL string` 字段(已添加)
- `UpdateSubTableRequest` 已有 `DDL string` 字段(已添加)
- `UpdateDatabaseRequest` 已有 `SubTables []CreateSubTableRequest` 字段(已添加)
### 3. Service 层修改
**sub_table_service.go**
1. `Create` 函数 - 添加 DDL 字段赋值:
```go
info := &model.SubTableInfo{
// ... 现有字段
DDL: req.DDL,
}
```
2. `Update` 函数 - 添加 DDL 更新逻辑:
```go
// 更新 DDL
info.DDL = req.DDL
```
**database_service.go 或 handler**
`Update` 方法中处理 `SubTables` 字段:
- 当前端传入 `sub_tables` 时,需要创建或更新对应的子表记录(包括 DDL
- 遍历 `sub_tables`,调用 `SubTableService.Create``SubTableService.Update`
## 影响范围
- `server/internal/service/sub_table_service.go` - Create/Update 方法
- `server/internal/service/database_service.go` 或 handler - Update 方法处理 SubTables
## 状态
- [x] 前端修改完成
- [x] 后端修改已完成