Files
16gagent/reflections/2026-06-05-ddl-leakage.md
2026-06-06 10:40:48 +08:00

32 lines
1.4 KiB
Markdown

# Reflection: DDL CONSTRAINT Leakage into TypeScript Interfaces
> Date: 2026-06-05 | Severity: P0 | Recurrence: 1
## Context
Backend Builder Agent (SF-04) — `schema.ts` 生成时 DDL PRIMARY KEY / FOREIGN KEY / CONSTRAINT 行被当作数据列,泄露进 TypeScript interface 定义。
Example: `"PRIMARY KEY (id)"` → parsed as column `PRIMARY` with type `KEY`, `FOREIGN KEY (user_id) REFERENCES users(id)` → parsed as column `FOREIGN` etc.
## Root Cause
DDL parser 没有区分 "column definition" 行和 "constraint" 行。`CREATE TABLE` 语句中的 CONSTRAINT 子句以特殊关键字开头(PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK),不应被解析为列定义。
## Fix
Added `isConstraintLine()` check before parsing each line as a column. Lines starting with `PRIMARY KEY`, `FOREIGN KEY`, `UNIQUE (`, `CHECK (` are skipped in column parsing.
## Pattern Class
**DDL-to-Code Mapping Error** — SQL DDL 的多层结构(column/constraint/index)被扁平化为单一映射时丢失语义。
## Future Trigger
- Any SQL schema → code generation
- Any DDL parser
- Any ORM code generator
## Checklist
- [ ] DDL 解析器必须有 column / constraint / index 三层分离
- [ ] Constraint 行识别:PRIMARY KEY, FOREIGN KEY, UNIQUE (, CHECK (
- [ ] 生成后验证:interface 字段数 ≤ 表列数(不含约束行)
- [ ] 跑 benchmark 验证所有领域 schema 生成正确
## Recurrence Count
1