From 30c4be14f6dab92f43af587c5f13771d29f6c74d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 24 Nov 2025 15:41:32 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E3=80=90framework=E3=80=91converto?= =?UTF-8?q?r.py=20=E5=85=BC=E5=AE=B9=20mall=20=E7=9A=84=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/tools/convertor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sql/tools/convertor.py b/sql/tools/convertor.py index b54d1337c8..d52a7a73c1 100644 --- a/sql/tools/convertor.py +++ b/sql/tools/convertor.py @@ -52,6 +52,7 @@ def load_and_clean(sql_file: str) -> str: REPLACE_PAIR_LIST = ( (")\nVALUES ", ") VALUES "), (" CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ", " "), + (" CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ", " "), (" KEY `", " INDEX `"), ("UNIQUE INDEX", "UNIQUE KEY"), ("b'0'", "'0'"), @@ -61,6 +62,11 @@ def load_and_clean(sql_file: str) -> str: content = open(sql_file, encoding="utf-8").read() for replace_pair in REPLACE_PAIR_LIST: content = content.replace(*replace_pair) + # 移除索引字段的前缀长度定义,例如: `name`(32) -> `name` + # 移除索引定义上的 USING BTREE COMMENT 部分 + # 相关 issue:https://t.zsxq.com/96IFc 、https://t.zsxq.com/rC3A3 + content = re.sub(r'`([^`]+)`\(\d+\)', r'`\1`', content) + content = re.sub(r'\s+USING\s+BTREE\s+COMMENT\s+\'[^\']+\'', '', content) content = re.sub(r"ENGINE.*COMMENT", "COMMENT", content) content = re.sub(r"ENGINE.*;", ";", content) return content @@ -262,10 +268,10 @@ class Convertor(ABC): # 解析注释 for column in table_ddl["columns"]: column["comment"] = bytes(column["comment"], "utf-8").decode( - "unicode_escape" + r"unicode_escape" )[1:-1] table_ddl["comment"] = bytes(table_ddl["comment"], "utf-8").decode( - "unicode_escape" + r"unicode_escape" )[1:-1] # 为每个表生成个6个基本部分