# Skill: eip4-data-modeling ## 触发场景 - 用户要新建业务实体(表)、给已有表加字段。 - 需要引用列(外键)、主子表结构。 > 调用方式:经 REST(无对应 CLI 子命令),或经 `platform-mcp`(MCP)。非 local 环境需带 `Authorization: Bearer `,取 token 见 `eip4-env-manage`。 ## 端点 建实体:`POST {{EIP4_BASE_URL}}/api/meta/entity` ```json { "tablename": "EIP4AI_DEMO", "name": "演示实体", "attributes": [ {"column": "TITLE", "display": "标题", "type": "string", "length": 200, "mandatory": true}, {"column": "OWNER", "display": "负责人", "type": "reference", "referenceTable": "SYS_USER"} ], "tabletype": 0, "masterTable": "PARENT_TABLE" } ``` - `tablename` 必须 EIP4 前缀,大写,匹配 `[A-Z][A-Z0-9_]{2,40}`。 - `type`:`string | integer | number | date | datetime | boolean | reference`。 - `reference` 必带 `referenceTable`,自动生成 CHAR(36) 外键列指向目标表。 - `tabletype`:`0`=主表 `1`=子表 `2`=中间表;子表用 `masterTable` 指定主表,自动加 `MASTERID` 回链列。 - 标准列(主键/版本/审计时间/操作人)由引擎自动补齐,**不要手传**。 加字段:`POST {{EIP4_BASE_URL}}/api/meta/entity/{table}/attributes`,body 为 `{"attributes":[...]}`。 - ALTER ADD COLUMN 恒可空(有数据的表加 NOT NULL 会失败)。 查询: - `GET {{EIP4_BASE_URL}}/api/meta/entities` — 实体目录(引用列目标表选择)。 - `GET {{EIP4_BASE_URL}}/api/meta/entity/{table}` — 单实体属性(columns + displayColumn)。 - `GET {{EIP4_BASE_URL}}/api/meta/entity-types` — 实体分类。 删除:`DELETE {{EIP4_BASE_URL}}/api/meta/entity/{table}`(仅 EIP4 前缀表)。 ## 命令示例 ```bash curl -X POST {{EIP4_BASE_URL}}/api/meta/entity \ -H "Content-Type: application/json" \ --data-binary @entity.json ``` ## 红线 - 表名必须 EIP4 前缀,DDL 经 CreateTableSqlGuard / AlterTableSqlGuard / DropTableSqlGuard 强制校验。 - 建表/加列/删表只对 EIP4 前缀表;生产表禁碰。 - 不手传标准审计列。