Skip to content

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

chore: add sdl format to get change history (#6375)

Danny Xudc9bfa54b808
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.go
index 4882dd9d88..acecf8ca06 100644
--- a/backend/api/v1/database_service.go
+++ b/backend/api/v1/database_service.go
@@ -367,7 +367,7 @@ func (s *DatabaseService) GetDatabaseSchema(ctx context.Context, request *v1pb.G
case db.MySQL, db.TiDB, db.MariaDB, db.OceanBase:
sdlSchema, err := transform.SchemaTransform(parser.MySQL, schema)
if err != nil {
- return nil, status.Errorf(codes.Internal, err.Error())
+ return nil, status.Errorf(codes.Internal, "failed to convert schema to sdl format, error %v", err.Error())
}
schema = sdlSchema
}
@@ -679,6 +679,21 @@ func (s *DatabaseService) GetChangeHistory(ctx context.Context, request *v1pb.Ge
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to convert change history, error: %v", err)
}
+ if request.SdlFormat {
+ switch instance.Engine {
+ case db.MySQL, db.TiDB, db.MariaDB, db.OceanBase:
+ sdlSchema, err := transform.SchemaTransform(parser.MySQL, converted.Schema)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to convert schema to sdl format, error %v", err.Error())
+ }
+ converted.Schema = sdlSchema
+ sdlSchema, err = transform.SchemaTransform(parser.MySQL, converted.PrevSchema)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to convert previous schema to sdl format, error %v", err.Error())
+ }
+ converted.PrevSchema = sdlSchema
+ }
+ }
return converted, nil
}
diff --git a/frontend/src/types/proto/v1/database_service.ts b/frontend/src/types/proto/v1/database_service.ts
index 280b30621c..e332e3923d 100644
--- a/frontend/src/types/proto/v1/database_service.ts
+++ b/frontend/src/types/proto/v1/database_service.ts
@@ -996,6 +996,8 @@ export interface GetChangeHistoryRequest {
*/
name: string;
view: ChangeHistoryView;
+ /** Format the schema dump into SDL format. */
+ sdlFormat: boolean;
}
function createBaseGetDatabaseRequest(): GetDatabaseRequest {
@@ -5494,7 +5496,7 @@ export const ListChangeHistoriesResponse = {
};
function createBaseGetChangeHistoryRequest(): GetChangeHistoryRequest {
- return { name: "", view: 0 };
+ return { name: "", view: 0, sdlFormat: false };
}
export const GetChangeHistoryRequest = {
@@ -5505,6 +5507,9 @@ export const GetChangeHistoryRequest = {
if (message.view !== 0) {
writer.uint32(16).int32(message.view);
}
+ if (message.sdlFormat === true) {
+ writer.uint32(24).bool(message.sdlFormat);
+ }
return writer;
},
@@ -5529,6 +5534,13 @@ export const GetChangeHistoryRequest = {
message.view = reader.int32() as any;
continue;
+ case 3:
+ if (tag !== 24) {
+ break;
+ }
+
+ message.sdlFormat = reader.bool();
+ continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
@@ -5542,6 +5554,7 @@ export const GetChangeHistoryRequest = {
return {
name: isSet(object.name) ? String(object.name) : "",
view: isSet(object.view) ? changeHistoryViewFromJSON(object.view) : 0,
+ sdlFormat: isSet(object.sdlFormat) ? Boolean(object.sdlFormat) : false,
};
},
@@ -5549,6 +5562,7 @@ export const GetChangeHistoryRequest = {
const obj: any = {};
message.name !== undefined && (obj.name = message.name);
message.view !== undefined && (obj.view = changeHistoryViewToJSON(message.view));
+ message.sdlFormat !== undefined && (obj.sdlFormat = message.sdlFormat);
return obj;
},
@@ -5560,6 +5574,7 @@ export const GetChangeHistoryRequest = {
const message = createBaseGetChangeHistoryRequest();
message.name = object.name ?? "";
message.view = object.view ?? 0;
+ message.sdlFormat = object.sdlFormat ?? false;
return message;
},
};
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 1cc2fea166..99ff3bd93e 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -1762,6 +1762,7 @@ FunctionMetadata is the metadata for functions.
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the change history to retrieve. Format: instances/{instance}/databases/{database}/changeHistories/{changeHistory} |
| view | [ChangeHistoryView](#bytebase-v1-ChangeHistoryView) | | |
+| sdl_format | [bool](#bool) | | Format the schema dump into SDL format. |
diff --git a/proto/generated-go/v1/database_service.pb.go b/proto/generated-go/v1/database_service.pb.go
index cacf252de7..8e25e8c418 100644
--- a/proto/generated-go/v1/database_service.pb.go
+++ b/proto/generated-go/v1/database_service.pb.go
@@ -3745,6 +3745,8 @@ type GetChangeHistoryRequest struct {
// Format: instances/{instance}/databases/{database}/changeHistories/{changeHistory}
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
View ChangeHistoryView `protobuf:"varint,2,opt,name=view,proto3,enum=bytebase.v1.ChangeHistoryView" json:"view,omitempty"`
+ // Format the schema dump into SDL format.
+ SdlFormat bool `protobuf:"varint,3,opt,name=sdl_format,json=sdlFormat,proto3" json:"sdl_format,omitempty"`
}
func (x *GetChangeHistoryRequest) Reset() {
@@ -3793,6 +3795,13 @@ func (x *GetChangeHistoryRequest) GetView() ChangeHistoryView {
return ChangeHistoryView_CHANGE_HISTORY_VIEW_UNSPECIFIED
}
+func (x *GetChangeHistoryRequest) GetSdlFormat() bool {
+ if x != nil {
+ return x.SdlFormat
+ }
+ return false
+}
+
var File_v1_database_service_proto protoreflect.FileDescriptor
var file_v1_database_service_proto_rawDesc = []byte{
@@ -4323,13 +4332,15 @@ var file_v1_database_service_proto_rawDesc = []byte{
0x65, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x12, 0x26, 0x0a, 0x0f, 0x6e, 0x65,
0x78, 0x74, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0d, 0x6e, 0x65, 0x78, 0x74, 0x50, 0x61, 0x67, 0x65, 0x54, 0x6f, 0x6b,
- 0x65, 0x6e, 0x22, 0x61, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x48,
- 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a,
- 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d,
- 0x65, 0x12, 0x32, 0x0a, 0x04, 0x76, 0x69, 0x65, 0x77, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32,
- 0x1e, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x68,
- 0x61, 0x6e, 0x67, 0x65, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x56, 0x69, 0x65, 0x77, 0x52,
- 0x04, 0x76, 0x69, 0x65, 0x77, 0x2a, 0x75, 0x0a, 0x11, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x48,
+ 0x65, 0x6e, 0x22, 0x80, 0x01, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65,
+ 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12,
+ 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
+ 0x6d, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x76, 0x69, 0x65, 0x77, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e,
+ 0x32, 0x1e, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43,
+ 0x68, 0x61, 0x6e, 0x67, 0x65, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x56, 0x69, 0x65, 0x77,
+ 0x52, 0x04, 0x76, 0x69, 0x65, 0x77, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x64, 0x6c, 0x5f, 0x66, 0x6f,
+ 0x72, 0x6d, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x73, 0x64, 0x6c, 0x46,
+ 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x2a, 0x75, 0x0a, 0x11, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x48,
0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x56, 0x69, 0x65, 0x77, 0x12, 0x23, 0x0a, 0x1f, 0x43, 0x48,
0x41, 0x4e, 0x47, 0x45, 0x5f, 0x48, 0x49, 0x53, 0x54, 0x4f, 0x52, 0x59, 0x5f, 0x56, 0x49, 0x45,
0x57, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12,
diff --git a/proto/v1/database_service.proto b/proto/v1/database_service.proto
index 564cc90016..3ada5cfbaf 100644
--- a/proto/v1/database_service.proto
+++ b/proto/v1/database_service.proto
@@ -881,5 +881,9 @@ message GetChangeHistoryRequest {
// The name of the change history to retrieve.
// Format: instances/{instance}/databases/{database}/changeHistories/{changeHistory}
string name = 1;
+
ChangeHistoryView view = 2;
+
+ // Format the schema dump into SDL format.
+ bool sdl_format = 3;
}