Skip to content

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

Trigger a syntax check if we have updated the statement

天舟936c448ad24a
diff --git a/server/task.go b/server/task.go
index af3930792b..6d12441707 100644
--- a/server/task.go
+++ b/server/task.go
@@ -80,6 +80,34 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch updated task \"%v\" relationship", updatedTask.Name)).SetInternal(err)
}
+ // If we have updated the statement, then we trigger a syntax check
+ if task.Type == api.TaskDatabaseSchemaUpdate && taskPatch.Statement != nil {
+ payload, err := json.Marshal(api.TaskCheckDatabaseStatementAdvisePayload{
+ Statement: *taskPatch.Statement,
+ DbType: updatedTask.Database.Instance.Engine,
+ Charset: updatedTask.Database.CharacterSet,
+ Collation: updatedTask.Database.Collation,
+ })
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to marshal statement advise payload: %v, err: %w", task.Name, err))
+ }
+ _, err = s.TaskCheckRunService.CreateTaskCheckRunIfNeeded(context.Background(), &api.TaskCheckRunCreate{
+ CreatorId: api.SYSTEM_BOT_ID,
+ TaskId: task.ID,
+ Type: api.TaskCheckDatabaseStatementSyntax,
+ Payload: string(payload),
+ SkipIfAlreadyDone: false,
+ })
+ if err != nil {
+ // It's OK if we failed to trigger a check, just emit an error log
+ s.l.Error("Failed to trigger syntax check after changing task statement",
+ zap.Int("task_id", task.ID),
+ zap.String("task_name", task.Name),
+ zap.Error(err),
+ )
+ }
+ }
+
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := jsonapi.MarshalPayload(c.Response().Writer, updatedTask); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal update task \"%v\" status response", updatedTask.Name)).SetInternal(err)
diff --git a/server/task_check_scheduler.go b/server/task_check_scheduler.go
index 713550bf59..d7ed7264c5 100644
--- a/server/task_check_scheduler.go
+++ b/server/task_check_scheduler.go
@@ -173,7 +173,7 @@ func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *ap
Collation: database.Collation,
})
if err != nil {
- return nil, fmt.Errorf("failed to marshal activity after changing the task status: %v, err: %w", task.Name, err)
+ return nil, fmt.Errorf("failed to marshal statement advise payload: %v, err: %w", task.Name, err)
}
_, err = s.server.TaskCheckRunService.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
CreatorId: creatorId,