From f4993ee6f4318ed5862bd7dc81a5d525e2ca3601 Mon Sep 17 00:00:00 2001 From: ssw Date: Sat, 27 Jun 2026 10:37:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(dm+test):=20v0.11e+=20=E6=94=B6=E5=B0=BE=20?= =?UTF-8?q?-=20PK=20=E6=A0=A1=E9=AA=8C=E7=9F=9B=E7=9B=BE=20+=20sample=20da?= =?UTF-8?q?ta=20=E6=88=AA=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/commands/dm/_validate.ts | 19 +++++++++++-------- src/commands/test/run.ts | 7 ++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/commands/dm/_validate.ts b/src/commands/dm/_validate.ts index addd198..7f86d39 100644 --- a/src/commands/dm/_validate.ts +++ b/src/commands/dm/_validate.ts @@ -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() diff --git a/src/commands/test/run.ts b/src/commands/test/run.ts index 73d9c36..26370c8 100644 --- a/src/commands/test/run.ts +++ b/src/commands/test/run.ts @@ -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)) {