diff --git a/backend/apps/datasource/api/datasource.py b/backend/apps/datasource/api/datasource.py index 6849da36..1fbca788 100644 --- a/backend/apps/datasource/api/datasource.py +++ b/backend/apps/datasource/api/datasource.py @@ -17,7 +17,7 @@ from common.utils.utils import SQLBotLogUtil from ..crud.datasource import get_datasource_list, check_status, create_ds, update_ds, delete_ds, getTables, getFields, \ execSql, update_table_and_fields, getTablesByDs, chooseTables, preview, updateTable, updateField, get_ds, fieldEnum, \ - check_status_by_id + check_status_by_id, sync_single_fields from ..crud.field import get_fields_by_table_id from ..crud.table import get_tables_by_ds_id from ..models.datasource import CoreDatasource, CreateDatasource, TableObj, CoreTable, CoreField, FieldObj @@ -134,6 +134,11 @@ async def get_fields(session: SessionDep, id: int, table_name: str): return getFields(session, id, table_name) +@router.post("/syncFields/{id}") +async def sync_fields(session: SessionDep, id: int): + return sync_single_fields(session, id) + + from pydantic import BaseModel diff --git a/backend/apps/datasource/crud/datasource.py b/backend/apps/datasource/crud/datasource.py index 10e68e7a..153e5088 100644 --- a/backend/apps/datasource/crud/datasource.py +++ b/backend/apps/datasource/crud/datasource.py @@ -109,12 +109,14 @@ def update_ds(session: SessionDep, trans: Trans, user: CurrentUser, ds: CoreData run_save_ds_embeddings([ds.id]) return ds -def update_ds_recommended_config(session: SessionDep,datasource_id: int, recommended_config:int): + +def update_ds_recommended_config(session: SessionDep, datasource_id: int, recommended_config: int): record = session.exec(select(CoreDatasource).where(CoreDatasource.id == datasource_id)).first() record.recommended_config = recommended_config session.add(record) session.commit() + def delete_ds(session: SessionDep, id: int): term = session.exec(select(CoreDatasource).where(CoreDatasource.id == id)).first() if term.type == "excel": @@ -163,6 +165,19 @@ def execSql(session: SessionDep, id: int, sql: str): return exec_sql(ds, sql, True) +def sync_single_fields(session: SessionDep, id: int): + table = session.query(CoreTable).filter(CoreTable.id == id).first() + ds = session.query(CoreDatasource).filter(CoreDatasource.id == table.ds_id).first() + + # sync field + fields = getFieldsByDs(session, ds, table.table_name) + sync_fields(session, ds, table, fields) + + # do table embedding + run_save_table_embeddings([table.id]) + run_save_ds_embeddings([ds.id]) + + def sync_table(session: SessionDep, ds: CoreDatasource, tables: List[CoreTable]): id_list = [] for item in tables: diff --git a/frontend/src/api/datasource.ts b/frontend/src/api/datasource.ts index 802f9269..5a66e985 100644 --- a/frontend/src/api/datasource.ts +++ b/frontend/src/api/datasource.ts @@ -26,4 +26,5 @@ export const datasourceApi = { getDs: (id: number) => request.post(`/datasource/get/${id}`), cancelRequests: () => request.cancelRequests(), getSchema: (data: any) => request.post('/datasource/getSchemaByConf', data), + syncFields: (id: number) => request.post(`/datasource/syncFields/${id}`), } diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json index 32928006..b9cf2c99 100644 --- a/frontend/src/i18n/en.json +++ b/frontend/src/i18n/en.json @@ -335,7 +335,8 @@ }, "timeout": "Timeout(second)", "address": "Address" - } + }, + "sync_fields": "Sync Fields" }, "datasource": { "recommended_repetitive_tips": "Duplicate questions exist", diff --git a/frontend/src/i18n/ko-KR.json b/frontend/src/i18n/ko-KR.json index 00724c6d..ab0e1c48 100644 --- a/frontend/src/i18n/ko-KR.json +++ b/frontend/src/i18n/ko-KR.json @@ -335,7 +335,8 @@ }, "timeout": "쿼리 시간 초과(초)", "address": "주소" - } + }, + "sync_fields": "동기화된 테이블 구조" }, "datasource": { "recommended_repetitive_tips": "중복된 문제가 존재합니다", diff --git a/frontend/src/i18n/zh-CN.json b/frontend/src/i18n/zh-CN.json index 0be8b96b..86990ecf 100644 --- a/frontend/src/i18n/zh-CN.json +++ b/frontend/src/i18n/zh-CN.json @@ -336,7 +336,8 @@ }, "timeout": "查询超时(秒)", "address": "地址" - } + }, + "sync_fields": "同步表结构" }, "datasource": { "recommended_repetitive_tips": "存在重复问题", diff --git a/frontend/src/views/ds/DataTable.vue b/frontend/src/views/ds/DataTable.vue index 82bf3ffa..cf528aa3 100644 --- a/frontend/src/views/ds/DataTable.vue +++ b/frontend/src/views/ds/DataTable.vue @@ -10,6 +10,7 @@ import { useI18n } from 'vue-i18n' import ParamsForm from './ParamsForm.vue' import TableRelationship from '@/views/ds/TableRelationship.vue' import icon_mindnote_outlined from '@/assets/svg/icon_mindnote_outlined.svg' +import { Refresh } from '@element-plus/icons-vue' interface Table { name: string host: string @@ -223,6 +224,19 @@ const changeStatus = (row: any) => { }) } +const syncFields = () => { + loading.value = true + datasourceApi + .syncFields(currentTable.value.id) + .then(() => { + btnSelectClick('d') + loading.value = false + }) + .catch(() => { + loading.value = false + }) +} + const emits = defineEmits(['back', 'refresh']) const back = () => { emits('back') @@ -316,13 +330,13 @@ const btnSelectClick = (val: any) => { :key="ele.table_name" :draggable="activeRelationship && !tableName.includes(ele.id)" class="model" - @dragstart="($event: any) => singleDragStartD($event, ele)" - @dragend="singleDragEnd" :class="[ currentTable.table_name === ele.table_name && 'isActive', tableName.includes(ele.id) && activeRelationship && 'disabled-table', ]" :title="ele.table_name" + @dragstart="($event: any) => singleDragStartD($event, ele)" + @dragend="singleDragEnd" @click="clickTable(ele)" > @@ -349,7 +363,7 @@ const btnSelectClick = (val: any) => {
-
+
@@ -362,9 +376,9 @@ const btnSelectClick = (val: any) => {
{{ t('training.table_relationship_management') }}
@@ -409,12 +423,20 @@ const btnSelectClick = (val: any) => {
+ + {{ t('ds.sync_fields') }} +
{ position: absolute; right: 16px; top: 16px; - width: 240px; + width: 360px; + display: flex; } .btn-select {