fix(dm+test): v0.11e+ 收尾 - PK 校验矛盾 + sample data 截断
tds 9 bug 复盘 2026-06-27 第 3 轮:
1. dm/_validate.ts: 去掉 '至少 1 个 primaryKey' 校验
- 原因: H 子代理 (B-8) 禁止业务字段 primaryKey=1 + 旧校验强制 primaryKey=1, 矛盾
- 修复: 让 JNPF 自动 f_id 作为物理 PK, 业务唯一性用 unique 约束
- 副作用: 现有 dm 表 (有 PK=1 业务字段) 不受影响 (是创建时校验)
2. test/run.ts: sample data 截断到 20 字符
- 原因: buildSampleData 用 test_${vmodel} (24 字符), 但 varchar(20) 字段超长
- 修复: 用短前缀 t_ + 截断到 20 字符
- 副作用: 仍有 datetime 字段类型不匹配问题 (form jnpfKey 推断),
Phase 4-5 手动 POST 验证 form 真实可用 (tds_connector CRUD PASS)
This commit is contained in:
1 parent
f90d877a47
commit
f4993ee6f4
2 files changed
+17
-9
No files matched your search
@@ -189,14 +189,17 @@ export function validateFields(opts: {
|
||||
return { ok: false, step: 1, stepName: '字段定义', errors }
|
||||
}
|
||||
|
||||
// 镜像 Form.vue:215-216 至少 1 个 primaryKey
|
||||
const hasPrimaryKey = opts.fields.some((f) => !!f.primaryKey)
|
||||
if (!hasPrimaryKey) {
|
||||
errors.push({
|
||||
field: 'fields.primaryKey',
|
||||
message: '请选择一个字段作为主键',
|
||||
})
|
||||
}
|
||||
// v0.11e+ (2026-06-27 tds 复盘): 移除 "至少 1 个 primaryKey" 校验
|
||||
// 原因: JNPF 自动注入 f_id 作为物理 PK (per CLAUDE.md §3 / dm create 自动补 9 系统列 + 2 PK 机制),
|
||||
// 用户不需要 (也不应该) 在 --fields 中指定 primaryKey=1 的业务字段.
|
||||
// 旧校验要求用户至少标 1 个 PK, 但 H 子代理 B-8 修复禁止业务字段 PK, 形成矛盾:
|
||||
// - 旧校验: 用户必须 primaryKey=1 (否则"请选择字段作为主键")
|
||||
// - B-8 校验: 业务字段 primaryKey=1 禁止 (PK 必须留给 f_id)
|
||||
// 结果: dm create 永远 fail.
|
||||
// 修复: 去掉 "至少 1 个 PK" 校验. NMPF 自动 f_id 管 PK, 业务唯一性用 unique 约束或 billRule jnpfKey.
|
||||
// 之前代码 (注释保留作为历史):
|
||||
// const hasPrimaryKey = opts.fields.some((f) => !!f.primaryKey)
|
||||
// if (!hasPrimaryKey) { errors.push({...message: '请选择一个字段作为主键'}) }
|
||||
|
||||
// 镜像 Form.vue:174-209 exist() 字段级 7 项校验
|
||||
const seenFields = new Set<string>()
|
||||
|
||||
@@ -268,7 +268,12 @@ function buildSampleData(fields: Array<{ __vModel__?: string; __config__?: { jnp
|
||||
if (sysKeys.has(key)) continue
|
||||
if (['uploadImg', 'uploadFz', 'uploadFile'].includes(key)) continue
|
||||
if (['input', 'textarea'].includes(key)) {
|
||||
sample[vmodel] = `test_${vmodel}`
|
||||
// v0.11e+ (2026-06-27 tds): 用短前缀 `t_` + vmodel 截断到 20 字符
|
||||
// 之前 `test_${vmodel}` 对 f_connector_type (varchar(20)) 超长 → MySQL truncation 报错.
|
||||
// formData.fields 没有 dataLength 字段 (在 tables[].fields), 简单方案: 短前缀 + 截断.
|
||||
// 截断保留字段名前 17 字符 + 短前缀 (例: t_f_connector_ty).
|
||||
const value = `t_${vmodel}`.slice(0, 20)
|
||||
sample[vmodel] = value
|
||||
continue
|
||||
}
|
||||
if (['inputNumber', 'numInput', 'calculate'].includes(key)) {
|
||||
|
||||
Reference in new issue
Block a user