Skip to content

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

feat: no auto approve for rollback tasks (#4765)

p0ny969faed6686f
diff --git a/backend/legacyapi/task.go b/backend/legacyapi/task.go
index c7967876a8..ae89474881 100644
--- a/backend/legacyapi/task.go
+++ b/backend/legacyapi/task.go
@@ -317,8 +317,9 @@ type TaskFind struct {
TypeList *[]TaskType
// Payload contains JSONB expressions
// Ref: https://www.postgresql.org/docs/current/functions-json.html
- Payload string
- StageBlocked *bool
+ Payload string
+ NoBlockingStage bool
+ NonRollbackTask bool
}
func (find *TaskFind) String() string {
diff --git a/backend/runner/taskrun/scheduler.go b/backend/runner/taskrun/scheduler.go
index 6efd8fb53c..ab57ba344c 100644
--- a/backend/runner/taskrun/scheduler.go
+++ b/backend/runner/taskrun/scheduler.go
@@ -799,10 +799,10 @@ func (s *Scheduler) isTaskBlocked(ctx context.Context, task *store.TaskMessage)
// scheduleAutoApprovedTasks schedules tasks that are approved automatically.
func (s *Scheduler) scheduleAutoApprovedTasks(ctx context.Context) error {
taskStatusList := []api.TaskStatus{api.TaskPendingApproval}
- blocked := false
taskList, err := s.store.ListTasks(ctx, &api.TaskFind{
- StatusList: &taskStatusList,
- StageBlocked: &blocked,
+ StatusList: &taskStatusList,
+ NoBlockingStage: true,
+ NonRollbackTask: true,
})
if err != nil {
return err
diff --git a/backend/store/task.go b/backend/store/task.go
index ea5aec7a15..396cb83ac7 100644
--- a/backend/store/task.go
+++ b/backend/store/task.go
@@ -333,8 +333,11 @@ func (s *Store) ListTasks(ctx context.Context, find *api.TaskFind) ([]*TaskMessa
if v := find.Payload; v != "" {
where = append(where, v)
}
- if v := find.StageBlocked; v != nil {
- where = append(where, "(SELECT COUNT(1) > 0 FROM task as other_task WHERE other_task.pipeline_id = task.pipeline_id AND other_task.stage_id < task.stage_id AND other_task.status != 'DONE') = FALSE")
+ if find.NoBlockingStage {
+ where = append(where, "(SELECT NOT EXISTS (SELECT 1 FROM task as other_task WHERE other_task.pipeline_id = task.pipeline_id AND other_task.stage_id < task.stage_id AND other_task.status != 'DONE'))")
+ }
+ if find.NonRollbackTask {
+ where = append(where, "(NOT (task.type='bb.task.database.data.update' AND task.payload->>'rollbackFromTaskId' IS NOT NULL))")
}
tx, err := s.db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})