Merge pull request #983 from DevDengChao/feat/converter.py
feat: 允许通过参数转换自定义数据库脚本文件
This commit is contained in:
@@ -6,12 +6,12 @@ Author: dhb52 (https://gitee.com/dhb52)
|
|||||||
pip install simple-ddl-parser
|
pip install simple-ddl-parser
|
||||||
|
|
||||||
or with uv
|
or with uv
|
||||||
uv run --with simple-ddl-parser convertor.py postgres > ../postgresql/ruoyi-vue-pro.sql 239ms 四 5/22 21:03:16 2025
|
uv run --with simple-ddl-parser convertor.py postgres ../mysql/ruoyi-vue-pro.sql > ../postgresql/ruoyi-vue-pro.sql
|
||||||
uv run --with simple-ddl-parser convertor.py sqlserver > ../sqlserver/ruoyi-vue-pro.sql
|
uv run --with simple-ddl-parser convertor.py sqlserver ../mysql/ruoyi-vue-pro.sql > ../sqlserver/ruoyi-vue-pro.sql
|
||||||
uv run --with simple-ddl-parser convertor.py kingbase > ../kingbase/ruoyi-vue-pro.sql
|
uv run --with simple-ddl-parser convertor.py kingbase ../mysql/ruoyi-vue-pro.sql > ../kingbase/ruoyi-vue-pro.sql
|
||||||
uv run --with simple-ddl-parser convertor.py opengauss > ../opengauss/ruoyi-vue-pro.sql
|
uv run --with simple-ddl-parser convertor.py opengauss ../mysql/ruoyi-vue-pro.sql > ../opengauss/ruoyi-vue-pro.sql
|
||||||
uv run --with simple-ddl-parser convertor.py oracle > ../oracle/ruoyi-vue-pro.sql
|
uv run --with simple-ddl-parser convertor.py oracle ../mysql/ruoyi-vue-pro.sql > ../oracle/ruoyi-vue-pro.sql
|
||||||
uv run --with simple-ddl-parser convertor.py dm8 > ../dm/ruoyi-vue-pro-dm8.sql
|
uv run --with simple-ddl-parser convertor.py dm8 ../mysql/ruoyi-vue-pro.sql > ../dm/ruoyi-vue-pro-dm8.sql
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
@@ -24,6 +24,9 @@ from typing import Dict, Generator, Optional, Tuple, Union
|
|||||||
|
|
||||||
from simple_ddl_parser import DDLParser
|
from simple_ddl_parser import DDLParser
|
||||||
|
|
||||||
|
# 避免 Windows 系统使用默认的 GBK 编码
|
||||||
|
sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf-8', buffering=1)
|
||||||
|
|
||||||
PREAMBLE = """/*
|
PREAMBLE = """/*
|
||||||
Yudao Database Transfer Tool
|
Yudao Database Transfer Tool
|
||||||
|
|
||||||
@@ -919,9 +922,15 @@ def main():
|
|||||||
help="目标数据库类型",
|
help="目标数据库类型",
|
||||||
choices=["postgres", "oracle", "sqlserver", "dm8", "kingbase", "opengauss"],
|
choices=["postgres", "oracle", "sqlserver", "dm8", "kingbase", "opengauss"],
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"path",
|
||||||
|
type=str,
|
||||||
|
help="源数据库脚本路径",
|
||||||
|
default="../mysql/ruoyi-vue-pro.sql"
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
sql_file = pathlib.Path("../mysql/ruoyi-vue-pro.sql").resolve().as_posix()
|
sql_file = pathlib.Path(args.path).resolve().as_posix()
|
||||||
convertor = None
|
convertor = None
|
||||||
if args.type == "postgres":
|
if args.type == "postgres":
|
||||||
convertor = PostgreSQLConvertor(sql_file)
|
convertor = PostgreSQLConvertor(sql_file)
|
||||||
|
|||||||
Reference in New Issue
Block a user