modifyDataModel 功能描述中写了支持修改模型,但具体action仅支持新增,不支持更新?#928
小T
@cnb.cUF1dEVLwEA(张兴禹) 感谢反馈!你观察得很仔细 👍
你说得对,文档描述与参数定义确实存在不一致:
action 参数仅支持 "create" 一个值这确实是文档的表述不够准确。
我已经记录了这个问题,会推动文档团队进行以下处理:
你可以先通过 manageDataModel 工具(action: "list" / "get")查看和管理已创建的模型。
如有其他疑问,随时可以继续提问!
小T
通过@cloudbase/cli 命令行可以实现对模型的修改,我创建了一个补丁skill,仅供其他开发者参考。
xingyuzhang@macbook lottery-stack-cloudrun % ls skills/cloudbase-model-patch
SKILL.md
---
name: cloudbase-model-patch
description: 通过 pull-modify-push 工作流更新 CloudBase 数据模型。当需要修改已存在的数据模型(添加/删除/修改字段)时使用此 skill 作为 modifyDataModel 的补充。
description_zh: 通过 pull-modify-push 工作流更新 CloudBase 数据模型,支持添加、删除、修改字段
version: 1.0.0
---
# CloudBase 数据模型补丁更新指南
## 何时使用此 Skill
当用户需要**修改已存在的数据模型**时,使用此 skill:
- 添加新字段
- 删除字段
- 修改字段类型或属性
- 重命名字段
## 前置要求
- 已安装 CloudBase CLI 3.0.3+
- 已登录 CloudBase CLI (`tcb login`)
- 项目根目录有 `cloudbaserc.json` 配置文件
## 工作流程
### 1. 拉取现有模型 (Pull)
```bash
# 拉取指定模型
tcb db model pull -n <模型名称>
# 示例:拉取 Animal 模型
tcb db model pull -n Animal
生成的文件:
database-schemas/<模型名>.json - 模型 Schema 定义cloud-models.d.ts - TypeScript 类型定义编辑 database-schemas/<模型名>.json 文件:
添加字段示例:
{
"properties": {
"existingField": {
"type": "string",
"title": "已有字段"
},
"newField": {
"description": "新字段描述",
"type": "number",
"title": "新字段"
}
}
}
支持的字段类型:
| 类型 | 说明 |
|---|---|
string | 字符串 |
number | 数字 |
boolean | 布尔值 |
datetime | 日期时间 |
date | 日期 |
time | 时间 |
x-enum | 枚举 |
x-file | 文件 |
x-image | 图片 |
x-rtf | 富文本 |
同步更新 cloud-models.d.ts 文件:
interface IModal_<模型名> {
existingField?: string
newField?: number
}
# 推送指定模型
tcb db model push -n <模型名称>
# 示例:推送 Animal 模型
tcb db model push -n Animal
交互式确认:
Data model <模型名> already exists, update it? → 输入 YesData models have been imported successfully, publish them? → 输入 Yes# Step 1: 拉取模型
tcb db model pull -n Animal
# Step 2: 修改 database-schemas/Animal.json
# 在 properties 中添加:
# "lifespan": {
# "description": "寿命",
# "type": "number",
# "title": "寿命"
# }
# Step 3: 修改 cloud-models.d.ts
# 在 IModal_Animal 接口中添加:
# lifespan?: number
# Step 4: 推送更新
tcb db model push -n Animal
| 命令 | 说明 |
|---|---|
tcb db model list | 列出所有数据模型 |
tcb db model pull -n <name> | 拉取指定模型 |
tcb db model push -n <name> | 推送指定模型 |
tcb db model pull | 拉取所有模型 |
tcb db model push | 推送所有本地模型 |
_ 开头的系统字段(如 _id, _openid, createdAt 等)解决:确保在项目根目录执行命令,且 database-schemas/<模型名>.json 文件存在
解决:确认已在 push 时选择发布(publish),或在控制台手动发布
解决:参考上方支持的字段类型表,使用正确的类型名称
妲己
问题类型
文档内容错误
文档链接
https://docs.cloudbase.net/ai/cloudbase-ai-toolkit/mcp-tools
问题描述
modifyDataModel
基于Mermaid classDiagram创建或更新数据模型。支持创建新模型和更新现有模型结构。内置异步任务监控,自动轮询直至完成或超时。
参数
参数名 类型 必填 说明
mermaidDiagram string 是 Mermaid classDiagram代码,描述数据模型结构。
action string 操作类型:create=创建新模型 可填写的值: "create";默认值: "create"
publish boolean 是否立即发布模型 默认值: false
dbInstanceType string 数据库实例类型 默认值: "MYSQL"
示例
classDiagram
class Student {
name: string <<姓名>>
age: number = 18 <<年龄>>
gender: x-enum = "男" <<性别>>
classId: string <<班级ID>>
identityId: string <<身份ID>>
course: Course[] <<课程>>
required() ["name"]
unique() ["name"]
enum_gender() ["男", "女"]
display_field() "name"
}
class Class {
className: string <<班级名称>>
display_field() "className"
}
class Course {
name: string <<课程名称>>
students: Student[] <<学生>>
display_field() "name"
}
class Identity {
number: string <<证件号码>>
display_field() "number"
}
截图或补充信息