Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: use `notify` to display schema review advice (#1562)

Steven8bb659de7efc
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.ts
index e9f773ad78..dd6f626f5c 100644
--- a/frontend/src/composables/useExecuteSQL.ts
+++ b/frontend/src/composables/useExecuteSQL.ts
@@ -100,21 +100,51 @@ const useExecuteSQL = () => {
);
}
+ let selectStatement =
+ data !== null ? transformSQL(data, config.databaseType) : sqlStatement;
+ if (option?.explain) {
+ selectStatement = `EXPLAIN ${selectStatement}`;
+ }
+
try {
- const isExplain = option?.explain || false;
state.isLoadingData = true;
sqlEditorStore.setIsExecuting(true);
- // remove the comment from the sql statement in front-end
- const selectStatement =
- data !== null ? transformSQL(data, config.databaseType) : sqlStatement;
- const explainStatement = `EXPLAIN ${selectStatement}`;
- const queryResult = (await sqlEditorStore.executeQuery({
- statement: isExplain ? explainStatement : selectStatement,
- })) as any;
- tabStore.updateCurrentTab({ queryResult });
+ const sqlResultSet = await sqlEditorStore.executeQuery({
+ statement: selectStatement,
+ });
+ // TODO(steven): use BBModel instead of notify to show the advice from schema review.
+ let adviceStatus = "";
+ let adviceNotifyMessage = "";
+ for (const advice of sqlResultSet.adviceList) {
+ if (advice.status === "ERROR") {
+ adviceStatus = "ERROR";
+ } else if (adviceStatus !== "ERROR") {
+ adviceStatus = advice.status;
+ }
+
+ adviceNotifyMessage += `${advice.status}: ${advice.title}\n`;
+ if (advice.content) {
+ adviceNotifyMessage += `${advice.content}\n`;
+ }
+ }
+ if (adviceStatus) {
+ const notifyStyle = adviceStatus === "ERROR" ? "CRITICAL" : "WARN";
+ notify(
+ notifyStyle,
+ t("sql-editor.sql-review-result"),
+ adviceNotifyMessage
+ );
+ }
+ tabStore.updateCurrentTab({
+ queryResult: sqlResultSet.data as any,
+ adviceList: sqlResultSet.adviceList,
+ });
sqlEditorStore.fetchQueryHistoryList();
} catch (error) {
- tabStore.updateCurrentTab({ queryResult: undefined });
+ tabStore.updateCurrentTab({
+ queryResult: undefined,
+ adviceList: undefined,
+ });
notify("CRITICAL", error as string);
} finally {
state.isLoadingData = false;
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 5ad1a88f1b..a5475b7e1f 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1177,7 +1177,8 @@
"save-sheet": "Save Sheet",
"save-sheet-input-placeholder": "Please input a sheet name",
"untitled-sheet": "Untitled Sheet",
- "format": "Format"
+ "format": "Format",
+ "sql-review-result": "SQL review result"
},
"label": {
"empty-label-value": "<Empty Value>",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 9dc229b142..e28afaaed6 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1177,7 +1177,8 @@
"save-sheet": "保存工作表",
"save-sheet-input-placeholder": "请输入工作表名称",
"untitled-sheet": "未命名工作表",
- "format": "格式化"
+ "format": "格式化",
+ "sql-review-result": "SQL 检查结果"
},
"label": {
"empty-label-value": "<空值>",
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index 3cd1e069bb..048d65ba48 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -388,13 +388,13 @@ export const useInstanceStore = defineStore("instance", {
};
},
async createMigrationSetup(instanceId: InstanceId): Promise<SQLResultSet> {
- const data = (
+ const res = (
await axios.post(`/api/instance/${instanceId}/migration`, undefined, {
timeout: INSTANCE_OPERATION_TIMEOUT,
})
- ).data.data;
+ ).data;
- return useSQLStore().convert(data) as SQLResultSet;
+ return useSQLStore().convert(res.data) as SQLResultSet;
},
async fetchMigrationHistoryById({
instanceId,
diff --git a/frontend/src/store/modules/sql.ts b/frontend/src/store/modules/sql.ts
index 2a97d3f9a5..1bf392e0c3 100644
--- a/frontend/src/store/modules/sql.ts
+++ b/frontend/src/store/modules/sql.ts
@@ -7,14 +7,16 @@ import {
QueryInfo,
ResourceObject,
SQLResultSet,
+ Advice,
} from "@/types";
import { useDatabaseStore } from "./database";
import { useInstanceStore } from "./instance";
function convert(resultSet: ResourceObject): SQLResultSet {
return {
- data: JSON.parse((resultSet.attributes.data as string) || "{}"),
+ data: JSON.parse((resultSet.attributes.data as string) || "null"),
error: resultSet.attributes.error as string,
+ adviceList: resultSet.attributes.adviceList as Advice[],
};
}
@@ -25,19 +27,19 @@ export const useSQLStore = defineStore("sql", {
},
async ping(connectionInfo: ConnectionInfo) {
- const data = (
+ const res = (
await axios.post(`/api/sql/ping`, {
data: {
type: "connectionInfo",
attributes: connectionInfo,
},
})
- ).data.data;
+ ).data;
- return convert(data);
+ return convert(res.data);
},
async syncSchema(instanceId: InstanceId) {
- const data = (
+ const res = (
await axios.post(
`/api/sql/sync-schema`,
{
@@ -52,9 +54,9 @@ export const useSQLStore = defineStore("sql", {
timeout: INSTANCE_OPERATION_TIMEOUT,
}
)
- ).data.data;
+ ).data;
- const resultSet = convert(data);
+ const resultSet = convert(res.data);
if (!resultSet.error) {
// Refresh the corresponding list.
useDatabaseStore().fetchDatabaseListByInstanceId(instanceId);
@@ -63,8 +65,8 @@ export const useSQLStore = defineStore("sql", {
return resultSet;
},
- async query(queryInfo: QueryInfo) {
- const data = (
+ async query(queryInfo: QueryInfo): Promise<SQLResultSet> {
+ const res = (
await axios.post(
`/api/sql/execute`,
{
@@ -80,14 +82,14 @@ export const useSQLStore = defineStore("sql", {
timeout: INSTANCE_OPERATION_TIMEOUT,
}
)
- ).data.data;
+ ).data;
- const resultSet = convert(data);
+ const resultSet = convert(res.data);
if (resultSet.error) {
throw new Error(resultSet.error);
}
- return resultSet.data;
+ return resultSet;
},
},
});
diff --git a/frontend/src/types/sql.ts b/frontend/src/types/sql.ts
index 81ec9b6f1b..74278d9871 100644
--- a/frontend/src/types/sql.ts
+++ b/frontend/src/types/sql.ts
@@ -1,4 +1,4 @@
-import { EngineType } from ".";
+import { EngineType, TaskCheckResult } from ".";
import { InstanceId } from "./id";
export type ConnectionInfo = {
@@ -23,7 +23,10 @@ export type QueryInfo = {
limit?: number;
};
+export type Advice = TaskCheckResult;
+
export type SQLResultSet = {
- data: string;
+ data: any[];
error: string;
+ adviceList: Advice[];
};
diff --git a/frontend/src/types/tab.ts b/frontend/src/types/tab.ts
index 648983dd73..f244e7785b 100644
--- a/frontend/src/types/tab.ts
+++ b/frontend/src/types/tab.ts
@@ -1,4 +1,4 @@
-import { SheetId } from "../types";
+import { Advice, SheetId } from "../types";
export interface TabInfo {
id: string;
@@ -10,6 +10,7 @@ export interface TabInfo {
// [columnNames: string[], types: string[], data: any[][]]
queryResult?: [string[], string[], any[][]];
sheetId?: SheetId;
+ adviceList?: Advice[];
}
export type AnyTabInfo = Partial<TabInfo>;
diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue b/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue
index a069309de1..6b3992eaf8 100644
--- a/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue
@@ -158,8 +158,8 @@ const hasReadonlyDataSource = computed(() => {
const { execute, state: executeState } = useExecuteSQL();
-const handleRunQuery = () => {
- execute({ databaseType: selectedInstanceEngine.value });
+const handleRunQuery = async () => {
+ await execute({ databaseType: selectedInstanceEngine.value });
};
const handleExplainQuery = () => {
diff --git a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
index 792a2e973c..2ca320301b 100644
--- a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
@@ -110,14 +110,14 @@ const handleChangeSelection = debounce((value: string) => {
});
}, 300);
-const handleRunQuery = ({
+const handleRunQuery = async ({
explain,
query,
}: {
explain: boolean;
query: string;
}) => {
- execute({ databaseType: selectedInstanceEngine.value }, { explain });
+ await execute({ databaseType: selectedInstanceEngine.value }, { explain });
};
const handleSaveSheet = () => {
diff --git a/frontend/src/views/sql-editor/TablePanel/TableView.vue b/frontend/src/views/sql-editor/TablePanel/TableView.vue
index c87d2c40df..82475cffe9 100644
--- a/frontend/src/views/sql-editor/TablePanel/TableView.vue
+++ b/frontend/src/views/sql-editor/TablePanel/TableView.vue
@@ -129,7 +129,7 @@ const data = computed(() => {
return temp;
});
const notifyMessage = computed(() => {
- if (queryResult.value === null) {
+ if (!queryResult.value) {
return t("sql-editor.table-empty-placehoder");
}
if (sqlEditorStore.isExecuting) {