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): fill in relationships for validate only issue creation (#335)
spinningbotfeda45b5563b
diff --git a/server/issue.go b/server/issue.goindex 2bf18bed43..d318a4896a 100644--- a/server/issue.go+++ b/server/issue.go@@ -314,6 +314,10 @@ func (s *Server) composeIssueRelationship(ctx context.Context, issue *api.Issue)if err != nil {return err}+ } else {+ if err := s.composePipelineRelationship(ctx, issue.Pipeline); err != nil {+ return err+ }}return nil@@ -516,33 +520,42 @@ func (s *Server) createIssue(ctx context.Context, issueCreate *api.IssueCreate,return issue, nil}-func createPipelineValidateOnly(ctx context.Context, pc *api.PipelineCreate) (*api.Pipeline, error) {+func createPipelineValidateOnly(ctx context.Context, pc *api.PipelineCreate, creatorID int) (*api.Pipeline, error) {+ // We cannot emit ID or use default zero by following https://google.aip.dev/163, otherwise+ // jsonapi resource relationships will collide different resources into the same bucket.+ id := 0+ ts := time.Now().Unix()pipeline := &api.Pipeline{+ ID: id,Name: pc.Name,Status: api.PipelineOpen,- CreatorID: pc.CreatorID,- CreatedTs: time.Now().Unix(),- UpdaterID: pc.CreatorID,- UpdatedTs: time.Now().Unix(),+ CreatorID: creatorID,+ CreatedTs: ts,+ UpdaterID: creatorID,+ UpdatedTs: ts,}for _, sc := range pc.StageList {+ id++stage := &api.Stage{+ ID: id,Name: sc.Name,- CreatorID: sc.CreatorID,- CreatedTs: time.Now().Unix(),- UpdaterID: sc.CreatorID,- UpdatedTs: time.Now().Unix(),+ CreatorID: creatorID,+ CreatedTs: ts,+ UpdaterID: creatorID,+ UpdatedTs: ts,PipelineID: sc.PipelineID,EnvironmentID: sc.EnvironmentID,}for _, tc := range sc.TaskList {+ id++task := &api.Task{+ ID: id,Name: tc.Name,Status: tc.Status,- CreatorID: tc.CreatorID,- CreatedTs: time.Now().Unix(),- UpdaterID: tc.CreatorID,- UpdatedTs: time.Now().Unix(),+ CreatorID: creatorID,+ CreatedTs: ts,+ UpdaterID: creatorID,+ UpdatedTs: ts,Type: tc.Type,Payload: tc.Payload,EarliestAllowedTs: tc.EarliestAllowedTs,@@ -824,7 +837,7 @@ func (s *Server) createPipelineFromIssue(ctx context.Context, issueCreate *api.I// Create the pipeline, stages, and tasks.if validateOnly {- return createPipelineValidateOnly(ctx, pipelineCreate)+ return createPipelineValidateOnly(ctx, pipelineCreate, creatorID)}pipelineCreate.CreatorID = creatorIDdiff --git a/server/pipeline.go b/server/pipeline.goindex 9773e37a41..95a81338ff 100644--- a/server/pipeline.go+++ b/server/pipeline.go@@ -36,9 +36,17 @@ func (s *Server) composePipelineRelationship(ctx context.Context, pipeline *api.return err}- pipeline.StageList, err = s.composeStageListByPipelineID(ctx, pipeline.ID)- if err != nil {- return err+ if pipeline.StageList == nil {+ pipeline.StageList, err = s.composeStageListByPipelineID(ctx, pipeline.ID)+ if err != nil {+ return err+ }+ } else {+ for _, stage := range pipeline.StageList {+ if err := s.composeStageRelationship(ctx, stage); err != nil {+ return err+ }+ }}return nildiff --git a/server/stage.go b/server/stage.goindex 6b6750d95d..981d615a3d 100644--- a/server/stage.go+++ b/server/stage.go@@ -41,9 +41,17 @@ func (s *Server) composeStageRelationship(ctx context.Context, stage *api.Stage)return err}- stage.TaskList, err = s.composeTaskListByPipelineAndStageID(ctx, stage.PipelineID, stage.ID)- if err != nil {- return err+ if stage.TaskList == nil {+ stage.TaskList, err = s.composeTaskListByPipelineAndStageID(ctx, stage.PipelineID, stage.ID)+ if err != nil {+ return err+ }+ } else {+ for _, task := range stage.TaskList {+ if err := s.composeTaskRelationship(ctx, task); err != nil {+ return err+ }+ }}return nil