Commit 4fa523e29c004eae289901868983c47784f84d8e
Committed by
GitHub
Merge pull request #983 from DevDengChao/feat/converter.py
feat: 允许通过参数转换自定义数据库脚本文件
Showing
1 changed file
with
16 additions
and
7 deletions
sql/tools/convertor.py
| ... | ... | @@ -6,12 +6,12 @@ Author: dhb52 (https://gitee.com/dhb52) |
| 6 | 6 | pip install simple-ddl-parser |
| 7 | 7 | |
| 8 | 8 | or with uv |
| 9 | -uv run --with simple-ddl-parser convertor.py postgres > ../postgresql/ruoyi-vue-pro.sql 239ms 四 5/22 21:03:16 2025 | |
| 10 | -uv run --with simple-ddl-parser convertor.py sqlserver > ../sqlserver/ruoyi-vue-pro.sql | |
| 11 | -uv run --with simple-ddl-parser convertor.py kingbase > ../kingbase/ruoyi-vue-pro.sql | |
| 12 | -uv run --with simple-ddl-parser convertor.py opengauss > ../opengauss/ruoyi-vue-pro.sql | |
| 13 | -uv run --with simple-ddl-parser convertor.py oracle > ../oracle/ruoyi-vue-pro.sql | |
| 14 | -uv run --with simple-ddl-parser convertor.py dm8 > ../dm/ruoyi-vue-pro-dm8.sql | |
| 9 | +uv run --with simple-ddl-parser convertor.py postgres ../mysql/ruoyi-vue-pro.sql > ../postgresql/ruoyi-vue-pro.sql | |
| 10 | +uv run --with simple-ddl-parser convertor.py sqlserver ../mysql/ruoyi-vue-pro.sql > ../sqlserver/ruoyi-vue-pro.sql | |
| 11 | +uv run --with simple-ddl-parser convertor.py kingbase ../mysql/ruoyi-vue-pro.sql > ../kingbase/ruoyi-vue-pro.sql | |
| 12 | +uv run --with simple-ddl-parser convertor.py opengauss ../mysql/ruoyi-vue-pro.sql > ../opengauss/ruoyi-vue-pro.sql | |
| 13 | +uv run --with simple-ddl-parser convertor.py oracle ../mysql/ruoyi-vue-pro.sql > ../oracle/ruoyi-vue-pro.sql | |
| 14 | +uv run --with simple-ddl-parser convertor.py dm8 ../mysql/ruoyi-vue-pro.sql > ../dm/ruoyi-vue-pro-dm8.sql | |
| 15 | 15 | """ |
| 16 | 16 | |
| 17 | 17 | import argparse |
| ... | ... | @@ -24,6 +24,9 @@ from typing import Dict, Generator, Optional, Tuple, Union |
| 24 | 24 | |
| 25 | 25 | from simple_ddl_parser import DDLParser |
| 26 | 26 | |
| 27 | +# 避免 Windows 系统使用默认的 GBK 编码 | |
| 28 | +sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf-8', buffering=1) | |
| 29 | + | |
| 27 | 30 | PREAMBLE = """/* |
| 28 | 31 | Yudao Database Transfer Tool |
| 29 | 32 | |
| ... | ... | @@ -919,9 +922,15 @@ def main(): |
| 919 | 922 | help="目标数据库类型", |
| 920 | 923 | choices=["postgres", "oracle", "sqlserver", "dm8", "kingbase", "opengauss"], |
| 921 | 924 | ) |
| 925 | + parser.add_argument( | |
| 926 | + "path", | |
| 927 | + type=str, | |
| 928 | + help="源数据库脚本路径", | |
| 929 | + default="../mysql/ruoyi-vue-pro.sql" | |
| 930 | + ) | |
| 922 | 931 | args = parser.parse_args() |
| 923 | 932 | |
| 924 | - sql_file = pathlib.Path("../mysql/ruoyi-vue-pro.sql").resolve().as_posix() | |
| 933 | + sql_file = pathlib.Path(args.path).resolve().as_posix() | |
| 925 | 934 | convertor = None |
| 926 | 935 | if args.type == "postgres": |
| 927 | 936 | convertor = PostgreSQLConvertor(sql_file) | ... | ... |