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(tenancy): add name field to deployment (#324)
spinningbotcb5b90696aba
diff --git a/api/deploy.go b/api/deploy.goindex 840280a3d1..fd68a3ce82 100644--- a/api/deploy.go+++ b/api/deploy.go@@ -37,6 +37,7 @@ type DeploymentSchedule struct {// Deployment is the API message for deployment.type Deployment struct {+ Name string `json:"name"`Spec *DeploymentSpec `json:"spec"`}@@ -116,6 +117,9 @@ func ValidateAndGetDeploymentSchedule(payload string) (*DeploymentSchedule, erro}for _, d := range schedule.Deployments {+ if d.Name == "" {+ return nil, common.Errorf(common.Invalid, fmt.Errorf("Deployment name must not be empty"))+ }hasEnv := falsefor _, e := range d.Spec.Selector.MatchExpressions {switch e.Operator {diff --git a/server/deploy.go b/server/deploy.goindex eb4871f4f7..aafe7643cc 100644--- a/server/deploy.go+++ b/server/deploy.go@@ -45,8 +45,9 @@ func isMatchExpressions(labels map[string]string, expressionList []*api.LabelSel// getDatabaseMatrixFromDeploymentSchedule gets a pipeline based on deployment schedule.// The returned matrix doesn't include deployment with no matched database.-func getDatabaseMatrixFromDeploymentSchedule(schedule *api.DeploymentSchedule, name string, databaseList []*api.Database) ([][]*api.Database, error) {+func getDatabaseMatrixFromDeploymentSchedule(schedule *api.DeploymentSchedule, name string, databaseList []*api.Database) ([]*api.Deployment, [][]*api.Database, error) {var pipeline [][]*api.Database+ var deployments []*api.Deployment// idToLabels maps databaseID -> label.Key -> label.ValueidToLabels := make(map[int]map[string]string)@@ -58,7 +59,7 @@ func getDatabaseMatrixFromDeploymentSchedule(schedule *api.DeploymentSchedule, n}var labelList []*api.DatabaseLabelif err := json.Unmarshal([]byte(database.Labels), &labelList); err != nil {- return nil, err+ return nil, nil, err}for _, label := range labelList {idToLabels[database.ID][label.Key] = label.Value@@ -97,8 +98,9 @@ func getDatabaseMatrixFromDeploymentSchedule(schedule *api.DeploymentSchedule, nif len(stage) > 0 {pipeline = append(pipeline, stage)+ deployments = append(deployments, deployment)}}- return pipeline, nil+ return deployments, pipeline, nil}diff --git a/server/deploy_test.go b/server/deploy_test.goindex de859a52e7..4774eab09d 100644--- a/server/deploy_test.go+++ b/server/deploy_test.go@@ -199,7 +199,7 @@ func TestGetDatabaseMatrixFromDeploymentSchedule(t *testing.T) {}for _, test := range tests {- create, _ := getDatabaseMatrixFromDeploymentSchedule(test.schedule, test.databaseName, test.databaseList)+ _, create, _ := getDatabaseMatrixFromDeploymentSchedule(test.schedule, test.databaseName, test.databaseList)diff := pretty.Diff(create, test.want)if len(diff) > 0 {diff --git a/server/issue.go b/server/issue.goindex a729938f9d..2bf18bed43 100644--- a/server/issue.go+++ b/server/issue.go@@ -754,7 +754,7 @@ func (s *Server) createPipelineFromIssue(ctx context.Context, issueCreate *api.Iif err != nil {return nil, echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch databases in project ID: %v", issueCreate.ProjectID)).SetInternal(err)}- p, err := s.getTenantDatabaseMatrix(ctx, issueCreate.ProjectID, databaseList, d.DatabaseName)+ deployments, p, err := s.getTenantDatabaseMatrix(ctx, issueCreate.ProjectID, databaseList, d.DatabaseName)if err != nil {return nil, err}@@ -783,7 +783,7 @@ func (s *Server) createPipelineFromIssue(ctx context.Context, issueCreate *api.I}pc.StageList = append(pc.StageList, api.StageCreate{- Name: fmt.Sprintf("Deployment %v", i),+ Name: fmt.Sprintf("Deployment: %s", deployments[i].Name),EnvironmentID: environmentID,TaskList: taskCreateList,})@@ -1037,30 +1037,30 @@ func (s *Server) postInboxIssueActivity(ctx context.Context, issue *api.Issue, areturn nil}-func (s *Server) getTenantDatabaseMatrix(ctx context.Context, projectID int, databaseList []*api.Database, databaseName string) ([][]*api.Database, error) {+func (s *Server) getTenantDatabaseMatrix(ctx context.Context, projectID int, databaseList []*api.Database, databaseName string) ([]*api.Deployment, [][]*api.Database, error) {deployConfig, err := s.DeploymentConfigService.FindDeploymentConfig(ctx, &api.DeploymentConfigFind{ProjectID: &projectID,})if err != nil {- return nil, echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch deployment config for project ID: %v", projectID)).SetInternal(err)+ return nil, nil, echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch deployment config for project ID: %v", projectID)).SetInternal(err)}if deployConfig == nil {- return nil, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Deployment config missing for project ID: %v", projectID)).SetInternal(err)+ return nil, nil, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Deployment config missing for project ID: %v", projectID)).SetInternal(err)}deploySchedule, err := api.ValidateAndGetDeploymentSchedule(deployConfig.Payload)if err != nil {- return nil, echo.NewHTTPError(http.StatusInternalServerError, "Failed to get deployment schedule").SetInternal(err)+ return nil, nil, echo.NewHTTPError(http.StatusInternalServerError, "Failed to get deployment schedule").SetInternal(err)}for _, database := range databaseList {if err := s.composeDatabaseRelationship(ctx, database); err != nil {- return nil, echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to compose database relationship for database ID %v", database.ID)).SetInternal(err)+ return nil, nil, echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to compose database relationship for database ID %v", database.ID)).SetInternal(err)}}- p, err := getDatabaseMatrixFromDeploymentSchedule(deploySchedule, databaseName, databaseList)+ d, p, err := getDatabaseMatrixFromDeploymentSchedule(deploySchedule, databaseName, databaseList)if err != nil {- return nil, echo.NewHTTPError(http.StatusInternalServerError, "Failed to create deployment pipeline").SetInternal(err)+ return nil, nil, echo.NewHTTPError(http.StatusInternalServerError, "Failed to create deployment pipeline").SetInternal(err)}- return p, nil+ return d, p, nil}// getSchemaFromPeerTenantDatabase gets the schema version and schema from a peer tenant database.@@ -1076,7 +1076,7 @@ func (s *Server) getSchemaFromPeerTenantDatabase(ctx context.Context, instance *return "", "", echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch databases in project ID: %v", projectID)).SetInternal(err)}- pipeline, err := s.getTenantDatabaseMatrix(ctx, projectID, databaseList, databaseName)+ _, pipeline, err := s.getTenantDatabaseMatrix(ctx, projectID, databaseList, databaseName)if err != nil {return "", "", err}diff --git a/store/seed/test/10210__deployment_config.sql b/store/seed/test/10210__deployment_config.sqlindex 48232c6b31..30cd909280 100644--- a/store/seed/test/10210__deployment_config.sql+++ b/store/seed/test/10210__deployment_config.sql@@ -15,7 +15,7 @@ VALUES101,3005,'regional-1',- '{"deployments":[{"spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Dev"]},{"key":"bb.location","operator":"In","values":["earth"]}]}}},{"spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Integration"]},{"key":"bb.tenant","operator":"Exists"}]}}}]}'+ '{"deployments":[{"name":"Dev Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Dev"]},{"key":"bb.location","operator":"In","values":["earth"]}]}}},{"name":"Integration Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Integration"]},{"key":"bb.tenant","operator":"Exists"}]}}}]}');INSERT INTO@@ -34,5 +34,5 @@ VALUES101,3006,'regional-2',- '{"deployments":[{"spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Dev"]},{"key":"bb.location","operator":"In","values":["earth"]}]}}},{"spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Integration"]},{"key":"bb.tenant","operator":"Exists"}]}}}]}'+ '{"deployments":[{"name":"Dev Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Dev"]},{"key":"bb.location","operator":"In","values":["earth"]}]}}},{"name":"Integration Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Integration"]},{"key":"bb.tenant","operator":"Exists"}]}}}]}');