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: impl CreatePlan dependsOnSpecs (#11197)
p0ny6a32dbffff6e
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.goindex e7f12d5293..eff26a1b55 100644--- a/backend/api/v1/rollout_service.go+++ b/backend/api/v1/rollout_service.go@@ -1235,6 +1235,7 @@ func validateSteps(steps []*v1pb.Plan_Step) error {var databaseTarget, databaseGroupTarget, deploymentConfigTarget intseenID := map[string]bool{}for _, step := range steps {+ seenIDInStep := map[string]bool{}for _, spec := range step.Specs {id := spec.GetId()if id == "" {@@ -1244,6 +1245,7 @@ func validateSteps(steps []*v1pb.Plan_Step) error {return errors.Errorf("found duplicate spec id %q", spec.GetId())}seenID[id] = true+ seenIDInStep[id] = trueif config := spec.GetChangeDatabaseConfig(); config != nil {if _, _, err := common.GetInstanceDatabaseID(config.Target); err == nil {databaseTarget++@@ -1256,6 +1258,16 @@ func validateSteps(steps []*v1pb.Plan_Step) error {}}}+ for _, spec := range step.Specs {+ for _, dependOnSpec := range spec.DependsOnSpecs {+ if !seenIDInStep[dependOnSpec] {+ return errors.Errorf("spec %q depends on spec %q, but spec %q is not found in the step", spec.Id, dependOnSpec, dependOnSpec)+ }+ if dependOnSpec == spec.Id {+ return errors.Errorf("spec %q depends on itself", spec.Id)+ }+ }+ }}if deploymentConfigTarget > 1 {return errors.Errorf("expect at most on deploymentConfig target, got %d", deploymentConfigTarget)@@ -1300,6 +1312,8 @@ func GetPipelineCreate(ctx context.Context, s *store.Store, licenseService enter}return nil}++ taskIndexesBySpecID := map[string][]int{}for _, spec := range step.Specs {taskCreates, taskIndexDAGCreates, err := getTaskCreatesFromSpec(ctx, s, licenseService, dbFactory, spec, project, registerEnvironmentID)if err != nil {@@ -1307,6 +1321,9 @@ func GetPipelineCreate(ctx context.Context, s *store.Store, licenseService enter}offset := len(stageCreate.TaskList)+ for i := range taskCreates {+ taskIndexesBySpecID[spec.Id] = append(taskIndexesBySpecID[spec.Id], i+offset)+ }for i := range taskIndexDAGCreates {taskIndexDAGCreates[i].FromIndex += offsettaskIndexDAGCreates[i].ToIndex += offset@@ -1314,6 +1331,9 @@ func GetPipelineCreate(ctx context.Context, s *store.Store, licenseService enterstageCreate.TaskList = append(stageCreate.TaskList, taskCreates...)stageCreate.TaskIndexDAGList = append(stageCreate.TaskIndexDAGList, taskIndexDAGCreates...)}+ stageCreate.TaskIndexDAGList = append(stageCreate.TaskIndexDAGList, getTaskIndexDAGs(step.Specs, func(specID string) []int {+ return taskIndexesBySpecID[specID]+ })...)environment, err := s.GetEnvironmentV2(ctx, &store.FindEnvironmentMessage{ResourceID: &stageEnvironmentID})if err != nil {@@ -1333,6 +1353,23 @@ func GetPipelineCreate(ctx context.Context, s *store.Store, licenseService enterreturn pipelineCreate, nil}+func getTaskIndexDAGs(specs []*storepb.PlanConfig_Spec, getTaskIndexes func(specID string) []int) []store.TaskIndexDAG {+ var taskIndexDAGs []store.TaskIndexDAG+ for _, spec := range specs {+ for _, dependsOnSpec := range spec.DependsOnSpecs {+ for _, dependsOnTask := range getTaskIndexes(dependsOnSpec) {+ for _, task := range getTaskIndexes(spec.Id) {+ taskIndexDAGs = append(taskIndexDAGs, store.TaskIndexDAG{+ FromIndex: dependsOnTask,+ ToIndex: task,+ })+ }+ }+ }+ }+ return taskIndexDAGs+}+func (s *RolloutService) createPipeline(ctx context.Context, project *store.ProjectMessage, pipelineCreate *store.PipelineMessage, creatorID int) (*store.PipelineMessage, error) {pipelineCreated, err := s.store.CreatePipelineV2(ctx, &store.PipelineMessage{Name: pipelineCreate.Name,diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.goindex af5496eef7..a0fcedc352 100644--- a/backend/api/v1/rollout_service_converter.go+++ b/backend/api/v1/rollout_service_converter.go@@ -77,6 +77,7 @@ func convertToPlanSpec(spec *storepb.PlanConfig_Spec) *v1pb.Plan_Spec {v1Spec := &v1pb.Plan_Spec{EarliestAllowedTime: spec.EarliestAllowedTime,Id: spec.Id,+ DependsOnSpecs: spec.DependsOnSpecs,}switch v := spec.Config.(type) {@@ -226,6 +227,7 @@ func convertPlanSpec(spec *v1pb.Plan_Spec) *storepb.PlanConfig_Spec {storeSpec := &storepb.PlanConfig_Spec{EarliestAllowedTime: spec.EarliestAllowedTime,Id: spec.Id,+ DependsOnSpecs: spec.DependsOnSpecs,}switch v := spec.Config.(type) {diff --git a/backend/store/task.go b/backend/store/task.goindex ad8d273abf..6b4941b485 100644--- a/backend/store/task.go+++ b/backend/store/task.go@@ -248,7 +248,7 @@ func (s *Store) ListTasks(ctx context.Context, find *api.TaskFind) ([]*TaskMessavar tasks []*TaskMessagefor rows.Next() {task := &TaskMessage{}- var blockedBy pgtype.Int4Array+ var dependsOn pgtype.Int4Arrayif err := rows.Scan(&task.ID,&task.CreatorID,@@ -264,11 +264,11 @@ func (s *Store) ListTasks(ctx context.Context, find *api.TaskFind) ([]*TaskMessa&task.Type,&task.Payload,&task.EarliestAllowedTs,- &blockedBy,+ &dependsOn,); err != nil {return nil, err}- if err := blockedBy.AssignTo(&task.DependsOn); err != nil {+ if err := dependsOn.AssignTo(&task.DependsOn); err != nil {return nil, err}tasks = append(tasks, task)diff --git a/frontend/src/types/proto/google/protobuf/struct.ts b/frontend/src/types/proto/google/protobuf/struct.tsindex b87dbf5bac..dbdf7a289a 100644--- a/frontend/src/types/proto/google/protobuf/struct.ts+++ b/frontend/src/types/proto/google/protobuf/struct.ts@@ -8,7 +8,7 @@ export const protobufPackage = "google.protobuf";* `NullValue` is a singleton enumeration to represent the null value for the* `Value` type union.*- * The JSON representation for `NullValue` is JSON `null`.+ * The JSON representation for `NullValue` is JSON `null`.*/export enum NullValue {/** NULL_VALUE - Null value. */diff --git a/frontend/src/types/proto/google/protobuf/timestamp.ts b/frontend/src/types/proto/google/protobuf/timestamp.tsindex 5781891bc0..51695e08d0 100644--- a/frontend/src/types/proto/google/protobuf/timestamp.ts+++ b/frontend/src/types/proto/google/protobuf/timestamp.ts@@ -92,7 +92,7 @@ export const protobufPackage = "google.protobuf";* [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with* the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use* the Joda Time's [`ISODateTimeFormat.dateTime()`](- * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()+ * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D* ) to obtain a formatter capable of generating timestamps in this format.*/export interface Timestamp {diff --git a/frontend/src/types/proto/store/plan.ts b/frontend/src/types/proto/store/plan.tsindex 17c3714bdf..39a9bfd811 100644--- a/frontend/src/types/proto/store/plan.ts+++ b/frontend/src/types/proto/store/plan.ts@@ -25,7 +25,10 @@ export interface PlanConfig_Spec {| undefined;/** A UUID4 string that uniquely identifies the Spec. */id: string;- /** IDs of the specs that this spec depends on. */+ /**+ * IDs of the specs that this spec depends on.+ * Must be a subset of the specs in the same step.+ */dependsOnSpecs: string[];createDatabaseConfig?: PlanConfig_CreateDatabaseConfig | undefined;changeDatabaseConfig?: PlanConfig_ChangeDatabaseConfig | undefined;diff --git a/frontend/src/types/proto/v1/rollout_service.ts b/frontend/src/types/proto/v1/rollout_service.tsindex ac3e6f33f1..487858c513 100644--- a/frontend/src/types/proto/v1/rollout_service.ts+++ b/frontend/src/types/proto/v1/rollout_service.ts@@ -105,7 +105,10 @@ export interface Plan_Spec {| undefined;/** A UUID4 string that uniquely identifies the Spec. */id: string;- /** IDs of the specs that this spec depends on. */+ /**+ * IDs of the specs that this spec depends on.+ * Must be a subset of the specs in the same step.+ */dependsOnSpecs: string[];createDatabaseConfig?: Plan_CreateDatabaseConfig | undefined;changeDatabaseConfig?: Plan_ChangeDatabaseConfig | undefined;diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex 5065e53aad..2c0c47e7e4 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -2043,7 +2043,7 @@ InstanceOptions is the option for instances.| ----- | ---- | ----- | ----------- || earliest_allowed_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | earliest_allowed_time the earliest execution time of the change. || id | [string](#string) | | A UUID4 string that uniquely identifies the Spec. |-| depends_on_specs | [string](#string) | repeated | IDs of the specs that this spec depends on. |+| depends_on_specs | [string](#string) | repeated | IDs of the specs that this spec depends on. Must be a subset of the specs in the same step. || create_database_config | [PlanConfig.CreateDatabaseConfig](#bytebase-store-PlanConfig-CreateDatabaseConfig) | | || change_database_config | [PlanConfig.ChangeDatabaseConfig](#bytebase-store-PlanConfig-ChangeDatabaseConfig) | | || restore_database_config | [PlanConfig.RestoreDatabaseConfig](#bytebase-store-PlanConfig-RestoreDatabaseConfig) | | |diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.htmlindex 9f7c61fe8e..356e9c6e41 100644--- a/proto/gen/grpc-doc/store/index.html+++ b/proto/gen/grpc-doc/store/index.html@@ -5409,7 +5409,8 @@ Format: instances/{instance}/databases/{database}/backups/{backup-name} </p></td<td>depends_on_specs</td><td><a href="#string">string</a></td><td>repeated</td>- <td><p>IDs of the specs that this spec depends on. </p></td>+ <td><p>IDs of the specs that this spec depends on.+Must be a subset of the specs in the same step. </p></td></tr><tr>diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex 3e8da20cad..89baa853dd 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -8041,7 +8041,7 @@ When paginating, all other parameters provided to `ListRolloutTaskRuns` must mat| ----- | ---- | ----- | ----------- || earliest_allowed_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | earliest_allowed_time the earliest execution time of the change. || id | [string](#string) | | A UUID4 string that uniquely identifies the Spec. |-| depends_on_specs | [string](#string) | repeated | IDs of the specs that this spec depends on. |+| depends_on_specs | [string](#string) | repeated | IDs of the specs that this spec depends on. Must be a subset of the specs in the same step. || create_database_config | [Plan.CreateDatabaseConfig](#bytebase-v1-Plan-CreateDatabaseConfig) | | || change_database_config | [Plan.ChangeDatabaseConfig](#bytebase-v1-Plan-ChangeDatabaseConfig) | | || restore_database_config | [Plan.RestoreDatabaseConfig](#bytebase-v1-Plan-RestoreDatabaseConfig) | | |diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.htmlindex a487f5f92a..36e17e17e9 100644--- a/proto/gen/grpc-doc/v1/index.html+++ b/proto/gen/grpc-doc/v1/index.html@@ -22333,7 +22333,8 @@ Format: instances/{instance}/databases/{database} </p></td><td>depends_on_specs</td><td><a href="#string">string</a></td><td>repeated</td>- <td><p>IDs of the specs that this spec depends on. </p></td>+ <td><p>IDs of the specs that this spec depends on.+Must be a subset of the specs in the same step. </p></td></tr><tr>diff --git a/proto/generated-go/store/plan.pb.go b/proto/generated-go/store/plan.pb.goindex 38d3c8d3f5..e538f3684a 100644--- a/proto/generated-go/store/plan.pb.go+++ b/proto/generated-go/store/plan.pb.go@@ -206,6 +206,7 @@ type PlanConfig_Spec struct {// A UUID4 string that uniquely identifies the Spec.Id string `protobuf:"bytes,5,opt,name=id,proto3" json:"id,omitempty"`// IDs of the specs that this spec depends on.+ // Must be a subset of the specs in the same step.DependsOnSpecs []string `protobuf:"bytes,6,rep,name=depends_on_specs,json=dependsOnSpecs,proto3" json:"depends_on_specs,omitempty"`// Types that are assignable to Config://diff --git a/proto/generated-go/v1/rollout_service.pb.go b/proto/generated-go/v1/rollout_service.pb.goindex d738dd1f7e..16c7fb57af 100644--- a/proto/generated-go/v1/rollout_service.pb.go+++ b/proto/generated-go/v1/rollout_service.pb.go@@ -2538,6 +2538,7 @@ type Plan_Spec struct {// A UUID4 string that uniquely identifies the Spec.Id string `protobuf:"bytes,5,opt,name=id,proto3" json:"id,omitempty"`// IDs of the specs that this spec depends on.+ // Must be a subset of the specs in the same step.DependsOnSpecs []string `protobuf:"bytes,6,rep,name=depends_on_specs,json=dependsOnSpecs,proto3" json:"depends_on_specs,omitempty"`// Types that are assignable to Config://diff --git a/proto/store/plan.proto b/proto/store/plan.protoindex f7772e9fd8..2efd58ef76 100644--- a/proto/store/plan.proto+++ b/proto/store/plan.proto@@ -22,6 +22,7 @@ message PlanConfig {// A UUID4 string that uniquely identifies the Spec.string id = 5;// IDs of the specs that this spec depends on.+ // Must be a subset of the specs in the same step.repeated string depends_on_specs = 6;oneof config {diff --git a/proto/v1/rollout_service.proto b/proto/v1/rollout_service.protoindex a7b5c3472c..638b066790 100644--- a/proto/v1/rollout_service.proto+++ b/proto/v1/rollout_service.proto@@ -187,6 +187,7 @@ message Plan {// A UUID4 string that uniquely identifies the Spec.string id = 5;// IDs of the specs that this spec depends on.+ // Must be a subset of the specs in the same step.repeated string depends_on_specs = 6;oneof config {