fix(deploy): split_ddl 改引号感知切分——COMMENT 内分号(llm_usage'记账失败;仅status=...')曾把 CREATE TABLE 拦腰截断致 pipeline-llm 建表整段中止;llm 执行段收敛用 split_ddl

This commit is contained in:
yumoqing 2026-09-07 14:07:44 +08:00
parent 8ede565596
commit 20a6fd8283

View File

@ -205,13 +205,50 @@ CREATE TABLE IF NOT EXISTS pipeline_git_locks (
def split_ddl(ddl): def split_ddl(ddl):
"""按分号分割 DDL,跳过注释行和空语句。""" """按分号分割 DDL,跳过注释行和空语句。
引号感知:单引号字符串内的分号不作为分隔符(实测事故 2026-09-07:
llm_usage 的 COMMENT '记账状态(三态:...;仅status=SUCCEEDED...)' 注释含分号,
裸 split(';') 把 CREATE TABLE 拦腰截断 → 语法错误 → 该模块建表整段中止)。
"""
stmts = [] stmts = []
for raw in ddl.split(';'): cur = []
lines = [l for l in raw.split('\n') if not l.strip().startswith('--')] in_str = False
s = '\n'.join(lines).strip() i = 0
if s: n = len(ddl)
stmts.append(s) while i < n:
ch = ddl[i]
if in_str:
cur.append(ch)
if ch == "'":
# '' 是转义的单引号,仍在串内
if i + 1 < n and ddl[i + 1] == "'":
cur.append("'")
i += 1
else:
in_str = False
elif ch == '\\' and i + 1 < n:
# 反斜杠转义(MySQL 风格)
cur.append(ddl[i + 1])
i += 1
elif ch == "'":
in_str = True
cur.append(ch)
elif ch == ';':
raw = ''.join(cur)
lines = [l for l in raw.split('\n') if not l.strip().startswith('--')]
s = '\n'.join(lines).strip()
if s:
stmts.append(s)
cur = []
else:
cur.append(ch)
i += 1
raw = ''.join(cur)
lines = [l for l in raw.split('\n') if not l.strip().startswith('--')]
s = '\n'.join(lines).strip()
if s:
stmts.append(s)
return stmts return stmts
@ -357,11 +394,9 @@ async def main():
_llm_ddl = '\n'.join( _llm_ddl = '\n'.join(
_l for _l in _f.read().splitlines() if not _l.strip().startswith('--')) _l for _l in _f.read().splitlines() if not _l.strip().startswith('--'))
_n = 0 _n = 0
for _stmt in _llm_ddl.split(';'): for _stmt in split_ddl(_llm_ddl):
_stmt = _stmt.strip() await sor.execute(_stmt, {})
if _stmt: _n += 1
await sor.execute(_stmt, {})
_n += 1
print(f' tables: pipeline-llm ensured ({_n} statements, idempotent)') print(f' tables: pipeline-llm ensured ({_n} statements, idempotent)')
else: else:
print(' WARN: pkgs/pipeline-llm/mysql.ddl.sql not found (skip llm_ tables)') print(' WARN: pkgs/pipeline-llm/mysql.ddl.sql not found (skip llm_ tables)')