feat(datasource):add oceanbase support (#1622)

Co-authored-by: csunny <cfqsunny@163.com>
Co-authored-by: aries_ckt <916701291@qq.com>
This commit is contained in:
明天
2024-06-13 15:13:50 +08:00
committed by GitHub
parent 58d08780d6
commit 0541d1494c
37 changed files with 117 additions and 36 deletions

View File

@@ -8,6 +8,7 @@ from typing import Optional
from dbgpt._private.config import Config
from dbgpt.component import SystemApp
from dbgpt.storage import DBType
from dbgpt.util.parameter_utils import BaseParameters
ROOT_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -31,7 +32,6 @@ def async_db_summary(system_app: SystemApp):
def server_init(param: "WebServerParameters", system_app: SystemApp):
# logger.info(f"args: {args}")
# init config
cfg = Config()
@@ -105,13 +105,16 @@ def _initialize_db(
from urllib.parse import quote_plus as urlquote
from dbgpt.configs.model_config import PILOT_PATH
from dbgpt.datasource.rdbms.dialect.oceanbase.ob_dialect import ( # noqa: F401
OBDialect,
)
from dbgpt.storage.metadata.db_manager import initialize_db
CFG = Config()
db_name = CFG.LOCAL_DB_NAME
default_meta_data_path = os.path.join(PILOT_PATH, "meta_data")
os.makedirs(default_meta_data_path, exist_ok=True)
if CFG.LOCAL_DB_TYPE == "mysql":
if CFG.LOCAL_DB_TYPE == DBType.MySQL.value():
db_url = (
f"mysql+pymysql://{quote(CFG.LOCAL_DB_USER)}:"
f"{urlquote(CFG.LOCAL_DB_PASSWORD)}@"
@@ -121,6 +124,15 @@ def _initialize_db(
)
# Try to create database, if failed, will raise exception
_create_mysql_database(db_name, db_url, try_to_create_db)
elif CFG.LOCAL_DB_TYPE == DBType.OceanBase.value():
db_url = (
f"mysql+ob://{quote(CFG.LOCAL_DB_USER)}:"
f"{urlquote(CFG.LOCAL_DB_PASSWORD)}@"
f"{CFG.LOCAL_DB_HOST}:"
f"{str(CFG.LOCAL_DB_PORT)}/"
f"{db_name}?charset=utf8mb4"
)
_create_mysql_database(db_name, db_url, try_to_create_db)
else:
sqlite_db_path = os.path.join(default_meta_data_path, f"{db_name}.db")
db_url = f"sqlite:///{sqlite_db_path}"