Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: include environment in database labels (#245)
p0ny04f0381547e9
diff --git a/api/issue.go b/api/issue.goindex 2f89f283a9..84675dd74d 100644--- a/api/issue.go+++ b/api/issue.go@@ -108,7 +108,7 @@ type IssueCreate struct {Payload string `jsonapi:"attr,payload"`// CreateContext is used to create the issue pipeline and not persisted.// The context format depends on the issue type. For example, create database issue corresponds to CreateDatabaseContext.- // This consoliates the pipeline generation to backend because both frontend and VCS pipeline could create issues and+ // This consolidates the pipeline generation to backend because both frontend and VCS pipeline could create issues and// we want the complexity resides in the backend.CreateContext string `jsonapi:"attr,createContext"`@@ -182,7 +182,7 @@ type IssuePatch struct {// Domain specific fieldsName *string `jsonapi:"attr,name"`- // Status is only set manualy via IssueStatusPatch+ // Status is only set manually via IssueStatusPatchStatus *IssueStatusDescription *string `jsonapi:"attr,description"`AssigneeID *int `jsonapi:"attr,assigneeId"`diff --git a/api/label.go b/api/label.goindex 72b39585a3..c13b4b0e8d 100644--- a/api/label.go+++ b/api/label.go@@ -4,6 +4,11 @@ import ("context")+const (+ // EnvironmentKeyName is the reserved key for environment.+ EnvironmentKeyName string = "bb.environment"+)+// LabelKey is the available key for labels.type LabelKey struct {ID int `jsonapi:"primary,labelKey"`diff --git a/server/database.go b/server/database.goindex 743351322f..a9377c299e 100644--- a/server/database.go+++ b/server/database.go@@ -77,7 +77,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {var filteredList []*api.Databaserole := c.Get(getRoleContextKey()).(api.Role)- // If caller is NOT requesting for a particular project and is NOT requesting for a paritcular+ // If caller is NOT requesting for a particular project and is NOT requesting for a particular// instance or the caller is a Developer, then we will only return databases belonging to the// project where the caller is a member of.// Looking from the UI perspective:@@ -199,7 +199,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {DatabaseName: database.Name,})if err == nil {- existingDatabase.Project, err = s.composeProjectlByID(ctx, existingDatabase.ProjectID)+ existingDatabase.Project, err = s.composeProjectByID(ctx, existingDatabase.ProjectID)if err == nil {activityCreate := &api.ActivityCreate{CreatorID: c.Get(getPrincipalIDContextKey()).(int),@@ -662,7 +662,7 @@ func (s *Server) composeDatabaseRelationship(ctx context.Context, database *api.return err}- database.Project, err = s.composeProjectlByID(ctx, database.ProjectID)+ database.Project, err = s.composeProjectByID(ctx, database.ProjectID)if err != nil {return err}@@ -701,7 +701,7 @@ func (s *Server) composeDatabaseRelationship(ctx context.Context, database *api.}rowStatus = api.Normal- labels, err := s.LabelService.FindDatabaseLabelList(ctx, &api.DatabaseLabelFind{+ labelList, err := s.LabelService.FindDatabaseLabelList(ctx, &api.DatabaseLabelFind{DatabaseID: &database.ID,RowStatus: &rowStatus,})@@ -709,13 +709,23 @@ func (s *Server) composeDatabaseRelationship(ctx context.Context, database *api.return err}- if len(labels) > 0 {- labels, err := json.Marshal(labels)- if err != nil {- return err- }- database.Labels = string(labels)+ // Since tenants are identified by labels in deployment config, we need an environment+ // label to identify tenants from different environment in a schema update deployment.+ // If we expose the environment label concept in the deployment config, it should look consistent in the label API.++ // Each database instance is created under a particular environment.+ // The value of bb.environment is identical to the name of the environment.++ labelList = append(labelList, &api.DatabaseLabel{+ Key: api.EnvironmentKeyName,+ Value: database.Instance.Environment.Name,+ })++ labels, err := json.Marshal(labelList)+ if err != nil {+ return err}+ database.Labels = string(labels)return nil}diff --git a/server/issue.go b/server/issue.goindex 25279782dc..95c6b043f0 100644--- a/server/issue.go+++ b/server/issue.go@@ -297,7 +297,7 @@ func (s *Server) composeIssueRelationship(ctx context.Context, issue *api.Issue)issue.SubscriberIDList = append(issue.SubscriberIDList, subscriber.SubscriberID)}- issue.Project, err = s.composeProjectlByID(ctx, issue.ProjectID)+ issue.Project, err = s.composeProjectByID(ctx, issue.ProjectID)if err != nil {return err}diff --git a/server/project.go b/server/project.goindex 426642614d..1560e00f08 100644--- a/server/project.go+++ b/server/project.go@@ -99,7 +99,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("projectID"))).SetInternal(err)}- project, err := s.composeProjectlByID(ctx, id)+ project, err := s.composeProjectByID(ctx, id)if err != nil {if common.ErrorCode(err) == common.NotFound {return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project ID not found: %d", id))@@ -489,7 +489,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {}deploymentConfigUpsert.UpdaterID = c.Get(getPrincipalIDContextKey()).(int)- if _, err := s.composeProjectlByID(ctx, id); err != nil {+ if _, err := s.composeProjectByID(ctx, id); err != nil {if common.ErrorCode(err) == common.NotFound {return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project ID not found: %d", id))}@@ -516,7 +516,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)}- if _, err := s.composeProjectlByID(ctx, id); err != nil {+ if _, err := s.composeProjectByID(ctx, id); err != nil {if common.ErrorCode(err) == common.NotFound {return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project ID not found: %d", id))}@@ -539,7 +539,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {})}-func (s *Server) composeProjectlByID(ctx context.Context, id int) (*api.Project, error) {+func (s *Server) composeProjectByID(ctx context.Context, id int) (*api.Project, error) {projectFind := &api.ProjectFind{ID: &id,}diff --git a/server/repository.go b/server/repository.goindex 7ccbe639dd..f9698bf84d 100644--- a/server/repository.go+++ b/server/repository.go@@ -24,7 +24,7 @@ func (s *Server) composeRepositoryRelationship(ctx context.Context, repository *return err}- repository.Project, err = s.composeProjectlByID(ctx, repository.ProjectID)+ repository.Project, err = s.composeProjectByID(ctx, repository.ProjectID)if err != nil {return err}