Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: only show succeed query history (#788)
STEVEN5d5a62cd87eb
diff --git a/api/activity.go b/api/activity.goindex 3d03385cae..93d6d2220c 100644--- a/api/activity.go+++ b/api/activity.go@@ -293,6 +293,7 @@ type ActivityFind struct {// Domain specific fieldsCreatorID *intType *string+ Level *ActivityLevelContainerID *intLimit *int}diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.tsindex 1e5b60fd10..6ac98c5c26 100644--- a/frontend/src/composables/useExecuteSQL.ts+++ b/frontend/src/composables/useExecuteSQL.ts@@ -101,20 +101,17 @@ const useExecuteSQL = () => {const selectStatement =data !== null ? transformSQL(data, config.databaseType) : sqlStatement;const explainStatement = `EXPLAIN ${selectStatement}`;- const res = await store.dispatch("sqlEditor/executeQuery", {+ const queryResult = await store.dispatch("sqlEditor/executeQuery", {statement: isExplain ? explainStatement : selectStatement,});- state.isLoadingData = false;- store.dispatch("sqlEditor/setIsExecuting", false);-- if (res.error) {- notify("CRITICAL", res.error);- return;- }+ store.dispatch("tab/updateCurrentTab", { queryResult });+ store.dispatch("sqlEditor/fetchQueryHistoryList");} catch (error) {+ store.dispatch("tab/updateCurrentTab", { queryResult: undefined });+ notify("CRITICAL", error as string);+ } finally {state.isLoadingData = false;store.dispatch("sqlEditor/setIsExecuting", false);- notify("CRITICAL", error as string);}};diff --git a/frontend/src/store/modules/activity.ts b/frontend/src/store/modules/activity.tsindex 97a01fe603..d55484c5ae 100644--- a/frontend/src/store/modules/activity.ts+++ b/frontend/src/store/modules/activity.ts@@ -122,6 +122,8 @@ const actions = {"type=bb.sql-editor.query",`user=${currentUser.id}`,`limit=${limit}`,+ // only fetch the successful query history+ `level=INFO`,];const data = (await axios.get(`/api/activity?${queryList.join("&")}`)).data;const activityList = data.data.map((activity: ResourceObject) => {diff --git a/frontend/src/store/modules/sqlEditor.ts b/frontend/src/store/modules/sqlEditor.tsindex f65452bb01..88ffaf7284 100644--- a/frontend/src/store/modules/sqlEditor.ts+++ b/frontend/src/store/modules/sqlEditor.ts@@ -201,8 +201,6 @@ const actions = {{ root: true });- dispatch("tab/updateCurrentTab", { queryResult }, { root: true });- dispatch("fetchQueryHistoryList");return queryResult;},async fetchConnectionByInstanceIdAndDatabaseId(diff --git a/server/activity.go b/server/activity.goindex 3d572db881..bcb4b33db8 100644--- a/server/activity.go+++ b/server/activity.go@@ -77,6 +77,10 @@ func (s *Server) registerActivityRoutes(g *echo.Group) {if typeStr := c.QueryParams().Get("type"); typeStr != "" {activityFind.Type = &typeStr}+ if levelStr := c.QueryParams().Get("level"); levelStr != "" {+ activityLevel := api.ActivityLevel(levelStr)+ activityFind.Level = &activityLevel+ }if containerIDStr := c.QueryParams().Get("container"); containerIDStr != "" {containerID, err := strconv.Atoi(containerIDStr)if err != nil {diff --git a/server/sql.go b/server/sql.goindex bcecb8f6b1..fb5badc31d 100644--- a/server/sql.go+++ b/server/sql.go@@ -149,7 +149,7 @@ func (s *Server) registerSQLRoutes(g *echo.Group) {activityLevel = api.ActivityError}- bytes, err := json.Marshal(api.ActivitySQLEditorQueryPayload{+ activityBytes, err := json.Marshal(api.ActivitySQLEditorQueryPayload{Statement: exec.Statement,DurationNs: time.Now().UnixNano() - start,InstanceName: instance.Name,@@ -173,7 +173,7 @@ func (s *Server) registerSQLRoutes(g *echo.Group) {Level: activityLevel,Comment: fmt.Sprintf("Executed `%q` in database %q of instance %q.",exec.Statement, exec.DatabaseName, instance.Name),- Payload: string(bytes),+ Payload: string(activityBytes),}_, err = s.ActivityManager.CreateActivity(ctx, activityCreate, &ActivityMeta{})@@ -184,6 +184,7 @@ func (s *Server) registerSQLRoutes(g *echo.Group) {zap.String("instance_name", instance.Name),zap.String("statement", exec.Statement),zap.Error(err))+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)}}diff --git a/store/activity.go b/store/activity.goindex 44f9287a0e..6f855a2fb5 100644--- a/store/activity.go+++ b/store/activity.go@@ -192,6 +192,9 @@ func findActivityList(ctx context.Context, tx *sql.Tx, find *api.ActivityFind) (if v := find.Type; v != nil {where, args = append(where, fmt.Sprintf("type = $%d", len(args)+1)), append(args, *v)}+ if v := find.Level; v != nil {+ where, args = append(where, fmt.Sprintf("level = $%d", len(args)+1)), append(args, *v)+ }var query = `SELECT