Skip to content

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

Remove statement, rollbackStatement in Issue table and just rely on the correponding payload stored in Task

天舟a060830f8fd4
diff --git a/backend/api/issue.go b/backend/api/issue.go
index 33c8069615..e5cfe1db31 100644
--- a/backend/api/issue.go
+++ b/backend/api/issue.go
@@ -88,16 +88,14 @@ type Issue struct {
Pipeline *Pipeline `jsonapi:"relation,pipeline"`
// Domain specific fields
- Name string `jsonapi:"attr,name"`
- Status IssueStatus `jsonapi:"attr,status"`
- Type IssueType `jsonapi:"attr,type"`
- Description string `jsonapi:"attr,description"`
- AssigneeId int `jsonapi:"attr,assigneeId"`
- Assignee *Principal `jsonapi:"attr,assignee"`
- SubscriberIdList []int `jsonapi:"attr,subscriberIdList"`
- Statement string `jsonapi:"attr,statement"`
- RollbackStatement string `jsonapi:"attr,rollbackStatement"`
- Payload IssuePayload `jsonapi:"attr,payload"`
+ Name string `jsonapi:"attr,name"`
+ Status IssueStatus `jsonapi:"attr,status"`
+ Type IssueType `jsonapi:"attr,type"`
+ Description string `jsonapi:"attr,description"`
+ AssigneeId int `jsonapi:"attr,assigneeId"`
+ Assignee *Principal `jsonapi:"attr,assignee"`
+ SubscriberIdList []int `jsonapi:"attr,subscriberIdList"`
+ Payload IssuePayload `jsonapi:"attr,payload"`
}
type IssueCreate struct {
diff --git a/backend/api/task.go b/backend/api/task.go
index 9a82a4a56e..99d996166e 100644
--- a/backend/api/task.go
+++ b/backend/api/task.go
@@ -72,7 +72,7 @@ type Task struct {
Name string `jsonapi:"attr,name"`
Status TaskStatus `jsonapi:"attr,status"`
Type TaskType `jsonapi:"attr,type"`
- Payload []byte `jsonapi:"attr,payload"`
+ Payload string `jsonapi:"attr,payload"`
}
type TaskCreate struct {
@@ -89,7 +89,7 @@ type TaskCreate struct {
Name string `jsonapi:"attr,name"`
Status TaskStatus `jsonapi:"attr,status"`
Type TaskType `jsonapi:"attr,type"`
- Payload []byte `jsonapi:"attr,payload"`
+ Payload string `jsonapi:"attr,payload"`
}
type TaskFind struct {
diff --git a/backend/api/task_run.go b/backend/api/task_run.go
index 6ecc4aa566..efd1f6b1f7 100644
--- a/backend/api/task_run.go
+++ b/backend/api/task_run.go
@@ -49,7 +49,7 @@ type TaskRun struct {
Status TaskRunStatus `jsonapi:"attr,status"`
Type TaskType `jsonapi:"attr,type"`
Error string `jsonapi:"attr,error"`
- Payload []byte `jsonapi:"attr,payload"`
+ Payload string `jsonapi:"attr,payload"`
}
type TaskRunCreate struct {
@@ -63,7 +63,7 @@ type TaskRunCreate struct {
// Domain specific fields
Name string `jsonapi:"attr,name"`
Type TaskType `jsonapi:"attr,type"`
- Payload []byte `jsonapi:"attr,payload"`
+ Payload string `jsonapi:"attr,payload"`
}
type TaskRunFind struct {
diff --git a/backend/server/issue.go b/backend/server/issue.go
index 5b40a4d37d..358a32e707 100644
--- a/backend/server/issue.go
+++ b/backend/server/issue.go
@@ -51,7 +51,7 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create task for issue").SetInternal(err)
}
- taskCreate.Payload = bytes
+ taskCreate.Payload = string(bytes)
}
_, err := s.TaskService.CreateTask(context.Background(), &taskCreate)
if err != nil {
diff --git a/backend/server/task_executor_sql.go b/backend/server/task_executor_sql.go
index 9e62704e4b..94a842f2bb 100644
--- a/backend/server/task_executor_sql.go
+++ b/backend/server/task_executor_sql.go
@@ -22,7 +22,7 @@ type SqlTaskExecutor struct {
func (exec *SqlTaskExecutor) RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, err error) {
payload := &api.TaskDatabaseSchemaUpdatePayload{}
- if err := json.Unmarshal(task.Payload, payload); err != nil {
+ if err := json.Unmarshal([]byte(task.Payload), payload); err != nil {
return true, fmt.Errorf("invalid schema update payload: %w", err)
}
diff --git a/backend/store/issue.go b/backend/store/issue.go
index 6620ebdf84..b4b2091dc4 100644
--- a/backend/store/issue.go
+++ b/backend/store/issue.go
@@ -127,12 +127,10 @@ func (s *IssueService) createIssue(ctx context.Context, tx *Tx, create *api.Issu
description,
assignee_id,
subscriber_id_list,
- statement,
- rollback_statement,
payload
)
- VALUES (?, ?, ?, ?, ?, 'OPEN', ?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, pipeline_id, name, `+"`status`, `type`, description, assignee_id, subscriber_id_list, statement, rollback_statement, payload"+`
+ VALUES (?, ?, ?, ?, ?, 'OPEN', ?, ?, ?, ?, ?)
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, pipeline_id, name, `+"`status`, `type`, description, assignee_id, subscriber_id_list, payload"+`
`,
create.CreatorId,
create.CreatorId,
@@ -143,8 +141,6 @@ func (s *IssueService) createIssue(ctx context.Context, tx *Tx, create *api.Issu
create.Description,
create.AssigneeId,
strings.Join(subscriberIdList, ","),
- create.Statement,
- create.RollbackStatement,
newPayload,
)
@@ -171,8 +167,6 @@ func (s *IssueService) createIssue(ctx context.Context, tx *Tx, create *api.Issu
&issue.Description,
&issue.AssigneeId,
&idList,
- &issue.Statement,
- &issue.RollbackStatement,
&payload,
); err != nil {
return nil, FormatError(err)
@@ -233,8 +227,6 @@ func (s *IssueService) findIssueList(ctx context.Context, tx *Tx, find *api.Issu
description,
assignee_id,
subscriber_id_list,
- statement,
- rollback_statement,
payload
FROM issue
WHERE `+strings.Join(where, " AND "),
@@ -265,8 +257,6 @@ func (s *IssueService) findIssueList(ctx context.Context, tx *Tx, find *api.Issu
&issue.Description,
&issue.AssigneeId,
&idList,
- &issue.Statement,
- &issue.RollbackStatement,
&payload,
); err != nil {
return nil, FormatError(err)
@@ -338,7 +328,7 @@ func (s *IssueService) patchIssue(ctx context.Context, tx *Tx, patch *api.IssueP
UPDATE issue
SET `+strings.Join(set, ", ")+`
WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, pipeline_id, name, `+"`status`, `type`, description, assignee_id, subscriber_id_list, statement, rollback_statement, payload"+`
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, pipeline_id, name, `+"`status`, `type`, description, assignee_id, subscriber_id_list, payload"+`
`,
args...,
)
@@ -365,8 +355,6 @@ func (s *IssueService) patchIssue(ctx context.Context, tx *Tx, patch *api.IssueP
&issue.Description,
&issue.AssigneeId,
&idList,
- &issue.Statement,
- &issue.RollbackStatement,
&payload,
); err != nil {
return nil, FormatError(err)
diff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sql
index 32c5675a65..abdd252e3d 100644
--- a/backend/store/migration/0001_init_schema.up.sql
+++ b/backend/store/migration/0001_init_schema.up.sql
@@ -543,8 +543,6 @@ CREATE TABLE issue (
description TEXT NOT NULL,
assignee_id INTEGER REFERENCES principal (id),
subscriber_id_list TEXT NOT NULL,
- statement TEXT NOT NULL DEFAULT '',
- rollback_statement TEXT NOT NULL DEFAULT '',
payload TEXT NOT NULL DEFAULT '{}'
);
diff --git a/backend/store/seed/0110_task.sql b/backend/store/seed/0110_task.sql
index 6a92a73a5b..995dc79aba 100644
--- a/backend/store/seed/0110_task.sql
+++ b/backend/store/seed/0110_task.sql
@@ -52,7 +52,7 @@ VALUES
'Update testdb1',
'bb.task.database.schema.update',
'PENDING',
- '{"statement":"ALTER TABLE warehouse ADD COLUMN location VARCHAR(255);", "rollbackStatement":"ALTER TABLE warehouse DROP COLUMN location;"}'
+ '{"statement":"ALTER TABLE testdb1.warehouse ADD COLUMN location VARCHAR(255);", "rollbackStatement":"ALTER TABLE testdb1.warehouse DROP COLUMN location;"}'
);
-- Task for stage 10003 "Integration" to update database 7003 'testdb2'
@@ -80,7 +80,7 @@ VALUES
'Update testdb2',
'bb.task.database.schema.update',
'PENDING',
- '{"statement":"ALTER TABLE warehouse ADD COLUMN location VARCHAR(255);", "rollbackStatement":"ALTER TABLE warehouse DROP COLUMN location;"}'
+ '{"statement":"ALTER TABLE testdb2.warehouse ADD COLUMN location VARCHAR(255);", "rollbackStatement":"ALTER TABLE testdb2.warehouse DROP COLUMN location;"}'
);
-- Task for stage 10004 "Staging" to update database 7006 'testdb3'
@@ -108,7 +108,7 @@ VALUES
'Update testdb3',
'bb.task.database.schema.update',
'PENDING_APPROVAL',
- '{"statement":"ALTER TABLE warehouse ADD COLUMN location VARCHAR(255);", "rollbackStatement":"ALTER TABLE warehouse DROP COLUMN location;"}'
+ '{"statement":"ALTER TABLE testdb3.warehouse ADD COLUMN location VARCHAR(255);", "rollbackStatement":"ALTER TABLE testdb3.warehouse DROP COLUMN location;"}'
);
-- Task for stage 10005 "Prod" to update database 7008 'testdb4'
@@ -136,7 +136,7 @@ VALUES
'Update testdb4',
'bb.task.database.schema.update',
'PENDING_APPROVAL',
- '{"statement":"ALTER TABLE warehouse ADD COLUMN location VARCHAR(255);", "rollbackStatement":"ALTER TABLE warehouse DROP COLUMN location;"}'
+ '{"statement":"ALTER TABLE testdb4.warehouse ADD COLUMN location VARCHAR(255);", "rollbackStatement":"ALTER TABLE testdb4.warehouse DROP COLUMN location;"}'
);
-- Task for Pipeline 9003 create table
@@ -165,7 +165,7 @@ VALUES
'Update testdb1',
'bb.task.database.schema.update',
'PENDING_APPROVAL',
- '{"statement":"CREATE TABLE tbl1 (name TEXT);", "rollbackStatement":"DROP TABLE tbl1;"}'
+ '{"statement":"CREATE TABLE testdb1.tbl1 (name TEXT);", "rollbackStatement":"DROP TABLE testdb1.tbl1;"}'
);
-- Task for stage 10003 "Integration" to update database 7003 'testdb2'
@@ -193,5 +193,5 @@ VALUES
'Update testdb2',
'bb.task.database.schema.update',
'PENDING',
- '{"statement":"CREATE TABLE tbl1 (name TEXT);", "rollbackStatement":"DROP TABLE tbl1;"}'
+ '{"statement":"CREATE TABLE testdb2.tbl1 (name TEXT);", "rollbackStatement":"DROP TABLE testdb2.tbl1;"}'
);
\ No newline at end of file
diff --git a/backend/store/seed/0130_issue.sql b/backend/store/seed/0130_issue.sql
index f2ff9d170a..58fb656f00 100644
--- a/backend/store/seed/0130_issue.sql
+++ b/backend/store/seed/0130_issue.sql
@@ -11,8 +11,7 @@ INSERT INTO
`type`,
description,
assignee_id,
- subscriber_id_list,
- statement
+ subscriber_id_list
)
VALUES
(
@@ -26,8 +25,7 @@ VALUES
'bb.issue.general',
'Welcome to Bytebase, this is the issue interface where tech leads, developers and DBAs collaborate on database management issues such as: ' || char(10, 10) || ' - Requesting a new database' || char(10) || ' - Creating a table' || char(10) || ' - Creating an index' || char(10) || ' - Adding a column' || char(10) || ' - Troubleshooting performance issue' || char(10, 10) || 'Let''s bookmark this issue by clicking the star icon on the top of this page.' || char(10, 10) || 'And then click the ''Approve'' button on the top right.',
1001,
- '1001,1002,1003,1004',
- 'SELECT ''Welcome Tech Lead, DBA, Developer'';'
+ '1001,1002,1003,1004'
);
-- Issue for the multi stage add column pipeline
@@ -43,9 +41,7 @@ INSERT INTO
`type`,
description,
assignee_id,
- subscriber_id_list,
- statement,
- rollback_statement
+ subscriber_id_list
)
VALUES
(
@@ -59,9 +55,7 @@ VALUES
'bb.issue.database.schema.update',
'Add the location column to record the warehouse address.',
1001,
- '1001,1002,1003,1004',
- 'ALTER TABLE warehouse ' || char(10) || 'ADD COLUMN location VARCHAR(255);',
- 'ALTER TABLE warehouse ' || char(10) || 'DROP COLUMN location;'
+ '1001,1002,1003,1004'
);
-- Issue for the multi stage create table pipeline
@@ -77,9 +71,7 @@ INSERT INTO
`type`,
description,
assignee_id,
- subscriber_id_list,
- statement,
- rollback_statement
+ subscriber_id_list
)
VALUES
(
@@ -93,7 +85,5 @@ VALUES
'bb.issue.database.schema.update',
'Create tbl1.',
1001,
- '1001,1002,1003,1004',
- 'CREATE TABLE tbl1 (name TEXT);',
- 'DROP TABLE tbl1;'
+ '1001,1002,1003,1004'
);
\ No newline at end of file
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index 68fc517477..3c5519afde 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -27,12 +27,19 @@ function convertTaskRun(
): TaskRun {
const creator = taskRun.attributes.creator as Principal;
const updater = taskRun.attributes.updater as Principal;
+ const payload = taskRun.attributes.payload
+ ? JSON.parse(taskRun.attributes.payload as string)
+ : undefined;
return {
- ...(taskRun.attributes as Omit<TaskRun, "id" | "creator" | "updater">),
+ ...(taskRun.attributes as Omit<
+ TaskRun,
+ "id" | "creator" | "updater" | "payload"
+ >),
id: parseInt(taskRun.id),
creator,
updater,
+ payload,
};
}
@@ -43,6 +50,9 @@ function convertPartial(
): Omit<Task, "pipeline" | "stage"> {
const creator = task.attributes.creator as Principal;
const updater = task.attributes.updater as Principal;
+ const payload = task.attributes.payload
+ ? JSON.parse(task.attributes.payload as string)
+ : undefined;
const taskRunList: TaskRun[] = [];
const taskRunIdList = task.relationships!.taskRun
@@ -82,6 +92,7 @@ function convertPartial(
| "id"
| "creator"
| "updater"
+ | "payload"
| "database"
| "taskRunList"
| "pipeline"
@@ -90,6 +101,7 @@ function convertPartial(
id: parseInt(task.id),
creator,
updater,
+ payload,
database,
taskRunList,
};
diff --git a/frontend/src/types/issue.ts b/frontend/src/types/issue.ts
index e422ac9754..f3af4ff589 100644
--- a/frontend/src/types/issue.ts
+++ b/frontend/src/types/issue.ts
@@ -41,8 +41,6 @@ export type Issue = {
description: string;
assignee?: Principal;
subscriberList: Principal[];
- statement?: string;
- rollbackStatement?: string;
payload: IssuePayload;
};
diff --git a/frontend/src/types/pipeline.ts b/frontend/src/types/pipeline.ts
index 76a887c06f..d4445c0a72 100644
--- a/frontend/src/types/pipeline.ts
+++ b/frontend/src/types/pipeline.ts
@@ -196,8 +196,8 @@ export type TaskStatus =
| "CANCELED";
export type DatabaseSchemaUpdateTaskPayload = {
- sql: string;
- rollbackSql: string;
+ statement: string;
+ rollbackStatement: string;
};
export type TaskPayload = DatabaseSchemaUpdateTaskPayload;
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index c305eb2340..21b7ccc983 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -140,17 +140,17 @@
</div>
<div class="lg:hidden border-t border-block-border" />
<div class="w-full py-6 pr-4">
- <section v-if="showIssueStatementPanel" class="border-b mb-4">
- <IssueStatementPanel
- :issue="issue"
+ <section v-if="showIssueTaskStatementPanel" class="border-b mb-4">
+ <IssueTaskStatementPanel
+ :statement="selectedStatement"
:create="state.create"
:rollback="false"
@update-statement="updateStatement"
/>
</section>
<section v-if="showIssueRollbackSqlPanel" class="border-b mb-4">
- <IssueStatementPanel
- :issue="issue"
+ <IssueTaskStatementPanel
+ :statement="selectedRollbackStatement"
:create="state.create"
:rollback="true"
@update-statement="updateRollbackStatement"
@@ -208,7 +208,7 @@ import {
import IssueHighlightPanel from "../views/IssueHighlightPanel.vue";
import IssueStagePanel from "../views/IssueStagePanel.vue";
import IssueOutputPanel from "../views/IssueOutputPanel.vue";
-import IssueStatementPanel from "./IssueStatementPanel.vue";
+import IssueTaskStatementPanel from "./IssueTaskStatementPanel.vue";
import IssueDescriptionPanel from "./IssueDescriptionPanel.vue";
import IssueActivityPanel from "../views/IssueActivityPanel.vue";
import IssueSidebar from "../views/IssueSidebar.vue";
@@ -231,6 +231,7 @@ import {
TaskStatus,
IssueStatusPatch,
Task,
+ DatabaseSchemaUpdateTaskPayload,
} from "../types";
import {
defaulTemplate,
@@ -270,7 +271,7 @@ export default {
IssueHighlightPanel,
IssueStagePanel,
IssueOutputPanel,
- IssueStatementPanel,
+ IssueTaskStatementPanel,
IssueDescriptionPanel,
IssueActivityPanel,
IssueSidebar,
@@ -632,6 +633,30 @@ export default {
});
};
+ const selectedTask = computed((): Task => {
+ const stage = selectedStage.value;
+ return stage.taskList[0];
+ });
+
+ const selectedStatement = computed((): string => {
+ if (state.create) {
+ return "";
+ }
+
+ const task = selectedStage.value.taskList[0];
+ return (task.payload as DatabaseSchemaUpdateTaskPayload).statement;
+ });
+
+ const selectedRollbackStatement = computed((): string => {
+ if (state.create) {
+ return "";
+ }
+
+ const task = selectedStage.value.taskList[0];
+ return (task.payload as DatabaseSchemaUpdateTaskPayload)
+ .rollbackStatement;
+ });
+
const allowEditSidebar = computed(() => {
// For now, we only allow assignee to update the field when the issue
// is 'OPEN'. This reduces flexibility as creator must ask assignee to
@@ -692,7 +717,7 @@ export default {
return !state.create && issueTemplate.value.outputFieldList.length > 0;
});
- const showIssueStatementPanel = computed(() => {
+ const showIssueTaskStatementPanel = computed(() => {
return (
issue.value.type == "bb.issue.general" ||
issue.value.type == "bb.issue.database.schema.update"
@@ -721,6 +746,8 @@ export default {
issueTemplate,
selectedStage,
selectStageId,
+ selectedStatement,
+ selectedRollbackStatement,
allowEditSidebar,
allowEditOutput,
allowEditNameAndDescription,
@@ -730,7 +757,7 @@ export default {
showPendingApproval,
showPipelineFlowBar,
showIssueOutputPanel,
- showIssueStatementPanel,
+ showIssueTaskStatementPanel,
showIssueRollbackSqlPanel,
};
},
diff --git a/frontend/src/views/IssueStatementPanel.vue b/frontend/src/views/IssueTaskStatementPanel.vue
similarity index 87%
rename from frontend/src/views/IssueStatementPanel.vue
rename to frontend/src/views/IssueTaskStatementPanel.vue
index 51255bd575..e60ec7d2c4 100644
--- a/frontend/src/views/IssueStatementPanel.vue
+++ b/frontend/src/views/IssueTaskStatementPanel.vue
@@ -50,16 +50,7 @@
</template>
<script lang="ts">
-import {
- nextTick,
- onMounted,
- onUnmounted,
- PropType,
- ref,
- reactive,
- watch,
-} from "vue";
-import { Issue } from "../types";
+import { nextTick, onMounted, onUnmounted, ref, reactive, watch } from "vue";
import { sizeToFit } from "../utils";
interface LocalState {
@@ -68,12 +59,12 @@ interface LocalState {
}
export default {
- name: "IssueStatementPanel",
+ name: "IssueTaskStatementPanel",
emits: ["update-statement"],
props: {
- issue: {
+ statement: {
required: true,
- type: Object as PropType<Issue>,
+ type: String,
},
create: {
required: true,
@@ -88,13 +79,9 @@ export default {
setup(props, { emit }) {
const editStatementTextArea = ref();
- const effectiveStatement = (issue: Issue): string => {
- return (props.rollback ? issue.rollbackStatement : issue.statement) || "";
- };
-
const state = reactive<LocalState>({
editing: false,
- editStatement: effectiveStatement(props.issue),
+ editStatement: props.statement,
});
const resizeTextAreaHandler = () => {
@@ -127,6 +114,13 @@ export default {
}
);
+ watch(
+ () => props.statement,
+ (cur, _) => {
+ state.editStatement = cur;
+ }
+ );
+
return {
editStatementTextArea,
state,