Skip to content

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

chore: remove activity (#12194)

p0nyacd591fb59d6
diff --git a/backend/api/v1/plan_service.go b/backend/api/v1/plan_service.go
index 62a300980b..4ea495f52e 100644
--- a/backend/api/v1/plan_service.go
+++ b/backend/api/v1/plan_service.go
@@ -360,8 +360,7 @@ func (s *PlanService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlanRe
tasksMap := map[int]*store.TaskMessage{}
var taskPatchList []*api.TaskPatch
- var statementUpdates []api.ActivityPipelineTaskStatementUpdatePayload
- var earliestUpdates []api.ActivityPipelineTaskEarliestAllowedTimeUpdatePayload
+ var issueCommentCreates []*store.IssueCommentMessage
var taskDAGRebuildList []struct {
fromTaskIDs []int
toTaskID int
@@ -430,12 +429,18 @@ func (s *PlanService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlanRe
seconds := spec.EarliestAllowedTime.GetSeconds()
taskPatch.EarliestAllowedTs = &seconds
doUpdate = true
- earliestUpdates = append(earliestUpdates, api.ActivityPipelineTaskEarliestAllowedTimeUpdatePayload{
- TaskID: task.ID,
- OldEarliestAllowedTs: task.EarliestAllowedTs,
- NewEarliestAllowedTs: seconds,
- IssueName: issue.Title,
- TaskName: task.Name,
+
+ issueCommentCreates = append(issueCommentCreates, &store.IssueCommentMessage{
+ IssueUID: issue.UID,
+ Payload: &storepb.IssueCommentPayload{
+ Event: &storepb.IssueCommentPayload_TaskUpdate_{
+ TaskUpdate: &storepb.IssueCommentPayload_TaskUpdate{
+ Tasks: []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, task.StageID, task.ID)},
+ FromEarliestAllowedTime: timestamppb.New(time.Unix(task.EarliestAllowedTs, 0)),
+ ToEarliestAllowedTime: timestamppb.New(time.Unix(seconds, 0)),
+ },
+ },
+ },
})
}
@@ -540,14 +545,21 @@ func (s *PlanService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlanRe
return status.Errorf(codes.NotFound, "sheet %q not found", oldSheetName)
}
doUpdate = true
- // TODO(p0ny): update schema version
taskPatch.SheetID = &sheet.UID
- statementUpdates = append(statementUpdates, api.ActivityPipelineTaskStatementUpdatePayload{
- TaskID: task.ID,
- OldSheetID: taskPayload.SheetID,
- NewSheetID: sheet.UID,
- TaskName: task.Name,
- IssueName: issue.Title,
+
+ oldSheet := common.FormatSheet(issue.Project.ResourceID, taskPayload.SheetID)
+ newSheet := common.FormatSheet(issue.Project.ResourceID, sheet.UID)
+ issueCommentCreates = append(issueCommentCreates, &store.IssueCommentMessage{
+ IssueUID: issue.UID,
+ Payload: &storepb.IssueCommentPayload{
+ Event: &storepb.IssueCommentPayload_TaskUpdate_{
+ TaskUpdate: &storepb.IssueCommentPayload_TaskUpdate{
+ Tasks: []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, task.StageID, task.ID)},
+ FromSheet: &oldSheet,
+ ToSheet: &newSheet,
+ },
+ },
+ },
})
}
return nil
@@ -712,48 +724,9 @@ func (s *PlanService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlanRe
}
}
- for _, statementUpdate := range statementUpdates {
- task := tasksMap[statementUpdate.TaskID]
-
- if err := func() error {
- oldSheet := common.FormatSheet(issue.Project.ResourceID, statementUpdate.OldSheetID)
- newSheet := common.FormatSheet(issue.Project.ResourceID, statementUpdate.NewSheetID)
- _, err := s.store.CreateIssueComment(ctx, &store.IssueCommentMessage{
- IssueUID: issue.UID,
- Payload: &storepb.IssueCommentPayload{
- Event: &storepb.IssueCommentPayload_TaskUpdate_{
- TaskUpdate: &storepb.IssueCommentPayload_TaskUpdate{
- Tasks: []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, task.StageID, task.ID)},
- FromSheet: &oldSheet,
- ToSheet: &newSheet,
- },
- },
- },
- }, user.ID)
- return err
- }(); err != nil {
- slog.Warn("failed to create issue comments for statement update", "issueUID", issue.UID, log.BBError(err))
- }
- }
- for _, earliestUpdate := range earliestUpdates {
- task := tasksMap[earliestUpdate.TaskID]
-
- if err := func() error {
- _, err := s.store.CreateIssueComment(ctx, &store.IssueCommentMessage{
- IssueUID: issue.UID,
- Payload: &storepb.IssueCommentPayload{
- Event: &storepb.IssueCommentPayload_TaskUpdate_{
- TaskUpdate: &storepb.IssueCommentPayload_TaskUpdate{
- Tasks: []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, task.StageID, task.ID)},
- FromEarliestAllowedTime: timestamppb.New(time.Unix(earliestUpdate.OldEarliestAllowedTs, 0)),
- ToEarliestAllowedTime: timestamppb.New(time.Unix(earliestUpdate.NewEarliestAllowedTs, 0)),
- },
- },
- },
- }, user.ID)
- return err
- }(); err != nil {
- slog.Warn("failed to create issue comments for earliest allowed time update", "issueUID", issue.UID, log.BBError(err))
+ for _, issueCommentCreate := range issueCommentCreates {
+ if _, err := s.store.CreateIssueComment(ctx, issueCommentCreate, user.ID); err != nil {
+ slog.Warn("failed to create issue comments", "issueUID", issue.UID, log.BBError(err))
}
}
diff --git a/backend/legacyapi/activity.go b/backend/legacyapi/activity.go
index f11460e3f0..bbd28f3641 100644
--- a/backend/legacyapi/activity.go
+++ b/backend/legacyapi/activity.go
@@ -1,10 +1,5 @@
package api
-import (
- "github.com/bytebase/bytebase/backend/plugin/advisor"
- storepb "github.com/bytebase/bytebase/proto/generated-go/store"
-)
-
// ActivityType is the type for an activity.
type ActivityType string
@@ -84,200 +79,3 @@ const (
// Database related.
)
-
-// ActivityLevel is the level of activities.
-type ActivityLevel string
-
-const (
- // ActivityInfo is the INFO level of activities.
- ActivityInfo ActivityLevel = "INFO"
- // ActivityWarn is the WARN level of activities.
- ActivityWarn ActivityLevel = "WARN"
- // ActivityError is the ERROR level of activities.
- ActivityError ActivityLevel = "ERROR"
-)
-
-// ActivityIssueCreatePayload is the API message payloads for creating issues.
-// These payload types are only used when marshalling to the json format for saving into the database.
-// So we annotate with json tag using camelCase naming which is consistent with normal
-// json naming convention. More importantly, frontend code can simply use JSON.parse to
-// convert to the expected struct there.
-type ActivityIssueCreatePayload struct {
- IssueName string `json:"issueName"`
-}
-
-// TaskRollbackBy records an issue rollback activity.
-// The task with taskID in IssueID is rollbacked by the task with RollbackByTaskID in RollbackByIssueID.
-type TaskRollbackBy struct {
- IssueID int `json:"issueId"`
- TaskID int `json:"taskId"`
- RollbackByIssueID int `json:"rollbackByIssueId"`
- RollbackByTaskID int `json:"rollbackByTaskId"`
-}
-
-// ApprovalEvent duplicates store/approval.proto.
-type ApprovalEvent struct {
- Status string `json:"status"`
-}
-
-// ActivityIssueCommentCreatePayload is the API message payloads for creating issue comments.
-type ActivityIssueCommentCreatePayload struct {
- ExternalApprovalEvent *ExternalApprovalEvent `json:"externalApprovalEvent,omitempty"`
-
- TaskRollbackBy *TaskRollbackBy `json:"taskRollbackBy,omitempty"`
-
- ApprovalEvent *ApprovalEvent `json:"approvalEvent,omitempty"`
-
- IssueName string `json:"issueName"`
-}
-
-// ActivityIssueFieldUpdatePayload is the API message payloads for updating issue fields.
-type ActivityIssueFieldUpdatePayload struct {
- FieldID IssueFieldID `json:"fieldId"`
- OldValue string `json:"oldValue,omitempty"`
- NewValue string `json:"newValue,omitempty"`
- IssueName string `json:"issueName"`
-}
-
-// ActivityIssueStatusUpdatePayload is the API message payloads for updating issue status.
-type ActivityIssueStatusUpdatePayload struct {
- OldStatus IssueStatus `json:"oldStatus,omitempty"`
- NewStatus IssueStatus `json:"newStatus,omitempty"`
- IssueName string `json:"issueName"`
-}
-
-// ActivityIssueApprovalNotifyPayload is the API message payloads for notifying issue approval.
-type ActivityIssueApprovalNotifyPayload struct {
- // ProtoPayload is protojson.Marshal(storepb.ActivityIssueApprovalNotifyPayload).
- ProtoPayload string `json:"protoPayload,omitempty"`
-}
-
-// ActivityPipelineStageStatusUpdatePayload is the API message payloads for stage status updates.
-type ActivityPipelineStageStatusUpdatePayload struct {
- StageID int `json:"stageId"`
- StageStatusUpdateType StageStatusUpdateType `json:"stageStatusUpdateType"`
-
- IssueName string `json:"issueName"`
- StageName string `json:"stageName"`
-}
-
-// ActivityPipelineTaskStatusUpdatePayload is the API message payloads for updating pipeline task status.
-type ActivityPipelineTaskStatusUpdatePayload struct {
- TaskID int `json:"taskId"`
- OldStatus TaskStatus `json:"oldStatus,omitempty"`
- NewStatus TaskStatus `json:"newStatus,omitempty"`
- IssueName string `json:"issueName"`
- TaskName string `json:"taskName"`
-}
-
-type ActivityPipelineTaskRunStatusUpdatePayload struct {
- TaskID int `json:"taskId"`
- NewStatus TaskRunStatus `json:"newStatus,omitempty"`
- IssueName string `json:"issueName"`
- TaskName string `json:"taskName"`
-}
-
-// ActivityPipelineTaskStatementUpdatePayload is the API message payloads for pipeline task statement updates.
-type ActivityPipelineTaskStatementUpdatePayload struct {
- TaskID int `json:"taskId"`
- OldStatement string `json:"oldStatement,omitempty"`
- NewStatement string `json:"newStatement,omitempty"`
- OldSheetID int `json:"oldSheetId,omitempty"`
- NewSheetID int `json:"newSheetId,omitempty"`
- IssueName string `json:"issueName"`
- TaskName string `json:"taskName"`
-}
-
-// ActivityPipelineTaskEarliestAllowedTimeUpdatePayload is the API message payloads for pipeline task the earliest allowed time updates.
-type ActivityPipelineTaskEarliestAllowedTimeUpdatePayload struct {
- TaskID int `json:"taskId"`
- OldEarliestAllowedTs int64 `json:"oldEarliestAllowedTs,omitempty"`
- NewEarliestAllowedTs int64 `json:"newEarliestAllowedTs,omitempty"`
- IssueName string `json:"issueName"`
- TaskName string `json:"taskName"`
-}
-
-// ActivityPipelineTaskPriorBackupPayload is the API message payloads for pipeline task prior backup.
-type ActivityPipelineTaskPriorBackupPayload struct {
- TaskID int `json:"taskId"`
- BackupSchemaMetadata []SchemaMetadata `json:"schemaMetadata"`
-
- IssueName string `json:"issueName"`
- TaskName string `json:"taskName"`
-}
-
-// SchemaMetadata is the database schema metadata.
-type SchemaMetadata struct {
- Schema string `json:"schema,omitempty"`
- Table string `json:"table"`
-}
-
-// ActivityMemberCreatePayload is the API message payloads for creating members.
-type ActivityMemberCreatePayload struct {
- PrincipalID int `json:"principalId"`
- PrincipalName string `json:"principalName"`
- PrincipalEmail string `json:"principalEmail"`
- MemberStatus MemberStatus `json:"memberStatus"`
- Role Role `json:"role"`
-}
-
-// ActivityMemberRoleUpdatePayload is the API message payloads for updating member roles.
-type ActivityMemberRoleUpdatePayload struct {
- PrincipalID int `json:"principalId"`
- PrincipalName string `json:"principalName"`
- PrincipalEmail string `json:"principalEmail"`
- OldRole Role `json:"oldRole"`
- NewRole Role `json:"newRole"`
-}
-
-// ActivityMemberActivateDeactivatePayload is the API message payloads for activating or deactivating members.
-type ActivityMemberActivateDeactivatePayload struct {
- PrincipalID int `json:"principalId"`
- PrincipalName string `json:"principalName"`
- PrincipalEmail string `json:"principalEmail"`
- Role Role `json:"role"`
-}
-
-// ActivityProjectRepositoryPushPayload is the API message payloads for pushing repositories.
-type ActivityProjectRepositoryPushPayload struct {
- // Used by activity table to display info without paying the join cost
- // IssueID/IssueName only exist if the push event leads to the issue creation.
- IssueID int `json:"issueId,omitempty"`
- IssueName string `json:"issueName,omitempty"`
-}
-
-// ActivityProjectDatabaseTransferPayload is the API message payloads for transferring databases.
-type ActivityProjectDatabaseTransferPayload struct {
- DatabaseID int `json:"databaseId,omitempty"`
- // Used by activity table to display info without paying the join cost
- DatabaseName string `json:"databaseName,omitempty"`
-}
-
-// ActivitySQLEditorQueryPayload is the API message payloads for the executed query info.
-type ActivitySQLEditorQueryPayload struct {
- // Used by activity table to display info without paying the join cost
- Statement string `json:"statement"`
- DurationNs int64 `json:"durationNs"`
- InstanceID int `json:"instanceId"`
- DatabaseID int `json:"databaseId"`
- DatabaseName string `json:"databaseName"`
- Error string `json:"error"`
- AdviceList []advisor.Advice `json:"adviceList"`
-}
-
-// ActivitySQLExportPayload is the API message payloads for the exported SQL info.
-type ActivitySQLExportPayload struct {
- // Used by activity table to display info without paying the join cost
- Statement string `json:"statement"`
- DurationNs int64 `json:"durationNs"`
- InstanceID int `json:"instanceId"`
- DatabaseID int `json:"databaseId"`
- DatabaseName string `json:"databaseName"`
- Error string `json:"error"`
-}
-
-type ActivityNotifyPipelineRolloutPayload struct {
- RolloutPolicy *storepb.RolloutPolicy
- // Used to display info without paying the join cost
- StageName string
-}
diff --git a/backend/store/activity.go b/backend/store/activity.go
deleted file mode 100644
index 741c13e718..0000000000
--- a/backend/store/activity.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package store
-
-import (
- api "github.com/bytebase/bytebase/backend/legacyapi"
-)
-
-// ActivityMessage is the API message for activity.
-type ActivityMessage struct {
- UID int
- CreatedTs int64
- UpdatedTs int64
-
- // Related fields
- CreatorUID int
- UpdaterUID int
- ResourceContainer string
- // The object where this activity belongs
- // e.g if Type is "bb.issue.xxx", then this field refers to the corresponding issue's id.
- ContainerUID int
-
- // Domain specific fields
- Type api.ActivityType
- Level api.ActivityLevel
- Comment string
- Payload string
-}