test: 修正列渲染断言——SQLAlchemy 会对保留字加反引号
Deploy VitePress site to Pages / build (push) Canceled after 0s
Deploy VitePress site to Pages / Deploy (push) Canceled after 0s

monitor_run.trigger 是 MySQL 保留字,渲染出来是 `trigger`。这比之前手写的列清单更正确:
清单里的裸 trigger 会直接语法错误。断言改为剥掉引号后比对列名。
This commit is contained in:
2026-10-07 15:37:08 +08:00
parent d937ff5fe6
commit e608b51210
+6 -1
View File
@@ -34,7 +34,12 @@ def _ddl(column: Column) -> str:
def test_column_renders_as_ddl(column):
ddl = db._column_ddl(column)
assert ddl.startswith(column.name)
# SQLAlchemy back-quotes an identifier only when it has to, so the rendered
# name matches the column's with the quoting stripped -- which is the case for
# reserved words like monitor_run.trigger. That quoting is a feature: the
# hand-kept list this replaced would have emitted bare `trigger` and died on a
# syntax error.
assert ddl.split(" ", 1)[0].strip("`") == column.name
# MySQL refuses AUTO_INCREMENT together with the DEFAULT this helper appends
# to NOT NULL columns.
assert "AUTO_INCREMENT" not in ddl