From 3943b566bb4007e9d2686a31a59ed9c07f4666c3 Mon Sep 17 00:00:00 2001 From: junjun <752696511@qq.com> Date: Fri, 26 Dec 2025 20:28:31 +0800 Subject: [PATCH] feat: Add table field update functionality --- backend/apps/datasource/api/datasource.py | 5 +++-- backend/apps/datasource/crud/datasource.py | 10 +++++++++- backend/locales/en.json | 3 ++- backend/locales/ko-KR.json | 3 ++- backend/locales/zh-CN.json | 3 ++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/backend/apps/datasource/api/datasource.py b/backend/apps/datasource/api/datasource.py index f5f5f5c4..c17e477e 100644 --- a/backend/apps/datasource/api/datasource.py +++ b/backend/apps/datasource/api/datasource.py @@ -158,8 +158,9 @@ async def get_fields(session: SessionDep, @router.post("/syncFields/{id}", response_model=None, summary=f"{PLACEHOLDER_PREFIX}ds_sync_fields") -async def sync_fields(session: SessionDep, id: int = Path(..., description=f"{PLACEHOLDER_PREFIX}ds_table_id")): - return sync_single_fields(session, id) +async def sync_fields(session: SessionDep, trans: Trans, + id: int = Path(..., description=f"{PLACEHOLDER_PREFIX}ds_table_id")): + return sync_single_fields(session, trans, id) from pydantic import BaseModel diff --git a/backend/apps/datasource/crud/datasource.py b/backend/apps/datasource/crud/datasource.py index 37b7eeed..795add8d 100644 --- a/backend/apps/datasource/crud/datasource.py +++ b/backend/apps/datasource/crud/datasource.py @@ -165,10 +165,18 @@ def execSql(session: SessionDep, id: int, sql: str): return exec_sql(ds, sql, True) -def sync_single_fields(session: SessionDep, id: int): +def sync_single_fields(session: SessionDep, trans: Trans, id: int): table = session.query(CoreTable).filter(CoreTable.id == id).first() ds = session.query(CoreDatasource).filter(CoreDatasource.id == table.ds_id).first() + tables = getTablesByDs(session, ds) + t_name = [] + for _t in tables: + t_name.append(_t.tableName) + + if not table.table_name in t_name: + raise HTTPException(status_code=500, detail=trans('i18n_table_not_exist')) + # sync field fields = getFieldsByDs(session, ds, table.table_name) sync_fields(session, ds, table, fields) diff --git a/backend/locales/en.json b/backend/locales/en.json index 0dbadf55..3ef2d684 100644 --- a/backend/locales/en.json +++ b/backend/locales/en.json @@ -174,5 +174,6 @@ "params_setting": "Parameters Setting", "rules": "Permission Rules", "log_setting": "Login Authentication" - } + }, + "i18n_table_not_exist": "Table not exist" } \ No newline at end of file diff --git a/backend/locales/ko-KR.json b/backend/locales/ko-KR.json index fc4049ef..6b76128d 100644 --- a/backend/locales/ko-KR.json +++ b/backend/locales/ko-KR.json @@ -174,5 +174,6 @@ "params_setting": "매개변수 설정", "rules": "권한 규칙", "log_setting": "로그인 인증" - } + }, + "i18n_table_not_exist": "현재 테이블이 존재하지 않습니다" } \ No newline at end of file diff --git a/backend/locales/zh-CN.json b/backend/locales/zh-CN.json index e92f99d6..51b24bce 100644 --- a/backend/locales/zh-CN.json +++ b/backend/locales/zh-CN.json @@ -174,5 +174,6 @@ "params_setting": "参数设置", "rules": "权限规则", "log_setting": "登录认证" - } + }, + "i18n_table_not_exist": "当前表不存在" } \ No newline at end of file