Skip to content

♻️ refactor(model): 固化列元数据字段契约 - #98

Merged
ZhaoXingPeng merged 1 commit into
mainfrom
refactor/97-column-metadata-contract
Sep 7, 2026
Merged

♻️ refactor(model): 固化列元数据字段契约#98
ZhaoXingPeng merged 1 commit into
mainfrom
refactor/97-column-metadata-contract

Conversation

@ZhaoXingPeng

@ZhaoXingPeng ZhaoXingPeng commented Sep 7, 2026

Copy link
Copy Markdown
Owner

背景

ColumnInfo 是核心数据模型,但 CodegenAnalyzer._build_table_info 当前先构造对象,再动态挂载 auto_incrementmax_lengthprecisionscale。其中 auto_increment 不在 dataclass 定义内,静态类型检查、序列化和调用方契约都无法发现该字段。

计划

  • auto_increment 纳入 ColumnInfo 的正式字段,默认值保持兼容。
  • 构造 ColumnInfo 时直接传入元数据,不再动态添加属性。
  • 增加模型和 analyzer 回归测试,确认字段在对象和输出字典中稳定存在。

边界

不改变数据库元数据读取逻辑或生成模板语义;这是核心模型类型安全修复。没有性能基准,不预设性能提升。

实现与验证

  • 将列元数据收敛为 ColumnInfo 的正式类型化字段,并由分析器在构造阶段显式传递。
  • 序列化路径直接读取字段,避免动态属性缺失造成契约漂移。
  • PYTHONPATH=src python -m pytest -q tests/unit:640 passed。

uff check src tests scripts 与
uff format --check:通过。

  • 本次未建立可比性能基准,性能数据未测量。

Closes #97

@ZhaoXingPeng

ZhaoXingPeng commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

问题复现:ColumnInfo 原先只声明基础列字段,auto_incrementmax_lengthprecisionscale 由分析器在实例创建后动态挂载。绕过该分析器直接构造列对象时可能缺少这些属性,序列化只能依赖 getattr 兜底,字段契约不稳定。

@ZhaoXingPeng

ZhaoXingPeng commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

实现记录:本次将上述 4 个元数据收敛到 ColumnInfo 正式字段,并在 _build_table_info 构造阶段显式传入;_column_to_dict 改为直接读取字段。新增测试覆盖默认值、显式自增值以及分析器输出中的精度和小数位字段。

@ZhaoXingPeng

ZhaoXingPeng commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

验证记录:PYTHONPATH=src python -m pytest -q tests/unit 结果为 640 passed;ruff check src tests scriptsruff format --check 均通过。本次未建立可比性能基准,性能数据未测量,因此不作性能提升结论。

@ZhaoXingPeng
ZhaoXingPeng merged commit cf03c4b into main Sep 7, 2026
10 checks passed
@ZhaoXingPeng ZhaoXingPeng changed the title ♻️ refactor(model): ?????????? ♻️ refactor(model): 固化列元数据字段契约 Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

♻️ refactor(model): 固化列元数据字段契约

1 participant