Skip to content

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

feat: remove task run useless columns (#7352)

p0ny4df30da89ee4
diff --git a/backend/migrator/migration/dev/LATEST.sql b/backend/migrator/migration/dev/LATEST.sql
index 63e58119e8..8370fb88f5 100644
--- a/backend/migrator/migration/dev/LATEST.sql
+++ b/backend/migrator/migration/dev/LATEST.sql
@@ -639,13 +639,10 @@ CREATE TABLE task_run (
updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
task_id INTEGER NOT NULL REFERENCES task (id),
name TEXT NOT NULL,
- status TEXT NOT NULL CHECK (status IN ('RUNNING', 'DONE', 'FAILED', 'CANCELED')),
- type TEXT NOT NULL CHECK (type LIKE 'bb.task.%'),
+ status TEXT NOT NULL CHECK (status IN ('PENDING', 'RUNNING', 'DONE', 'FAILED', 'CANCELED')),
code INTEGER NOT NULL DEFAULT 0,
- comment TEXT NOT NULL DEFAULT '',
-- result saves the task run result in json format
- result JSONB NOT NULL DEFAULT '{}',
- payload JSONB NOT NULL DEFAULT '{}'
+ result JSONB NOT NULL DEFAULT '{}'
);
CREATE INDEX idx_task_run_task_id ON task_run(task_id);
diff --git a/backend/migrator/migration/prod/2.6/0000##task_run_remove_useless_update_status.sql b/backend/migrator/migration/prod/2.6/0000##task_run_remove_useless_update_status.sql
new file mode 100644
index 0000000000..fca6e79af1
--- /dev/null
+++ b/backend/migrator/migration/prod/2.6/0000##task_run_remove_useless_update_status.sql
@@ -0,0 +1,5 @@
+ALTER TABLE task_run DROP IF EXISTS type, DROP IF EXISTS comment, DROP IF EXISTS payload;
+
+ALTER TABLE task_run DROP CONSTRAINT task_run_status_check;
+
+ALTER TABLE task_run ADD CONSTRAINT task_run_status_check CHECK (status IN ('PENDING', 'RUNNING', 'DONE', 'FAILED', 'CANCELED'));
\ No newline at end of file
diff --git a/backend/migrator/migration/prod/LATEST.sql b/backend/migrator/migration/prod/LATEST.sql
index 94a39862f6..860b08ca2c 100644
--- a/backend/migrator/migration/prod/LATEST.sql
+++ b/backend/migrator/migration/prod/LATEST.sql
@@ -638,13 +638,10 @@ CREATE TABLE task_run (
updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
task_id INTEGER NOT NULL REFERENCES task (id),
name TEXT NOT NULL,
- status TEXT NOT NULL CHECK (status IN ('RUNNING', 'DONE', 'FAILED', 'CANCELED')),
- type TEXT NOT NULL CHECK (type LIKE 'bb.task.%'),
+ status TEXT NOT NULL CHECK (status IN ('PENDING', 'RUNNING', 'DONE', 'FAILED', 'CANCELED')),
code INTEGER NOT NULL DEFAULT 0,
- comment TEXT NOT NULL DEFAULT '',
-- result saves the task run result in json format
- result JSONB NOT NULL DEFAULT '{}',
- payload JSONB NOT NULL DEFAULT '{}'
+ result JSONB NOT NULL DEFAULT '{}'
);
CREATE INDEX idx_task_run_task_id ON task_run(task_id);
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 2fd09933a9..e55f7c6638 100644
--- a/backend/migrator/migrator_test.go
+++ b/backend/migrator/migrator_test.go
@@ -241,5 +241,5 @@ func TestMigrationCompatibility(t *testing.T) {
func TestGetCutoffVersion(t *testing.T) {
releaseVersion, err := getProdCutoffVersion()
require.NoError(t, err)
- require.Equal(t, semver.MustParse("2.5.5"), releaseVersion)
+ require.Equal(t, semver.MustParse("2.6.0"), releaseVersion)
}
diff --git a/backend/store/task.go b/backend/store/task.go
index 51176e1579..2143368607 100644
--- a/backend/store/task.go
+++ b/backend/store/task.go
@@ -549,7 +549,6 @@ func (s *Store) UpdateTaskStatusV2(ctx context.Context, patch *api.TaskStatusPat
if err := s.createTaskRunImpl(ctx, tx, &TaskRunMessage{
TaskUID: task.ID,
Name: fmt.Sprintf("%s %d", task.Name, time.Now().Unix()),
- Type: task.Type,
}, patch.UpdaterID); err != nil {
return nil, err
}
@@ -563,7 +562,6 @@ func (s *Store) UpdateTaskStatusV2(ctx context.Context, patch *api.TaskStatusPat
UpdaterID: patch.UpdaterID,
Code: patch.Code,
Result: patch.Result,
- Comment: patch.Comment,
}
switch patch.Status {
case api.TaskDone:
diff --git a/backend/store/task_run.go b/backend/store/task_run.go
index 9af1362310..d7c5f458fc 100644
--- a/backend/store/task_run.go
+++ b/backend/store/task_run.go
@@ -21,12 +21,9 @@ type TaskRunMessage struct {
PipelineUID int
Name string
Status api.TaskRunStatus
- Type api.TaskType
Code common.Code
- Comment string
Result string
ResultProto *storepb.TaskRunResult
- Payload string
// Output only.
ID int
@@ -47,15 +44,6 @@ type FindTaskRunMessage struct {
PipelineUID *int
}
-// TaskRunCreate is the API message for creating a task run.
-type TaskRunCreate struct {
- CreatorID int
- TaskID int
- Name string
- Type api.TaskType
- Payload string
-}
-
// TaskRunFind is the API message for finding task runs.
type TaskRunFind struct {
// Related fields
@@ -77,9 +65,7 @@ type TaskRunStatusPatch struct {
// Domain specific fields
Status api.TaskRunStatus
Code *common.Code
- // Records the status detail (e.g. error message on failure)
- Comment *string
- Result *string
+ Result *string
}
func (taskRun *TaskRunMessage) toTaskRun() *api.TaskRun {
@@ -92,11 +78,11 @@ func (taskRun *TaskRunMessage) toTaskRun() *api.TaskRun {
TaskID: taskRun.TaskUID,
Name: taskRun.Name,
Status: taskRun.Status,
- Type: taskRun.Type,
+ Type: api.TaskGeneral,
Code: taskRun.Code,
- Comment: taskRun.Comment,
+ Comment: "",
Result: taskRun.Result,
- Payload: taskRun.Payload,
+ Payload: "",
}
}
@@ -126,11 +112,8 @@ func (s *Store) ListTaskRunsV2(ctx context.Context, find *FindTaskRunMessage) ([
task_run.task_id,
task_run.name,
task_run.status,
- task_run.type,
task_run.code,
- task_run.comment,
task_run.result,
- task_run.payload,
task.pipeline_id,
task.stage_id,
project.resource_id
@@ -158,11 +141,8 @@ func (s *Store) ListTaskRunsV2(ctx context.Context, find *FindTaskRunMessage) ([
&taskRun.TaskUID,
&taskRun.Name,
&taskRun.Status,
- &taskRun.Type,
&taskRun.Code,
- &taskRun.Comment,
&taskRun.Result,
- &taskRun.Payload,
&taskRun.PipelineUID,
&taskRun.StageUID,
&taskRun.ProjectID,
@@ -201,19 +181,14 @@ func (s *Store) ListTaskRunsV2(ctx context.Context, find *FindTaskRunMessage) ([
// createTaskRunImpl creates a new taskRun.
func (*Store) createTaskRunImpl(ctx context.Context, tx *Tx, create *TaskRunMessage, creatorID int) error {
- if create.Payload == "" {
- create.Payload = "{}"
- }
query := `
INSERT INTO task_run (
creator_id,
updater_id,
task_id,
name,
- status,
- type,
- payload
- ) VALUES ($1, $2, $3, $4, $5, $6, $7)
+ status
+ ) VALUES ($1, $2, $3, $4, $5)
`
if _, err := tx.ExecContext(ctx, query,
creatorID,
@@ -221,8 +196,6 @@ func (*Store) createTaskRunImpl(ctx context.Context, tx *Tx, create *TaskRunMess
create.TaskUID,
create.Name,
api.TaskRunRunning,
- create.Type,
- "{}", /* payload */
); err != nil {
return err
}
@@ -249,9 +222,6 @@ func (*Store) patchTaskRunStatusImpl(ctx context.Context, tx *Tx, patch *TaskRun
if v := patch.Code; v != nil {
set, args = append(set, fmt.Sprintf("code = $%d", len(args)+1)), append(args, *v)
}
- if v := patch.Comment; v != nil {
- set, args = append(set, fmt.Sprintf("comment = $%d", len(args)+1)), append(args, *v)
- }
if v := patch.Result; v != nil {
result := "{}"
if *v != "" {
@@ -269,7 +239,7 @@ func (*Store) patchTaskRunStatusImpl(ctx context.Context, tx *Tx, patch *TaskRun
UPDATE task_run
SET `+strings.Join(set, ", ")+`
WHERE `+strings.Join(where, " AND ")+`
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, status, type, code, comment, result, payload
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, status, code, result
`,
args...,
).Scan(
@@ -281,11 +251,8 @@ func (*Store) patchTaskRunStatusImpl(ctx context.Context, tx *Tx, patch *TaskRun
&taskRun.TaskUID,
&taskRun.Name,
&taskRun.Status,
- &taskRun.Type,
&taskRun.Code,
- &taskRun.Comment,
&taskRun.Result,
- &taskRun.Payload,
); err != nil {
if err == sql.ErrNoRows {
return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("project ID not found: %d", patch.ID)}
@@ -346,11 +313,8 @@ func (*Store) findTaskRunImpl(ctx context.Context, tx *Tx, find *TaskRunFind) ([
task_run.task_id,
task_run.name,
task_run.status,
- task_run.type,
task_run.code,
- task_run.comment,
task_run.result,
- task_run.payload,
task.pipeline_id,
task.stage_id
FROM task_run
@@ -375,11 +339,8 @@ func (*Store) findTaskRunImpl(ctx context.Context, tx *Tx, find *TaskRunFind) ([
&taskRun.TaskUID,
&taskRun.Name,
&taskRun.Status,
- &taskRun.Type,
&taskRun.Code,
- &taskRun.Comment,
&taskRun.Result,
- &taskRun.Payload,
&taskRun.PipelineUID,
&taskRun.StageUID,
); err != nil {