diff --git a/backend/apps/system/crud/assistant.py b/backend/apps/system/crud/assistant.py index fddf2247..74d08d61 100644 --- a/backend/apps/system/crud/assistant.py +++ b/backend/apps/system/crud/assistant.py @@ -131,7 +131,7 @@ class AssistantOutDs: def get_db_schema(self, ds_id: int) -> str: ds = self.get_ds(ds_id) schema_str = "" - db_name = ds.schema + db_name = ds.db_schema schema_str += f"【DB_ID】 {db_name}\n【Schema】\n" for table in ds.tables: schema_str += f"# Table: {db_name}.{table.name}" @@ -159,7 +159,9 @@ class AssistantOutDs: if attr in ds_dict: id_marker += str(ds_dict.get(attr, '')) + '--sqlbot--' id = string_to_numeric_hash(id_marker) - return AssistantOutDsSchema(**{**ds_dict, "id": id}) + db_schema = ds_dict.get('schema', ds_dict.get('db_schema', '')) + ds_dict.pop("schema", None) + return AssistantOutDsSchema(**{**ds_dict, "id": id, "db_schema": db_schema}) class AssistantOutDsFactory: @staticmethod @@ -177,12 +179,12 @@ def get_ds_engine(ds: AssistantOutDsSchema) -> Engine: database=ds.dataBase, driver='', extraJdbc=ds.extraParams, - dbSchema=ds.schema or '' + dbSchema=ds.db_schema or '' ) from apps.db.db import get_uri_from_config uri = get_uri_from_config(ds.type, conf) - if ds.type == "pg" and ds.schema: - connect_args.update({"options": f"-c search_path={ds.schema}"}) + if ds.type == "pg" and ds.db_schema: + connect_args.update({"options": f"-c search_path={ds.db_schema}"}) engine = create_engine(uri, connect_args=connect_args, pool_timeout=timeout, pool_size=20, max_overflow=10) return engine \ No newline at end of file diff --git a/backend/apps/system/schemas/system_schema.py b/backend/apps/system/schemas/system_schema.py index 3d2ab410..e6aa54b1 100644 --- a/backend/apps/system/schemas/system_schema.py +++ b/backend/apps/system/schemas/system_schema.py @@ -139,7 +139,7 @@ class AssistantOutDsSchema(AssistantOutDsBase): dataBase: Optional[str] = None user: Optional[str] = None password: Optional[str] = None - schema: Optional[str] = None + db_schema: Optional[str] = None extraParams: Optional[str] = None tables: Optional[list[AssistantTableSchema]] = None \ No newline at end of file