Skip to content

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

feat: added activity log for altering statement (#207)

Luke Zhou626a82fbb9f6
diff --git a/api/activity.go b/api/activity.go
index b9f3513d6c..56fda0fb98 100644
--- a/api/activity.go
+++ b/api/activity.go
@@ -25,6 +25,8 @@ const (
ActivityPipelineTaskStatusUpdate ActivityType = "bb.pipeline.task.status.update"
// ActivityPipelineTaskFileCommit is the type for committing pipeline task file.
ActivityPipelineTaskFileCommit ActivityType = "bb.pipeline.task.file.commit"
+ // ActivityPipelineTaskStatementUpdate is the type for updating pipeline task SQL statement.
+ ActivityPipelineTaskStatementUpdate ActivityType = "bb.pipeline.task.statement.update"
// Member related
@@ -65,6 +67,8 @@ func (e ActivityType) String() string {
return "bb.pipeline.task.status.update"
case ActivityPipelineTaskFileCommit:
return "bb.pipeline.task.file.commit"
+ case ActivityPipelineTaskStatementUpdate:
+ return "bb.pipeline.task.statement.update"
case ActivityMemberCreate:
return "bb.member.create"
case ActivityMemberRoleUpdate:
@@ -166,6 +170,16 @@ type ActivityPipelineTaskFileCommitPayload struct {
CommitID string `json:"commitId,omitempty"`
}
+// ActivityPipelineTaskStatementUpdatePayload
+type ActivityPipelineTaskStatementUpdatePayload struct {
+ TaskID int `json:"taskId"`
+ OldStatement string `json:"oldStatement,omitempty"`
+ NewStatement string `json:"newStatement,omitempty"`
+ // Used by inbox to display info without paying the join cost
+ IssueName string `json:"issueName"`
+ TaskName string `json:"taskName"`
+}
+
// ActivityMemberCreatePayload is the API message payloads for creating members.
type ActivityMemberCreatePayload struct {
PrincipalID int `json:"principalId"`
diff --git a/frontend/src/components/InboxList.vue b/frontend/src/components/InboxList.vue
index 7217064dbd..5cee54d087 100644
--- a/frontend/src/components/InboxList.vue
+++ b/frontend/src/components/InboxList.vue
@@ -60,6 +60,7 @@ import {
ActivityIssueFieldUpdatePayload,
ActivityIssueStatusUpdatePayload,
ActivityTaskStatusUpdatePayload,
+ ActivityTaskStatementUpdatePayload,
Activity,
Inbox,
} from "../types";
@@ -125,34 +126,46 @@ export default defineComponent({
}
}
return actionStr;
- } else if (activity.type == "bb.pipeline.task.status.update") {
- const payload = activity.payload as ActivityTaskStatusUpdatePayload;
- let actionStr = t(`activity.sentence.changed`);
- switch (payload.newStatus) {
- case "PENDING": {
- if (payload.oldStatus == "RUNNING") {
- actionStr = t(`activity.sentence.canceled`);
- } else if (payload.oldStatus == "PENDING_APPROVAL") {
- actionStr = t(`activity.sentence.approved`);
+ }
+ switch (activity.type) {
+ case "bb.pipeline.task.status.update": {
+ const payload = activity.payload as ActivityTaskStatusUpdatePayload;
+ let actionStr = t(`activity.sentence.changed`);
+ switch (payload.newStatus) {
+ case "PENDING": {
+ if (payload.oldStatus == "RUNNING") {
+ actionStr = t(`activity.sentence.canceled`);
+ } else if (payload.oldStatus == "PENDING_APPROVAL") {
+ actionStr = t(`activity.sentence.approved`);
+ }
+ break;
+ }
+ case "RUNNING": {
+ actionStr = t(`activity.sentence.started`);
+ break;
+ }
+ case "DONE": {
+ actionStr = t(`activity.sentence.completed`);
+ break;
+ }
+ case "FAILED": {
+ actionStr = t(`activity.sentence.failed`);
+ break;
}
- break;
- }
- case "RUNNING": {
- actionStr = t(`activity.sentence.started`);
- break;
- }
- case "DONE": {
- actionStr = t(`activity.sentence.completed`);
- break;
- }
- case "FAILED": {
- actionStr = t(`activity.sentence.failed`);
- break;
}
+ return `${t("activity.subject-prefix.task")} '${
+ payload.taskName
+ }' ${actionStr} - '${payload?.issueName || ""}'`;
+ }
+ case "bb.pipeline.task.statement.update": {
+ const payload =
+ activity.payload as ActivityTaskStatementUpdatePayload;
+ return t("activity.sentence.changed-from-to", {
+ name: "SQL",
+ oldValue: payload.oldStatement,
+ newValue: payload.newStatement,
+ });
}
- return `${t("activity.subject-prefix.task")} '${
- payload.taskName
- }' ${actionStr} - '${payload?.issueName || ""}'`;
}
return "";
diff --git a/frontend/src/components/IssueActivityPanel.vue b/frontend/src/components/IssueActivityPanel.vue
index 67727b7967..f7586394bf 100644
--- a/frontend/src/components/IssueActivityPanel.vue
+++ b/frontend/src/components/IssueActivityPanel.vue
@@ -349,6 +349,7 @@ import {
Activity,
ActivityIssueFieldUpdatePayload,
ActivityTaskStatusUpdatePayload,
+ ActivityTaskStatementUpdatePayload,
UNKNOWN_ID,
EMPTY_ID,
SYSTEM_BOT_ID,
@@ -667,6 +668,15 @@ export default defineComponent({
repo: payload.repositoryFullPath,
});
}
+ case "bb.pipeline.task.statement.update": {
+ const payload =
+ activity.payload as ActivityTaskStatementUpdatePayload;
+ return t("activity.sentence.changed-from-to", {
+ name: "SQL",
+ oldValue: payload.oldStatement,
+ newValue: payload.newStatement,
+ });
+ }
}
return "";
};
diff --git a/frontend/src/types/activity.ts b/frontend/src/types/activity.ts
index f28b9f813f..ddb406b6d0 100644
--- a/frontend/src/types/activity.ts
+++ b/frontend/src/types/activity.ts
@@ -12,7 +12,8 @@ export type IssueActivityType =
| "bb.issue.field.update"
| "bb.issue.status.update"
| "bb.pipeline.task.status.update"
- | "bb.pipeline.task.file.commit";
+ | "bb.pipeline.task.file.commit"
+ | "bb.pipeline.task.statement.update";
export type MemberActivityType =
| "bb.member.create"
@@ -46,6 +47,8 @@ export function activityName(type: ActivityType): string {
return "Update issue task status";
case "bb.pipeline.task.file.commit":
return "Commit file";
+ case "bb.pipeline.task.statement.update":
+ return "SQL update";
case "bb.member.create":
return "Create member";
case "bb.member.role.update":
@@ -108,6 +111,14 @@ export type ActivityTaskFileCommitPayload = {
commitId: string;
};
+export type ActivityTaskStatementUpdatePayload = {
+ taskId: TaskId;
+ oldStatement: string;
+ newStatement: string;
+ issueName: string;
+ taskName: string;
+};
+
export type ActivityMemberCreatePayload = {
principalId: PrincipalId;
principalName: string;
diff --git a/server/activity_manager.go b/server/activity_manager.go
index bfeef5ce0a..78bc9f26b0 100644
--- a/server/activity_manager.go
+++ b/server/activity_manager.go
@@ -274,6 +274,8 @@ func shouldPostInbox(activity *api.Activity, createType api.ActivityType) (bool,
return true, nil
case api.ActivityIssueFieldUpdate:
return true, nil
+ case api.ActivityPipelineTaskStatementUpdate:
+ return true, nil
case api.ActivityPipelineTaskStatusUpdate:
update := new(api.ActivityPipelineTaskStatusUpdatePayload)
if err := json.Unmarshal([]byte(activity.Payload), update); err != nil {
diff --git a/server/task.go b/server/task.go
index 210269e2fc..62513dcf94 100644
--- a/server/task.go
+++ b/server/task.go
@@ -81,6 +81,51 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to update task \"%v\"", task.Name)).SetInternal(err)
}
+ // we only create an activity for statement update for now
+ if updatedTask.Type == api.TaskDatabaseSchemaUpdate {
+ oldPayload := &api.TaskDatabaseSchemaUpdatePayload{}
+ newPayload := &api.TaskDatabaseSchemaUpdatePayload{}
+ if err := json.Unmarshal([]byte(updatedTask.Payload), oldPayload); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity after updating task statement: %v", updatedTask.Name).SetInternal(err)
+ }
+ if err := json.Unmarshal([]byte(task.Payload), newPayload); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity after updating task statement: %v", updatedTask.Name).SetInternal(err)
+ }
+ if oldPayload.Statement != newPayload.Statement {
+ issueFind := &api.IssueFind{
+ PipelineID: &task.PipelineID,
+ }
+ issue, err := s.IssueService.FindIssue(ctx, issueFind)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID after updating task statement: %v", task.PipelineID)).SetInternal(err)
+ }
+
+ payload, err := json.Marshal(api.ActivityPipelineTaskStatementUpdatePayload{
+ TaskID: updatedTask.ID,
+ OldStatement: oldPayload.Statement,
+ NewStatement: newPayload.Statement,
+ TaskName: task.Name,
+ IssueName: issue.Name,
+ })
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity after updating task statement: %v", updatedTask.Name).SetInternal(err)
+ }
+ activityCreate := &api.ActivityCreate{
+ CreatorID: updatedTask.CreatorID,
+ ContainerID: issue.ID,
+ Type: api.ActivityPipelineTaskStatementUpdate,
+ Level: api.ActivityInfo,
+ Payload: string(payload),
+ }
+ _, err = s.ActivityManager.CreateActivity(ctx, activityCreate, &ActivityMeta{
+ issue: issue,
+ })
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to create activity after updating task statement: %v", updatedTask.Name)).SetInternal(err)
+ }
+ }
+ }
+
if err := s.composeTaskRelationship(ctx, updatedTask); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch updated task \"%v\" relationship", updatedTask.Name)).SetInternal(err)
}