Skip to content

Commit

Permalink
feat(datasource):add oceanbase support (#1622)
Browse files Browse the repository at this point in the history
Co-authored-by: csunny <cfqsunny@163.com>
Co-authored-by: aries_ckt <916701291@qq.com>
  • Loading branch information
3 people authored Jun 13, 2024
1 parent 58d0878 commit 0541d14
Show file tree
Hide file tree
Showing 37 changed files with 117 additions and 36 deletions.
16 changes: 14 additions & 2 deletions dbgpt/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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__))))
Expand All @@ -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()
Expand Down Expand Up @@ -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)}@"
Expand All @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion dbgpt/app/static/404.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/404/index.html

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

Loading

0 comments on commit 0541d14

Please sign in to comment.