Skip to content

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

chore: use project filter (#14966)

Danny Xu42737d4380ad
diff --git a/backend/api/v1/anomaly_service.go b/backend/api/v1/anomaly_service.go
index 6487c5297a..d9d9ea0188 100644
--- a/backend/api/v1/anomaly_service.go
+++ b/backend/api/v1/anomaly_service.go
@@ -42,8 +42,13 @@ func NewAnomalyService(store *store.Store) *AnomalyService {
func (s *AnomalyService) SearchAnomalies(ctx context.Context, request *v1pb.SearchAnomaliesRequest) (*v1pb.
SearchAnomaliesResponse, error,
) {
+ projectID, err := common.GetProjectID(request.Parent)
+ if err != nil {
+ return nil, status.Error(codes.InvalidArgument, err.Error())
+ }
rowStatus := api.Normal
find := &store.ListAnomalyMessage{
+ ProjectID: projectID,
RowStatus: &rowStatus,
}
if request.Filter != "" {
diff --git a/backend/store/anomaly.go b/backend/store/anomaly.go
index e8f94c0a16..d6510ce8db 100644
--- a/backend/store/anomaly.go
+++ b/backend/store/anomaly.go
@@ -66,6 +66,7 @@ func (s *Store) UpsertActiveAnomalyV2(ctx context.Context, principalUID int, ups
status := api.Normal
find := &ListAnomalyMessage{
+ ProjectID: upsert.ProjectID,
RowStatus: &status,
InstanceID: &upsert.InstanceID,
DatabaseUID: upsert.DatabaseUID,
@@ -246,6 +247,7 @@ func (s *Store) createAnomalyImplV2(ctx context.Context, tx *Tx, principalUID in
func (*Store) listAnomalyImplV2(ctx context.Context, tx *Tx, list *ListAnomalyMessage) ([]*AnomalyMessage, error) {
where, args := []string{"TRUE"}, []any{}
+ where, args = append(where, fmt.Sprintf("anomaly.project = $%d", len(args)+1)), append(args, list.ProjectID)
if v := list.RowStatus; v != nil {
where, args = append(where, fmt.Sprintf("anomaly.row_status = $%d", len(args)+1)), append(args, *v)
}