Commit 30c4be14f6dab92f43af587c5f13771d29f6c74d
1 parent
2e236a7c
fix:【framework】convertor.py 兼容 mall 的转换
Showing
1 changed file
with
8 additions
and
2 deletions
sql/tools/convertor.py
| ... | ... | @@ -52,6 +52,7 @@ def load_and_clean(sql_file: str) -> str: |
| 52 | 52 | REPLACE_PAIR_LIST = ( |
| 53 | 53 | (")\nVALUES ", ") VALUES "), |
| 54 | 54 | (" CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ", " "), |
| 55 | + (" CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ", " "), | |
| 55 | 56 | (" KEY `", " INDEX `"), |
| 56 | 57 | ("UNIQUE INDEX", "UNIQUE KEY"), |
| 57 | 58 | ("b'0'", "'0'"), |
| ... | ... | @@ -61,6 +62,11 @@ def load_and_clean(sql_file: str) -> str: |
| 61 | 62 | content = open(sql_file, encoding="utf-8").read() |
| 62 | 63 | for replace_pair in REPLACE_PAIR_LIST: |
| 63 | 64 | content = content.replace(*replace_pair) |
| 65 | + # 移除索引字段的前缀长度定义,例如: `name`(32) -> `name` | |
| 66 | + # 移除索引定义上的 USING BTREE COMMENT 部分 | |
| 67 | + # 相关 issue:https://t.zsxq.com/96IFc 、https://t.zsxq.com/rC3A3 | |
| 68 | + content = re.sub(r'`([^`]+)`\(\d+\)', r'`\1`', content) | |
| 69 | + content = re.sub(r'\s+USING\s+BTREE\s+COMMENT\s+\'[^\']+\'', '', content) | |
| 64 | 70 | content = re.sub(r"ENGINE.*COMMENT", "COMMENT", content) |
| 65 | 71 | content = re.sub(r"ENGINE.*;", ";", content) |
| 66 | 72 | return content |
| ... | ... | @@ -262,10 +268,10 @@ class Convertor(ABC): |
| 262 | 268 | # 解析注释 |
| 263 | 269 | for column in table_ddl["columns"]: |
| 264 | 270 | column["comment"] = bytes(column["comment"], "utf-8").decode( |
| 265 | - "unicode_escape" | |
| 271 | + r"unicode_escape" | |
| 266 | 272 | )[1:-1] |
| 267 | 273 | table_ddl["comment"] = bytes(table_ddl["comment"], "utf-8").decode( |
| 268 | - "unicode_escape" | |
| 274 | + r"unicode_escape" | |
| 269 | 275 | )[1:-1] |
| 270 | 276 | |
| 271 | 277 | # 为每个表生成个6个基本部分 | ... | ... |