Skip to content

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

chore: resource_container for sql activity (#11216)

Danny Xu32644cc044f7
diff --git a/backend/api/v1/logging_service.go b/backend/api/v1/logging_service.go
index 64a3dc5e79..8316c444ee 100644
--- a/backend/api/v1/logging_service.go
+++ b/backend/api/v1/logging_service.go
@@ -40,7 +40,7 @@ var defaultResourceActionTypeMap = map[string][]api.ActivityType{
api.ActivityMemberDeactivate,
},
"instances": {
- api.ActivitySQLEditorQuery,
+ api.ActivitySQLQuery,
api.ActivitySQLExport,
},
"projects": {
@@ -401,7 +401,7 @@ func convertToLogEntity(ctx context.Context, db *store.Store, activity *store.Ac
}
resource = fmt.Sprintf("%s%s", common.ProjectNamePrefix, project.ResourceID)
case
- api.ActivitySQLEditorQuery,
+ api.ActivitySQLQuery,
api.ActivitySQLExport:
instance, err := db.GetInstanceV2(ctx, &store.FindInstanceMessage{
UID: &activity.ContainerUID,
@@ -483,7 +483,7 @@ func convertToActivityType(action v1pb.LogEntity_Action) (api.ActivityType, erro
return api.ActivityProjectMemberDelete, nil
case v1pb.LogEntity_ACTION_DATABASE_SQL_EDITOR_QUERY:
- return api.ActivitySQLEditorQuery, nil
+ return api.ActivitySQLQuery, nil
case v1pb.LogEntity_ACTION_DATABASE_SQL_EXPORT:
return api.ActivitySQLExport, nil
default:
@@ -536,7 +536,7 @@ func convertToActionType(activityType api.ActivityType) v1pb.LogEntity_Action {
return v1pb.LogEntity_ACTION_PROJECT_MEMBER_CREATE
case api.ActivityProjectMemberDelete:
return v1pb.LogEntity_ACTION_PROJECT_MEMBER_DELETE
- case api.ActivitySQLEditorQuery:
+ case api.ActivitySQLQuery:
return v1pb.LogEntity_ACTION_DATABASE_SQL_EDITOR_QUERY
case api.ActivitySQLExport:
return v1pb.LogEntity_ACTION_DATABASE_SQL_EXPORT
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index 687c20d376..a45794b83f 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -2415,7 +2415,7 @@ func convertToActivityTypeStrings(types []v1pb.Activity_Type) ([]string, error)
case v1pb.Activity_TYPE_PROJECT_MEMBER_DELETE:
result = append(result, string(api.ActivityProjectMemberDelete))
case v1pb.Activity_TYPE_SQL_EDITOR_QUERY:
- result = append(result, string(api.ActivitySQLEditorQuery))
+ result = append(result, string(api.ActivitySQLQuery))
case v1pb.Activity_TYPE_NOTIFY_ISSUE_APPROVED:
result = append(result, string(api.ActivityNotifyIssueApproved))
case v1pb.Activity_TYPE_NOTIFY_PIPELINE_ROLLOUT:
@@ -2469,7 +2469,7 @@ func convertNotificationTypeStrings(types []string) []v1pb.Activity_Type {
result = append(result, v1pb.Activity_TYPE_PROJECT_MEMBER_CREATE)
case string(api.ActivityProjectMemberDelete):
result = append(result, v1pb.Activity_TYPE_PROJECT_MEMBER_DELETE)
- case string(api.ActivitySQLEditorQuery):
+ case string(api.ActivitySQLQuery):
result = append(result, v1pb.Activity_TYPE_SQL_EDITOR_QUERY)
case string(api.ActivityNotifyIssueApproved):
result = append(result, v1pb.Activity_TYPE_NOTIFY_ISSUE_APPROVED)
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index 74ea29ed8e..586a35285f 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -1315,7 +1315,7 @@ func (s *SQLService) createQueryActivity(ctx context.Context, user *store.UserMe
}
activityCreate := &store.ActivityMessage{
CreatorUID: user.ID,
- Type: api.ActivitySQLEditorQuery,
+ Type: api.ActivitySQLQuery,
ResourceContainer: fmt.Sprintf("projects/%s", projectID),
ContainerUID: containerID,
Level: level,
diff --git a/backend/legacyapi/activity.go b/backend/legacyapi/activity.go
index 34a62d1fed..8de0204987 100644
--- a/backend/legacyapi/activity.go
+++ b/backend/legacyapi/activity.go
@@ -70,11 +70,8 @@ const (
// SQL Editor related.
- // ActivitySQLEditorQuery is the type for executing query.
- ActivitySQLEditorQuery ActivityType = "bb.sql-editor.query"
-
- // SQL related.
-
+ // ActivitySQLQuery is the type for executing query.
+ ActivitySQLQuery ActivityType = "bb.sql.query"
// ActivitySQLExport is the type for exporting SQL.
ActivitySQLExport ActivityType = "bb.sql.export"
diff --git a/backend/migrator/migration/prod/2.15/0001##activity_container.sql b/backend/migrator/migration/prod/2.15/0001##activity_container.sql
index 75a8d946e4..5fac86c8aa 100644
--- a/backend/migrator/migration/prod/2.15/0001##activity_container.sql
+++ b/backend/migrator/migration/prod/2.15/0001##activity_container.sql
@@ -5,3 +5,6 @@ DELETE FROM activity WHERE type = 'bb.database.recovery.pitr.done';
UPDATE activity SET resource_container = 'projects/' || coalesce((SELECT resource_id FROM project WHERE project.id = activity.container_id), 'default') WHERE type LIKE '%project%';
UPDATE activity SET resource_container = 'projects/' || coalesce((SELECT project.resource_id FROM project JOIN issue ON project.id = issue.project_id WHERE issue.id = activity.container_id), 'default') WHERE type LIKE '%issue%';
UPDATE activity SET resource_container = 'projects/' || coalesce((SELECT project.resource_id FROM project JOIN pipeline ON project.id = pipeline.project_id WHERE pipeline.id = activity.container_id), 'default') WHERE type LIKE '%pipeline%';
+UPDATE activity SET type = 'bb.sql.query' WHERE type = 'bb.sql-editor.query';
+UPDATE activity SET resource_container = 'projects/' || coalesce((SELECT project.resource_id FROM project JOIN db ON project.id = db.project_id WHERE (db.id)::text = (activity.payload->'databaseId')::text), 'default') WHERE type LIKE '%sql%' AND (payload ? 'databaseId');
+UPDATE activity SET resource_container = 'projects/default' WHERE type LIKE '%sql%' AND resource_container='';