From 20a6fd8283612d0d25d07c69e5ac5fcaf87388e8 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 7 Sep 2026 14:07:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20split=5Fddl=20=E6=94=B9=E5=BC=95?= =?UTF-8?q?=E5=8F=B7=E6=84=9F=E7=9F=A5=E5=88=87=E5=88=86=E2=80=94=E2=80=94?= =?UTF-8?q?COMMENT=20=E5=86=85=E5=88=86=E5=8F=B7(llm=5Fusage'=E8=AE=B0?= =?UTF-8?q?=E8=B4=A6=E5=A4=B1=E8=B4=A5;=E4=BB=85status=3D...')=E6=9B=BE?= =?UTF-8?q?=E6=8A=8A=20CREATE=20TABLE=20=E6=8B=A6=E8=85=B0=E6=88=AA?= =?UTF-8?q?=E6=96=AD=E8=87=B4=20pipeline-llm=20=E5=BB=BA=E8=A1=A8=E6=95=B4?= =?UTF-8?q?=E6=AE=B5=E4=B8=AD=E6=AD=A2;llm=20=E6=89=A7=E8=A1=8C=E6=AE=B5?= =?UTF-8?q?=E6=94=B6=E6=95=9B=E7=94=A8=20split=5Fddl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/create_tables.py | 57 ++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/scripts/create_tables.py b/scripts/create_tables.py index 4030b5c..ff41e8d 100644 --- a/scripts/create_tables.py +++ b/scripts/create_tables.py @@ -205,13 +205,50 @@ CREATE TABLE IF NOT EXISTS pipeline_git_locks ( def split_ddl(ddl): - """按分号分割 DDL,跳过注释行和空语句。""" + """按分号分割 DDL,跳过注释行和空语句。 + + 引号感知:单引号字符串内的分号不作为分隔符(实测事故 2026-09-07: + llm_usage 的 COMMENT '记账状态(三态:...;仅status=SUCCEEDED...)' 注释含分号, + 裸 split(';') 把 CREATE TABLE 拦腰截断 → 语法错误 → 该模块建表整段中止)。 + """ stmts = [] - for raw in ddl.split(';'): - lines = [l for l in raw.split('\n') if not l.strip().startswith('--')] - s = '\n'.join(lines).strip() - if s: - stmts.append(s) + cur = [] + in_str = False + i = 0 + n = len(ddl) + 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 @@ -357,11 +394,9 @@ async def main(): _llm_ddl = '\n'.join( _l for _l in _f.read().splitlines() if not _l.strip().startswith('--')) _n = 0 - for _stmt in _llm_ddl.split(';'): - _stmt = _stmt.strip() - if _stmt: - await sor.execute(_stmt, {}) - _n += 1 + for _stmt in split_ddl(_llm_ddl): + await sor.execute(_stmt, {}) + _n += 1 print(f' tables: pipeline-llm ensured ({_n} statements, idempotent)') else: print(' WARN: pkgs/pipeline-llm/mysql.ddl.sql not found (skip llm_ tables)')