Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: remove branch todo (#10121)
h3n4l408d46212081
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.goindex 19498d0a2d..5901a493dd 100644--- a/backend/api/v1/branch_service.go+++ b/backend/api/v1/branch_service.go@@ -367,8 +367,7 @@ func (s *BranchService) MergeBranch(ctx context.Context, request *v1pb.MergeBranreturn nil, status.Errorf(codes.Aborted, "cannot merge branches without conflict, error: %v", err)}if mergedMetadata == nil {- // TODO(zp): bug, this should not be no change.- return nil, status.Errorf(codes.FailedPrecondition, "failed to merge branch: no change")+ return nil, status.Errorf(codes.Internal, "merged metadata should not be nil if there is no error while merging (%+v, %+v, %+v)", headBranch.Base.Metadata, headBranch.Head.Metadata, baseBranch.Head.Metadata)}mergedSchema, err := schema.GetDesignSchema(storepb.Engine(baseBranch.Engine), string(headBranch.HeadSchema), mergedMetadata)if err != nil {@@ -478,8 +477,7 @@ func (s *BranchService) RebaseBranch(ctx context.Context, request *v1pb.RebaseBrreturn &v1pb.RebaseBranchResponse{Result: &v1pb.RebaseBranchResponse_ConflictSchema{ConflictSchema: conflictSchemaString}}, nil}if newHeadMetadata == nil {- // TODO(zp): bug, this should not be no change.- return nil, status.Errorf(codes.FailedPrecondition, "failed to rebase branch: no change")+ return nil, status.Errorf(codes.Internal, "merged metadata should not be nil if there is no error while merging (%+v, %+v, %+v)", baseBranch.Base.Metadata, baseBranch.Head.Metadata, newBaseMetadata)}// XXX(zp): We only try to merge the schema config while the schema could be merged successfully. Otherwise, users manually merge the// metadata in the frontend, and config would be ignored.diff --git a/backend/api/v1/schema_design_merge.go b/backend/api/v1/schema_design_merge.goindex 3dde34057c..592b9690f8 100644--- a/backend/api/v1/schema_design_merge.go+++ b/backend/api/v1/schema_design_merge.go@@ -21,9 +21,14 @@ const (diffActionDrop diffAction = "DROP")+// tryMerge merges other metadata to current metadata, always returns a non-nil metadata if no error occurs.func tryMerge(ancestor, head, base *storepb.DatabaseSchemaMetadata) (*storepb.DatabaseSchemaMetadata, error) {ancestor, head, base = proto.Clone(ancestor).(*storepb.DatabaseSchemaMetadata), proto.Clone(head).(*storepb.DatabaseSchemaMetadata), proto.Clone(base).(*storepb.DatabaseSchemaMetadata)+ if ancestor == nil {+ ancestor = &storepb.DatabaseSchemaMetadata{}+ }+diffBetweenAncestorAndHead, err := diffMetadata(ancestor, head)if err != nil {return nil, errors.Wrap(err, "failed to diff between ancestor and head")diff --git a/backend/api/v1/schema_design_merge_test.go b/backend/api/v1/schema_design_merge_test.goindex c2b118f830..75790bd9cd 100644--- a/backend/api/v1/schema_design_merge_test.go+++ b/backend/api/v1/schema_design_merge_test.go@@ -49,18 +49,21 @@ func TestTryMerge(t *testing.T) {baseSchemaMetadata := new(storepb.DatabaseSchemaMetadata)err := protojson.Unmarshal([]byte(tc.Base), baseSchemaMetadata)a.NoErrorf(err, "test case %d: %s", idx, tc.Description)- expectedSchemaMetadata := new(storepb.DatabaseSchemaMetadata)- err = protojson.Unmarshal([]byte(tc.Expected), expectedSchemaMetadata)- a.NoErrorf(err, "test case %d: %s", idx, tc.Description)mergedSchemaMetadata, err := tryMerge(ancestorSchemaMetadata, headSchemaMetadata, baseSchemaMetadata)a.NoErrorf(err, "test case %d: %s", idx, tc.Description)+ a.NotNil(mergedSchemaMetadata, "test case %d: %s, mergedSchemaMetadata should not be nil if there is no error", idx, tc.Description)s := protojson.MarshalOptions{Multiline: true, Indent: " "}.Format(mergedSchemaMetadata)a.NoErrorf(err, "test case %d: %s", idx, tc.Description)if record {testCases[idx].Expected = strings.TrimSpace(s)- } else if diff := cmp.Diff(expectedSchemaMetadata, mergedSchemaMetadata, protocmp.Transform()); diff != "" {- a.Failf("Failed", "mismatch (-want +got):\n%s", diff)+ } else {+ expectedSchemaMetadata := new(storepb.DatabaseSchemaMetadata)+ err = protojson.Unmarshal([]byte(tc.Expected), expectedSchemaMetadata)+ a.NoErrorf(err, "test case %d: %s", idx, tc.Description)+ if diff := cmp.Diff(expectedSchemaMetadata, mergedSchemaMetadata, protocmp.Transform()); diff != "" {+ a.Failf("Failed", "mismatch (-want +got):\n%s", diff)+ }}}diff --git a/backend/api/v1/testdata/schema_design_merge/try_merge.yaml b/backend/api/v1/testdata/schema_design_merge/try_merge.yamlindex de4f9e1667..77ba3b6c7a 100644--- a/backend/api/v1/testdata/schema_design_merge/try_merge.yaml+++ b/backend/api/v1/testdata/schema_design_merge/try_merge.yaml@@ -281,108 +281,108 @@}expected: |-{- "schemas": [+ "schemas": [{- "name": "public",- "tables": [+ "name": "public",+ "tables": [{- "name": "employee",- "columns": [+ "name": "employee",+ "columns": [{- "name": "id",- "position": 1,- "type": "integer"+ "name": "id",+ "position": 1,+ "type": "integer"},{- "name": "gender",- "position": 2,- "type": "char(1)"+ "name": "gender",+ "position": 2,+ "type": "char(1)"},{- "name": "debit_card_number",- "position": 3,- "type": "varchar(255)"+ "name": "debit_card_number",+ "position": 3,+ "type": "varchar(255)"},{- "name": "credit_card_number",- "position": 4,- "type": "varchar(255)"+ "name": "credit_card_number",+ "position": 4,+ "type": "varchar(255)"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["id"],- "type": "btree",- "unique": true,- "primary": true+ "type": "btree",+ "unique": true,+ "primary": true}]},{- "name": "address",- "columns": [+ "name": "address",+ "columns": [{- "name": "id",- "position": 1,- "type": "integer"+ "name": "id",+ "position": 1,+ "type": "integer"},{- "name": "address",- "position": 2,- "type": "varchar(255)"+ "name": "address",+ "position": 2,+ "type": "varchar(255)"},{- "name": "employee_id",- "position": 3,- "type": "integer"+ "name": "employee_id",+ "position": 3,+ "type": "integer"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["id"],- "primary": true+ "primary": true}],- "foreignKeys": [+ "foreignKeys": [{- "name": "address-fk-sc4rcmkp",- "columns": [+ "name": "address-fk-sc4rcmkp",+ "columns": ["employee_id"],- "referencedSchema": "public",- "referencedTable": "employee",- "referencedColumns": [+ "referencedSchema": "public",+ "referencedTable": "employee",+ "referencedColumns": ["id"]}]},{- "name": "hiring_date",- "columns": [+ "name": "hiring_date",+ "columns": [{- "name": "id",- "position": 1,- "type": "integer"+ "name": "id",+ "position": 1,+ "type": "integer"},{- "name": "employee_id",- "position": 2,- "type": "integer"+ "name": "employee_id",+ "position": 2,+ "type": "integer"}]}]}],- "characterSet": "UTF8",- "collation": "en_US.utf8"+ "characterSet": "UTF8",+ "collation": "en_US.utf8"}- description: Add different column on the same tableancestor: |-@@ -463,35 +463,35 @@}expected: |-{- "schemas": [+ "schemas": [{- "name": "public",- "tables": [+ "name": "public",+ "tables": [{- "name": "employee",- "columns": [+ "name": "employee",+ "columns": [{- "name": "id",- "position": 1,- "type": "integer"+ "name": "id",+ "position": 1,+ "type": "integer"},{- "name": "gender",- "position": 2,- "type": "char(1)"+ "name": "gender",+ "position": 2,+ "type": "char(1)"},{- "name": "name",- "position": 3,- "type": "varchar(255)"+ "name": "name",+ "position": 3,+ "type": "varchar(255)"}]}]}],- "characterSet": "UTF8",- "collation": "en_US.utf8"+ "characterSet": "UTF8",+ "collation": "en_US.utf8"}- description: Add index in baseancestor: |-@@ -586,39 +586,39 @@}expected: |-{- "schemas": [+ "schemas": [{- "name": "public",- "tables": [+ "name": "public",+ "tables": [{- "name": "employee",- "columns": [+ "name": "employee",+ "columns": [{- "name": "id",- "position": 1,- "type": "integer"+ "name": "id",+ "position": 1,+ "type": "integer"},{- "name": "name",- "position": 2,- "type": "text"+ "name": "name",+ "position": 2,+ "type": "text"}],- "indexes": [+ "indexes": [{- "name": "address_name_idx",- "expressions": [+ "name": "address_name_idx",+ "expressions": ["name"],- "visible": true+ "visible": true}]}]}],- "characterSet": "UTF8",- "collation": "en_US.utf8"+ "characterSet": "UTF8",+ "collation": "en_US.utf8"}- description: Create different tableancestor: |-@@ -707,43 +707,132 @@}expected: |-{- "schemas": [+ "schemas": [{- "name": "public",- "tables": [+ "name": "public",+ "tables": [{- "name": "employee",- "columns": [+ "name": "employee",+ "columns": [{- "name": "id",- "position": 1,- "type": "integer"+ "name": "id",+ "position": 1,+ "type": "integer"}]},{- "name": "address",- "columns": [+ "name": "address",+ "columns": [{- "name": "id",- "position": 1,- "type": "integer"+ "name": "id",+ "position": 1,+ "type": "integer"}]},{- "name": "salary",- "columns": [+ "name": "salary",+ "columns": [{- "name": "id",- "position": 1,- "type": "integer"+ "name": "id",+ "position": 1,+ "type": "integer"}]}]}],- "characterSet": "UTF8",- "collation": "en_US.utf8"+ "characterSet": "UTF8",+ "collation": "en_US.utf8"+ }+- description: no change+ ancestor: |-+ {+ "schemas": [+ {+ "name": "public",+ "tables": [+ {+ "name": "employee",+ "columns": [+ {+ "name": "id",+ "position": 1,+ "type": "integer"+ }+ ]+ }+ ]+ }+ ],+ "characterSet": "UTF8",+ "collation": "en_US.utf8"+ }+ head: |-+ {+ "schemas": [+ {+ "name": "public",+ "tables": [+ {+ "name": "employee",+ "columns": [+ {+ "name": "id",+ "position": 1,+ "type": "integer"+ }+ ]+ }+ ]+ }+ ],+ "characterSet": "UTF8",+ "collation": "en_US.utf8"+ }+ base: |-+ {+ "schemas": [+ {+ "name": "public",+ "tables": [+ {+ "name": "employee",+ "columns": [+ {+ "name": "id",+ "position": 1,+ "type": "integer"+ }+ ]+ }+ ]+ }+ ],+ "characterSet": "UTF8",+ "collation": "en_US.utf8"+ }+ expected: |-+ {+ "schemas": [+ {+ "name": "public",+ "tables": [+ {+ "name": "employee",+ "columns": [+ {+ "name": "id",+ "position": 1,+ "type": "integer"+ }+ ]+ }+ ]+ }+ ],+ "characterSet": "UTF8",+ "collation": "en_US.utf8"}