Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: branch rebase using bb-standard format schema string (#12510)

h3n4ld51b6c80d882
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.go
index 13ae792862..ec63e38cf9 100644
--- a/backend/api/v1/branch_service.go
+++ b/backend/api/v1/branch_service.go
@@ -700,7 +700,15 @@ func (s *BranchService) getNewBaseFromRebaseRequest(ctx context.Context, request
if databaseSchema == nil {
return nil, "", nil, status.Errorf(codes.NotFound, "database schema %q not found", databaseName)
}
- return databaseSchema.GetMetadata(), string(databaseSchema.GetSchema()), databaseSchema.GetConfig(), nil
+ databaseMetadata := databaseSchema.GetMetadata()
+ filteredNewBaseMetadata := filterDatabaseMetadataByEngine(databaseMetadata, instance.Engine)
+ defaultStoreSourceSchema := extractDefaultSchemaForOracleBranch(instance.Engine, filteredNewBaseMetadata)
+ sourceSchema, err := schema.GetDesignSchema(instance.Engine, defaultStoreSourceSchema, "" /* baseline*/, filteredNewBaseMetadata)
+ if err != nil {
+ return nil, "", nil, status.Errorf(codes.Internal, err.Error())
+ }
+
+ return databaseSchema.GetMetadata(), sourceSchema, databaseSchema.GetConfig(), nil
}
if request.SourceBranch != "" {
diff --git a/backend/plugin/schema/mysql/state.go b/backend/plugin/schema/mysql/state.go
index e52c2544ec..8989245cf6 100644
--- a/backend/plugin/schema/mysql/state.go
+++ b/backend/plugin/schema/mysql/state.go
@@ -198,8 +198,13 @@ func (t *tableState) toString(buf io.StringWriter) error {
for _, index := range t.indexes {
indexes = append(indexes, index)
}
+ // Our sync query is ordered by index name, and our UI only support append-only
+ // create index, to avoid introducing text diff, sorting by name instead of id.
sort.Slice(indexes, func(i, j int) bool {
- return indexes[i].id < indexes[j].id
+ if indexes[i].primary {
+ return true
+ }
+ return indexes[i].name < indexes[j].name
})
for i, index := range indexes {
@@ -218,7 +223,7 @@ func (t *tableState) toString(buf io.StringWriter) error {
foreignKeys = append(foreignKeys, fk)
}
sort.Slice(foreignKeys, func(i, j int) bool {
- return foreignKeys[i].id < foreignKeys[j].id
+ return foreignKeys[i].name < foreignKeys[j].name
})
for i, fk := range foreignKeys {
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml
index a24dbacaff..3878809d0a 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml
@@ -553,11 +553,11 @@
`c` int NOT NULL,
`d` text,
PRIMARY KEY (`a`),
- UNIQUE KEY `t_c_uniq_idx` (`c`),
- UNIQUE KEY `t_c_plus_5_uniq_idx` (((`c` + 5))),
- UNIQUE KEY `t_c_plus_5_t_c_plus_3_uniq_idx` (((`c` + 5)),((`c` + 3))),
KEY `idx_c` (`c`),
KEY `idx_d` (`d`),
+ UNIQUE KEY `t_c_plus_5_t_c_plus_3_uniq_idx` (((`c` + 5)),((`c` + 3))),
+ UNIQUE KEY `t_c_plus_5_uniq_idx` (((`c` + 5))),
+ UNIQUE KEY `t_c_uniq_idx` (`c`),
KEY `t_d_fulltext_idx` (`d`)
) COMMENT 'this is comment with '' escaped';