Skip to content

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

Respect project=xxx in the GET /database endpoint

天舟10c6bff89782
diff --git a/backend/api/database.go b/backend/api/database.go
index 6bec1d3121..2daacae57a 100644
--- a/backend/api/database.go
+++ b/backend/api/database.go
@@ -76,6 +76,7 @@ type DatabaseFind struct {
// Related fields
InstanceId *int
+ ProjectId *int
// Domain specific fields
IncludeAllDatabase bool
diff --git a/backend/server/database.go b/backend/server/database.go
index b0fb6ae5f7..ef23eea7f0 100644
--- a/backend/server/database.go
+++ b/backend/server/database.go
@@ -53,6 +53,14 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
}
databaseFind.InstanceId = &instanceId
}
+ projectIdStr := c.QueryParams().Get("project")
+ if projectIdStr != "" {
+ projectId, err := strconv.Atoi(projectIdStr)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("project query parameter is not a number: %s", projectIdStr)).SetInternal(err)
+ }
+ databaseFind.ProjectId = &projectId
+ }
list, err := s.DatabaseService.FindDatabaseList(context.Background(), databaseFind)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch database list").SetInternal(err)
diff --git a/backend/store/database.go b/backend/store/database.go
index af4046ca3a..7838723d12 100644
--- a/backend/store/database.go
+++ b/backend/store/database.go
@@ -167,6 +167,9 @@ func (s *DatabaseService) findDatabaseList(ctx context.Context, tx *Tx, find *ap
if v := find.InstanceId; v != nil {
where, args = append(where, "instance_id = ?"), append(args, *v)
}
+ if v := find.ProjectId; v != nil {
+ where, args = append(where, "project_id = ?"), append(args, *v)
+ }
if !find.IncludeAllDatabase {
where = append(where, "name != '"+api.ALL_DATABASE_NAME+"'")
}