Skip to content

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

feat: add /v1/sql/pretty API to improve SDL task differ display (#4967)

rebelice8afe72664201
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
new file mode 100644
index 0000000000..898a828848
--- /dev/null
+++ b/backend/api/v1/sql_service.go
@@ -0,0 +1,46 @@
+package v1
+
+import (
+ "context"
+
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/status"
+
+ "github.com/bytebase/bytebase/backend/plugin/parser"
+ "github.com/bytebase/bytebase/backend/plugin/parser/transform"
+ v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
+)
+
+// SQLService is the service for SQL.
+type SQLService struct {
+ v1pb.UnimplementedSQLServiceServer
+}
+
+// NewSQLService creates a SQLService.
+func NewSQLService() *SQLService {
+ return &SQLService{}
+}
+
+// Pretty returns pretty format SDL.
+func (*SQLService) Pretty(_ context.Context, request *v1pb.PrettyRequest) (*v1pb.PrettyResponse, error) {
+ engine := parser.EngineType(convertEngine(request.Engine))
+ if _, err := transform.CheckFormat(engine, request.ExpectedSchema); err != nil {
+ return nil, status.Errorf(codes.InvalidArgument, "User SDL is not SDL format: %s", err.Error())
+ }
+ if _, err := transform.CheckFormat(engine, request.CurrentSchema); err != nil {
+ return nil, status.Errorf(codes.InvalidArgument, "Dumped SDL is not SDL format: %s", err.Error())
+ }
+
+ prettyExpectedSchema, err := transform.SchemaTransform(engine, request.ExpectedSchema)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to transform user SDL: %s", err.Error())
+ }
+ prettyCurrentSchema, err := transform.Normalize(engine, request.CurrentSchema, prettyExpectedSchema)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to normalize dumped SDL: %s", err.Error())
+ }
+ return &v1pb.PrettyResponse{
+ CurrentSchema: prettyCurrentSchema,
+ ExpectedSchema: prettyExpectedSchema,
+ }, nil
+}
diff --git a/backend/server/server.go b/backend/server/server.go
index 84736c76a5..4d9bc553cf 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -491,6 +491,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
v1pb.RegisterIdentityProviderServiceServer(s.grpcServer, v1.NewIdentityProviderService(s.store, s.licenseService))
v1pb.RegisterSettingServiceServer(s.grpcServer, v1.NewSettingService(s.store, &s.profile))
v1pb.RegisterAnomalyServiceServer(s.grpcServer, v1.NewAnomalyService(s.store))
+ v1pb.RegisterSQLServiceServer(s.grpcServer, v1.NewSQLService())
reflection.Register(s.grpcServer)
// REST gateway proxy.
@@ -533,6 +534,9 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
if err := v1pb.RegisterAnomalyServiceHandler(ctx, mux, grpcConn); err != nil {
return nil, err
}
+ if err := v1pb.RegisterSQLServiceHandler(ctx, mux, grpcConn); err != nil {
+ return nil, err
+ }
e.Any("/v1/*", echo.WrapHandler(mux))
// GRPC web proxy.
options := []grpcweb.Option{
diff --git a/frontend/src/components/Issue/IssueTaskSDLPanel.vue b/frontend/src/components/Issue/IssueTaskSDLPanel.vue
index e0f861e7b9..1a3bc1b3af 100644
--- a/frontend/src/components/Issue/IssueTaskSDLPanel.vue
+++ b/frontend/src/components/Issue/IssueTaskSDLPanel.vue
@@ -32,7 +32,7 @@
<NTabPane name="diff" :tab="$t('issue.sdl.schema-change')">
<CodeDiff
:old-string="sdlState.detail.previousSDL"
- :new-string="sdlState.detail.expectedSDL"
+ :new-string="sdlState.detail.prettyExpectedSDL"
output-format="side-by-side"
data-label="bb-change-detail-code-diff-block"
/></NTabPane>
@@ -84,12 +84,15 @@ import { useIssueLogic } from "./logic";
import { Task, TaskDatabaseSchemaUpdateSDLPayload, TaskId } from "@/types";
import MonacoEditor from "../MonacoEditor";
import axios from "axios";
+import { sqlClient } from "@/grpcweb";
+import { convertEngineType } from "@/types";
import { useSQLAdviceMarkers } from "./logic/useSQLAdviceMarkers";
type TabView = "diff" | "statement" | "schema";
type SDLDetail = {
previousSDL: string;
+ prettyExpectedSDL: string;
expectedSDL: string;
diffDDL: string;
};
@@ -164,11 +167,22 @@ const useSDLState = () => {
};
const diffDDL = (await getSchemaDiff()) ?? "";
+ const { currentSchema, expectedSchema } = await sqlClient.pretty({
+ engine: convertEngineType(database.instance.engine),
+ currentSchema: previousSDL ?? "",
+ expectedSchema: expectedSDL ?? "",
+ });
+
if (task.status === "DONE") {
throw new Error();
}
- return { previousSDL, expectedSDL, diffDDL };
+ return {
+ previousSDL: currentSchema,
+ prettyExpectedSDL: expectedSchema,
+ expectedSDL,
+ diffDDL,
+ };
};
const fetchSDLDetailFromMigrationHistory = async (
@@ -192,6 +206,7 @@ const useSDLState = () => {
}
return {
previousSDL: history.schemaPrev,
+ prettyExpectedSDL: history.schema,
expectedSDL: history.schema,
diffDDL: history.statement,
};
diff --git a/frontend/src/grpcweb/index.ts b/frontend/src/grpcweb/index.ts
index a1098816d1..e0f4bed5c9 100644
--- a/frontend/src/grpcweb/index.ts
+++ b/frontend/src/grpcweb/index.ts
@@ -5,6 +5,7 @@ import { IdentityProviderServiceDefinition } from "@/types/proto/v1/idp_service"
import { EnvironmentServiceDefinition } from "@/types/proto/v1/environment_service";
import { InstanceServiceDefinition } from "@/types/proto/v1/instance_service";
import { ProjectServiceDefinition } from "@/types/proto/v1/project_service";
+import { SQLServiceDefinition } from "@/types/proto/v1/sql_service";
// Create each grpc service client.
// Reference: https://github.com/deeplay-io/nice-grpc/blob/master/packages/nice-grpc-web/README.md
@@ -47,6 +48,8 @@ export const identityProviderClient = clientFactory.create(
channel
);
+export const sqlClient = clientFactory.create(SQLServiceDefinition, channel);
+
// e.g. How to use `authServiceClient`?
//
// await authServiceClient.login({
diff --git a/frontend/src/types/instance.ts b/frontend/src/types/instance.ts
index 0271a0042f..85940965c8 100644
--- a/frontend/src/types/instance.ts
+++ b/frontend/src/types/instance.ts
@@ -7,6 +7,7 @@ import {
MigrationHistoryId,
ResourceId,
} from "./id";
+import { Engine } from "./proto/v1/common";
import { VCSPushEvent } from "./vcs";
export type EngineType =
@@ -18,6 +19,25 @@ export type EngineType =
| "MONGODB"
| "SPANNER";
+export function convertEngineType(type: EngineType): Engine {
+ switch (type) {
+ case "CLICKHOUSE":
+ return Engine.CLICKHOUSE;
+ case "MYSQL":
+ return Engine.MYSQL;
+ case "POSTGRES":
+ return Engine.POSTGRES;
+ case "SNOWFLAKE":
+ return Engine.SNOWFLAKE;
+ case "TIDB":
+ return Engine.TIDB;
+ case "MONGODB":
+ return Engine.MONGODB;
+ // TODO(xz): add Spanner here.
+ }
+ return Engine.ENGINE_UNSPECIFIED;
+}
+
export function defaultCharset(type: EngineType): string {
switch (type) {
case "CLICKHOUSE":
diff --git a/frontend/src/types/proto/v1/sql_service.ts b/frontend/src/types/proto/v1/sql_service.ts
new file mode 100644
index 0000000000..9b5e59fa53
--- /dev/null
+++ b/frontend/src/types/proto/v1/sql_service.ts
@@ -0,0 +1,184 @@
+/* eslint-disable */
+import type { CallContext, CallOptions } from "nice-grpc-common";
+import * as _m0 from "protobufjs/minimal";
+import { Engine, engineFromJSON, engineToJSON } from "./common";
+
+export const protobufPackage = "bytebase.v1";
+
+export interface PrettyRequest {
+ engine: Engine;
+ /**
+ * The SDL format SQL schema information that was dumped from a database engine.
+ * This information will be sorted to match the order of statements in the userSchema.
+ */
+ currentSchema: string;
+ /** The expected SDL schema. This schema will be checked for correctness and normalized. */
+ expectedSchema: string;
+}
+
+export interface PrettyResponse {
+ /** The pretty-formatted version of current schema. */
+ currentSchema: string;
+ /** The expected SDL schema after normalizing. */
+ expectedSchema: string;
+}
+
+function createBasePrettyRequest(): PrettyRequest {
+ return { engine: 0, currentSchema: "", expectedSchema: "" };
+}
+
+export const PrettyRequest = {
+ encode(message: PrettyRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.engine !== 0) {
+ writer.uint32(8).int32(message.engine);
+ }
+ if (message.currentSchema !== "") {
+ writer.uint32(18).string(message.currentSchema);
+ }
+ if (message.expectedSchema !== "") {
+ writer.uint32(26).string(message.expectedSchema);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): PrettyRequest {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBasePrettyRequest();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.engine = reader.int32() as any;
+ break;
+ case 2:
+ message.currentSchema = reader.string();
+ break;
+ case 3:
+ message.expectedSchema = reader.string();
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): PrettyRequest {
+ return {
+ engine: isSet(object.engine) ? engineFromJSON(object.engine) : 0,
+ currentSchema: isSet(object.currentSchema) ? String(object.currentSchema) : "",
+ expectedSchema: isSet(object.expectedSchema) ? String(object.expectedSchema) : "",
+ };
+ },
+
+ toJSON(message: PrettyRequest): unknown {
+ const obj: any = {};
+ message.engine !== undefined && (obj.engine = engineToJSON(message.engine));
+ message.currentSchema !== undefined && (obj.currentSchema = message.currentSchema);
+ message.expectedSchema !== undefined && (obj.expectedSchema = message.expectedSchema);
+ return obj;
+ },
+
+ fromPartial(object: DeepPartial<PrettyRequest>): PrettyRequest {
+ const message = createBasePrettyRequest();
+ message.engine = object.engine ?? 0;
+ message.currentSchema = object.currentSchema ?? "";
+ message.expectedSchema = object.expectedSchema ?? "";
+ return message;
+ },
+};
+
+function createBasePrettyResponse(): PrettyResponse {
+ return { currentSchema: "", expectedSchema: "" };
+}
+
+export const PrettyResponse = {
+ encode(message: PrettyResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.currentSchema !== "") {
+ writer.uint32(10).string(message.currentSchema);
+ }
+ if (message.expectedSchema !== "") {
+ writer.uint32(18).string(message.expectedSchema);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): PrettyResponse {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBasePrettyResponse();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.currentSchema = reader.string();
+ break;
+ case 2:
+ message.expectedSchema = reader.string();
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): PrettyResponse {
+ return {
+ currentSchema: isSet(object.currentSchema) ? String(object.currentSchema) : "",
+ expectedSchema: isSet(object.expectedSchema) ? String(object.expectedSchema) : "",
+ };
+ },
+
+ toJSON(message: PrettyResponse): unknown {
+ const obj: any = {};
+ message.currentSchema !== undefined && (obj.currentSchema = message.currentSchema);
+ message.expectedSchema !== undefined && (obj.expectedSchema = message.expectedSchema);
+ return obj;
+ },
+
+ fromPartial(object: DeepPartial<PrettyResponse>): PrettyResponse {
+ const message = createBasePrettyResponse();
+ message.currentSchema = object.currentSchema ?? "";
+ message.expectedSchema = object.expectedSchema ?? "";
+ return message;
+ },
+};
+
+export type SQLServiceDefinition = typeof SQLServiceDefinition;
+export const SQLServiceDefinition = {
+ name: "SQLService",
+ fullName: "bytebase.v1.SQLService",
+ methods: {
+ pretty: {
+ name: "Pretty",
+ requestType: PrettyRequest,
+ requestStream: false,
+ responseType: PrettyResponse,
+ responseStream: false,
+ options: {},
+ },
+ },
+} as const;
+
+export interface SQLServiceImplementation<CallContextExt = {}> {
+ pretty(request: PrettyRequest, context: CallContext & CallContextExt): Promise<DeepPartial<PrettyResponse>>;
+}
+
+export interface SQLServiceClient<CallOptionsExt = {}> {
+ pretty(request: DeepPartial<PrettyRequest>, options?: CallOptions & CallOptionsExt): Promise<PrettyResponse>;
+}
+
+type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
+
+export type DeepPartial<T> = T extends Builtin ? T
+ : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
+ : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
+ : Partial<T>;
+
+function isSet(value: any): boolean {
+ return value !== null && value !== undefined;
+}
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 7ee17f429e..ad94fd2452 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -237,6 +237,12 @@
- [SettingService](#bytebase-v1-SettingService)
+- [v1/sql_service.proto](#v1_sql_service-proto)
+ - [PrettyRequest](#bytebase-v1-PrettyRequest)
+ - [PrettyResponse](#bytebase-v1-PrettyResponse)
+
+ - [SQLService](#bytebase-v1-SQLService)
+
- [Scalar Value Types](#scalar-value-types)
@@ -3533,6 +3539,65 @@ The data in setting value.
+<a name="v1_sql_service-proto"></a>
+<p align="right"><a href="#top">Top</a></p>
+
+## v1/sql_service.proto
+
+
+
+<a name="bytebase-v1-PrettyRequest"></a>
+
+### PrettyRequest
+
+
+
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| engine | [Engine](#bytebase-v1-Engine) | | |
+| current_schema | [string](#string) | | The SDL format SQL schema information that was dumped from a database engine. This information will be sorted to match the order of statements in the userSchema. |
+| expected_schema | [string](#string) | | The expected SDL schema. This schema will be checked for correctness and normalized. |
+
+
+
+
+
+
+<a name="bytebase-v1-PrettyResponse"></a>
+
+### PrettyResponse
+
+
+
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| current_schema | [string](#string) | | The pretty-formatted version of current schema. |
+| expected_schema | [string](#string) | | The expected SDL schema after normalizing. |
+
+
+
+
+
+
+
+
+
+
+
+
+<a name="bytebase-v1-SQLService"></a>
+
+### SQLService
+
+
+| Method Name | Request Type | Response Type | Description |
+| ----------- | ------------ | ------------- | ------------|
+| Pretty | [PrettyRequest](#bytebase-v1-PrettyRequest) | [PrettyResponse](#bytebase-v1-PrettyResponse) | |
+
+
+
+
+
## Scalar Value Types
| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |
diff --git a/proto/generated-go/v1/sql_service.pb.go b/proto/generated-go/v1/sql_service.pb.go
new file mode 100644
index 0000000000..c326b336a6
--- /dev/null
+++ b/proto/generated-go/v1/sql_service.pb.go
@@ -0,0 +1,260 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// versions:
+// protoc-gen-go v1.28.1
+// protoc (unknown)
+// source: v1/sql_service.proto
+
+package v1
+
+import (
+ _ "google.golang.org/genproto/googleapis/api/annotations"
+ protoreflect "google.golang.org/protobuf/reflect/protoreflect"
+ protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+ reflect "reflect"
+ sync "sync"
+)
+
+const (
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
+)
+
+type PrettyRequest struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ Engine Engine `protobuf:"varint,1,opt,name=engine,proto3,enum=bytebase.v1.Engine" json:"engine,omitempty"`
+ // The SDL format SQL schema information that was dumped from a database engine.
+ // This information will be sorted to match the order of statements in the userSchema.
+ CurrentSchema string `protobuf:"bytes,2,opt,name=current_schema,json=currentSchema,proto3" json:"current_schema,omitempty"`
+ // The expected SDL schema. This schema will be checked for correctness and normalized.
+ ExpectedSchema string `protobuf:"bytes,3,opt,name=expected_schema,json=expectedSchema,proto3" json:"expected_schema,omitempty"`
+}
+
+func (x *PrettyRequest) Reset() {
+ *x = PrettyRequest{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_v1_sql_service_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *PrettyRequest) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*PrettyRequest) ProtoMessage() {}
+
+func (x *PrettyRequest) ProtoReflect() protoreflect.Message {
+ mi := &file_v1_sql_service_proto_msgTypes[0]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use PrettyRequest.ProtoReflect.Descriptor instead.
+func (*PrettyRequest) Descriptor() ([]byte, []int) {
+ return file_v1_sql_service_proto_rawDescGZIP(), []int{0}
+}
+
+func (x *PrettyRequest) GetEngine() Engine {
+ if x != nil {
+ return x.Engine
+ }
+ return Engine_ENGINE_UNSPECIFIED
+}
+
+func (x *PrettyRequest) GetCurrentSchema() string {
+ if x != nil {
+ return x.CurrentSchema
+ }
+ return ""
+}
+
+func (x *PrettyRequest) GetExpectedSchema() string {
+ if x != nil {
+ return x.ExpectedSchema
+ }
+ return ""
+}
+
+type PrettyResponse struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ // The pretty-formatted version of current schema.
+ CurrentSchema string `protobuf:"bytes,1,opt,name=current_schema,json=currentSchema,proto3" json:"current_schema,omitempty"`
+ // The expected SDL schema after normalizing.
+ ExpectedSchema string `protobuf:"bytes,2,opt,name=expected_schema,json=expectedSchema,proto3" json:"expected_schema,omitempty"`
+}
+
+func (x *PrettyResponse) Reset() {
+ *x = PrettyResponse{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_v1_sql_service_proto_msgTypes[1]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *PrettyResponse) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*PrettyResponse) ProtoMessage() {}
+
+func (x *PrettyResponse) ProtoReflect() protoreflect.Message {
+ mi := &file_v1_sql_service_proto_msgTypes[1]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use PrettyResponse.ProtoReflect.Descriptor instead.
+func (*PrettyResponse) Descriptor() ([]byte, []int) {
+ return file_v1_sql_service_proto_rawDescGZIP(), []int{1}
+}
+
+func (x *PrettyResponse) GetCurrentSchema() string {
+ if x != nil {
+ return x.CurrentSchema
+ }
+ return ""
+}
+
+func (x *PrettyResponse) GetExpectedSchema() string {
+ if x != nil {
+ return x.ExpectedSchema
+ }
+ return ""
+}
+
+var File_v1_sql_service_proto protoreflect.FileDescriptor
+
+var file_v1_sql_service_proto_rawDesc = []byte{
+ 0x0a, 0x14, 0x76, 0x31, 0x2f, 0x73, 0x71, 0x6c, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
+ 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65,
+ 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f,
+ 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74,
+ 0x6f, 0x1a, 0x0f, 0x76, 0x31, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f,
+ 0x74, 0x6f, 0x22, 0x8c, 0x01, 0x0a, 0x0d, 0x50, 0x72, 0x65, 0x74, 0x74, 0x79, 0x52, 0x65, 0x71,
+ 0x75, 0x65, 0x73, 0x74, 0x12, 0x2b, 0x0a, 0x06, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x18, 0x01,
+ 0x20, 0x01, 0x28, 0x0e, 0x32, 0x13, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e,
+ 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x52, 0x06, 0x65, 0x6e, 0x67, 0x69, 0x6e,
+ 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x73, 0x63, 0x68,
+ 0x65, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x75, 0x72, 0x72, 0x65,
+ 0x6e, 0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x27, 0x0a, 0x0f, 0x65, 0x78, 0x70, 0x65,
+ 0x63, 0x74, 0x65, 0x64, 0x5f, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28,
+ 0x09, 0x52, 0x0e, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x53, 0x63, 0x68, 0x65, 0x6d,
+ 0x61, 0x22, 0x60, 0x0a, 0x0e, 0x50, 0x72, 0x65, 0x74, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f,
+ 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x73,
+ 0x63, 0x68, 0x65, 0x6d, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x75, 0x72,
+ 0x72, 0x65, 0x6e, 0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x27, 0x0a, 0x0f, 0x65, 0x78,
+ 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x18, 0x02, 0x20,
+ 0x01, 0x28, 0x09, 0x52, 0x0e, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x53, 0x63, 0x68,
+ 0x65, 0x6d, 0x61, 0x32, 0x6a, 0x0a, 0x0a, 0x53, 0x51, 0x4c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
+ 0x65, 0x12, 0x5c, 0x0a, 0x06, 0x50, 0x72, 0x65, 0x74, 0x74, 0x79, 0x12, 0x1a, 0x2e, 0x62, 0x79,
+ 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x65, 0x74, 0x74, 0x79,
+ 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61,
+ 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x65, 0x74, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70,
+ 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x3a, 0x01, 0x2a, 0x22,
+ 0x0e, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x71, 0x6c, 0x2f, 0x70, 0x72, 0x65, 0x74, 0x74, 0x79, 0x42,
+ 0x11, 0x5a, 0x0f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67, 0x6f, 0x2f,
+ 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+}
+
+var (
+ file_v1_sql_service_proto_rawDescOnce sync.Once
+ file_v1_sql_service_proto_rawDescData = file_v1_sql_service_proto_rawDesc
+)
+
+func file_v1_sql_service_proto_rawDescGZIP() []byte {
+ file_v1_sql_service_proto_rawDescOnce.Do(func() {
+ file_v1_sql_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_v1_sql_service_proto_rawDescData)
+ })
+ return file_v1_sql_service_proto_rawDescData
+}
+
+var file_v1_sql_service_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
+var file_v1_sql_service_proto_goTypes = []interface{}{
+ (*PrettyRequest)(nil), // 0: bytebase.v1.PrettyRequest
+ (*PrettyResponse)(nil), // 1: bytebase.v1.PrettyResponse
+ (Engine)(0), // 2: bytebase.v1.Engine
+}
+var file_v1_sql_service_proto_depIdxs = []int32{
+ 2, // 0: bytebase.v1.PrettyRequest.engine:type_name -> bytebase.v1.Engine
+ 0, // 1: bytebase.v1.SQLService.Pretty:input_type -> bytebase.v1.PrettyRequest
+ 1, // 2: bytebase.v1.SQLService.Pretty:output_type -> bytebase.v1.PrettyResponse
+ 2, // [2:3] is the sub-list for method output_type
+ 1, // [1:2] is the sub-list for method input_type
+ 1, // [1:1] is the sub-list for extension type_name
+ 1, // [1:1] is the sub-list for extension extendee
+ 0, // [0:1] is the sub-list for field type_name
+}
+
+func init() { file_v1_sql_service_proto_init() }
+func file_v1_sql_service_proto_init() {
+ if File_v1_sql_service_proto != nil {
+ return
+ }
+ file_v1_common_proto_init()
+ if !protoimpl.UnsafeEnabled {
+ file_v1_sql_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*PrettyRequest); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ file_v1_sql_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*PrettyResponse); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ }
+ type x struct{}
+ out := protoimpl.TypeBuilder{
+ File: protoimpl.DescBuilder{
+ GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
+ RawDescriptor: file_v1_sql_service_proto_rawDesc,
+ NumEnums: 0,
+ NumMessages: 2,
+ NumExtensions: 0,
+ NumServices: 1,
+ },
+ GoTypes: file_v1_sql_service_proto_goTypes,
+ DependencyIndexes: file_v1_sql_service_proto_depIdxs,
+ MessageInfos: file_v1_sql_service_proto_msgTypes,
+ }.Build()
+ File_v1_sql_service_proto = out.File
+ file_v1_sql_service_proto_rawDesc = nil
+ file_v1_sql_service_proto_goTypes = nil
+ file_v1_sql_service_proto_depIdxs = nil
+}
diff --git a/proto/generated-go/v1/sql_service.pb.gw.go b/proto/generated-go/v1/sql_service.pb.gw.go
new file mode 100644
index 0000000000..3cc643ffaa
--- /dev/null
+++ b/proto/generated-go/v1/sql_service.pb.gw.go
@@ -0,0 +1,171 @@
+// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
+// source: v1/sql_service.proto
+
+/*
+Package v1 is a reverse proxy.
+
+It translates gRPC into RESTful JSON APIs.
+*/
+package v1
+
+import (
+ "context"
+ "io"
+ "net/http"
+
+ "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
+ "github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/grpclog"
+ "google.golang.org/grpc/metadata"
+ "google.golang.org/grpc/status"
+ "google.golang.org/protobuf/proto"
+)
+
+// Suppress "imported and not used" errors
+var _ codes.Code
+var _ io.Reader
+var _ status.Status
+var _ = runtime.String
+var _ = utilities.NewDoubleArray
+var _ = metadata.Join
+
+func request_SQLService_Pretty_0(ctx context.Context, marshaler runtime.Marshaler, client SQLServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
+ var protoReq PrettyRequest
+ var metadata runtime.ServerMetadata
+
+ newReader, berr := utilities.IOReaderFactory(req.Body)
+ if berr != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
+ }
+ if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+
+ msg, err := client.Pretty(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
+ return msg, metadata, err
+
+}
+
+func local_request_SQLService_Pretty_0(ctx context.Context, marshaler runtime.Marshaler, server SQLServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
+ var protoReq PrettyRequest
+ var metadata runtime.ServerMetadata
+
+ newReader, berr := utilities.IOReaderFactory(req.Body)
+ if berr != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
+ }
+ if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+
+ msg, err := server.Pretty(ctx, &protoReq)
+ return msg, metadata, err
+
+}
+
+// RegisterSQLServiceHandlerServer registers the http handlers for service SQLService to "mux".
+// UnaryRPC :call SQLServiceServer directly.
+// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
+// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterSQLServiceHandlerFromEndpoint instead.
+func RegisterSQLServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server SQLServiceServer) error {
+
+ mux.Handle("POST", pattern_SQLService_Pretty_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
+ ctx, cancel := context.WithCancel(req.Context())
+ defer cancel()
+ var stream runtime.ServerTransportStream
+ ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
+ inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
+ var err error
+ var annotatedContext context.Context
+ annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/bytebase.v1.SQLService/Pretty", runtime.WithHTTPPathPattern("/v1/sql/pretty"))
+ if err != nil {
+ runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
+ return
+ }
+ resp, md, err := local_request_SQLService_Pretty_0(annotatedContext, inboundMarshaler, server, req, pathParams)
+ md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
+ annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
+ if err != nil {
+ runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
+ return
+ }
+
+ forward_SQLService_Pretty_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
+
+ })
+
+ return nil
+}
+
+// RegisterSQLServiceHandlerFromEndpoint is same as RegisterSQLServiceHandler but
+// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
+func RegisterSQLServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
+ conn, err := grpc.Dial(endpoint, opts...)
+ if err != nil {
+ return err
+ }
+ defer func() {
+ if err != nil {
+ if cerr := conn.Close(); cerr != nil {
+ grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
+ }
+ return
+ }
+ go func() {
+ <-ctx.Done()
+ if cerr := conn.Close(); cerr != nil {
+ grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
+ }
+ }()
+ }()
+
+ return RegisterSQLServiceHandler(ctx, mux, conn)
+}
+
+// RegisterSQLServiceHandler registers the http handlers for service SQLService to "mux".
+// The handlers forward requests to the grpc endpoint over "conn".
+func RegisterSQLServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
+ return RegisterSQLServiceHandlerClient(ctx, mux, NewSQLServiceClient(conn))
+}
+
+// RegisterSQLServiceHandlerClient registers the http handlers for service SQLService
+// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "SQLServiceClient".
+// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "SQLServiceClient"
+// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
+// "SQLServiceClient" to call the correct interceptors.
+func RegisterSQLServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client SQLServiceClient) error {
+
+ mux.Handle("POST", pattern_SQLService_Pretty_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
+ ctx, cancel := context.WithCancel(req.Context())
+ defer cancel()
+ inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
+ var err error
+ var annotatedContext context.Context
+ annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/bytebase.v1.SQLService/Pretty", runtime.WithHTTPPathPattern("/v1/sql/pretty"))
+ if err != nil {
+ runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
+ return
+ }
+ resp, md, err := request_SQLService_Pretty_0(annotatedContext, inboundMarshaler, client, req, pathParams)
+ annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
+ if err != nil {
+ runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
+ return
+ }
+
+ forward_SQLService_Pretty_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
+
+ })
+
+ return nil
+}
+
+var (
+ pattern_SQLService_Pretty_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "sql", "pretty"}, ""))
+)
+
+var (
+ forward_SQLService_Pretty_0 = runtime.ForwardResponseMessage
+)
diff --git a/proto/generated-go/v1/sql_service_grpc.pb.go b/proto/generated-go/v1/sql_service_grpc.pb.go
new file mode 100644
index 0000000000..212788f011
--- /dev/null
+++ b/proto/generated-go/v1/sql_service_grpc.pb.go
@@ -0,0 +1,105 @@
+// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
+// versions:
+// - protoc-gen-go-grpc v1.2.0
+// - protoc (unknown)
+// source: v1/sql_service.proto
+
+package v1
+
+import (
+ context "context"
+ grpc "google.golang.org/grpc"
+ codes "google.golang.org/grpc/codes"
+ status "google.golang.org/grpc/status"
+)
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the grpc package it is being compiled against.
+// Requires gRPC-Go v1.32.0 or later.
+const _ = grpc.SupportPackageIsVersion7
+
+// SQLServiceClient is the client API for SQLService service.
+//
+// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
+type SQLServiceClient interface {
+ Pretty(ctx context.Context, in *PrettyRequest, opts ...grpc.CallOption) (*PrettyResponse, error)
+}
+
+type sQLServiceClient struct {
+ cc grpc.ClientConnInterface
+}
+
+func NewSQLServiceClient(cc grpc.ClientConnInterface) SQLServiceClient {
+ return &sQLServiceClient{cc}
+}
+
+func (c *sQLServiceClient) Pretty(ctx context.Context, in *PrettyRequest, opts ...grpc.CallOption) (*PrettyResponse, error) {
+ out := new(PrettyResponse)
+ err := c.cc.Invoke(ctx, "/bytebase.v1.SQLService/Pretty", in, out, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+// SQLServiceServer is the server API for SQLService service.
+// All implementations must embed UnimplementedSQLServiceServer
+// for forward compatibility
+type SQLServiceServer interface {
+ Pretty(context.Context, *PrettyRequest) (*PrettyResponse, error)
+ mustEmbedUnimplementedSQLServiceServer()
+}
+
+// UnimplementedSQLServiceServer must be embedded to have forward compatible implementations.
+type UnimplementedSQLServiceServer struct {
+}
+
+func (UnimplementedSQLServiceServer) Pretty(context.Context, *PrettyRequest) (*PrettyResponse, error) {
+ return nil, status.Errorf(codes.Unimplemented, "method Pretty not implemented")
+}
+func (UnimplementedSQLServiceServer) mustEmbedUnimplementedSQLServiceServer() {}
+
+// UnsafeSQLServiceServer may be embedded to opt out of forward compatibility for this service.
+// Use of this interface is not recommended, as added methods to SQLServiceServer will
+// result in compilation errors.
+type UnsafeSQLServiceServer interface {
+ mustEmbedUnimplementedSQLServiceServer()
+}
+
+func RegisterSQLServiceServer(s grpc.ServiceRegistrar, srv SQLServiceServer) {
+ s.RegisterService(&SQLService_ServiceDesc, srv)
+}
+
+func _SQLService_Pretty_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+ in := new(PrettyRequest)
+ if err := dec(in); err != nil {
+ return nil, err
+ }
+ if interceptor == nil {
+ return srv.(SQLServiceServer).Pretty(ctx, in)
+ }
+ info := &grpc.UnaryServerInfo{
+ Server: srv,
+ FullMethod: "/bytebase.v1.SQLService/Pretty",
+ }
+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ return srv.(SQLServiceServer).Pretty(ctx, req.(*PrettyRequest))
+ }
+ return interceptor(ctx, in, info, handler)
+}
+
+// SQLService_ServiceDesc is the grpc.ServiceDesc for SQLService service.
+// It's only intended for direct use with grpc.RegisterService,
+// and not to be introspected or modified (even as a copy)
+var SQLService_ServiceDesc = grpc.ServiceDesc{
+ ServiceName: "bytebase.v1.SQLService",
+ HandlerType: (*SQLServiceServer)(nil),
+ Methods: []grpc.MethodDesc{
+ {
+ MethodName: "Pretty",
+ Handler: _SQLService_Pretty_Handler,
+ },
+ },
+ Streams: []grpc.StreamDesc{},
+ Metadata: "v1/sql_service.proto",
+}
diff --git a/proto/v1/sql_service.proto b/proto/v1/sql_service.proto
new file mode 100644
index 0000000000..8534f521ac
--- /dev/null
+++ b/proto/v1/sql_service.proto
@@ -0,0 +1,37 @@
+syntax = "proto3";
+
+package bytebase.v1;
+
+import "google/api/annotations.proto";
+
+import "v1/common.proto";
+
+option go_package = "generated-go/v1";
+
+service SQLService {
+ rpc Pretty(PrettyRequest) returns (PrettyResponse) {
+ option (google.api.http) = {
+ post: "/v1/sql/pretty"
+ body: "*"
+ };
+ }
+}
+
+message PrettyRequest {
+ Engine engine = 1;
+
+ // The SDL format SQL schema information that was dumped from a database engine.
+ // This information will be sorted to match the order of statements in the userSchema.
+ string current_schema = 2;
+
+ // The expected SDL schema. This schema will be checked for correctness and normalized.
+ string expected_schema = 3;
+}
+
+message PrettyResponse {
+ // The pretty-formatted version of current schema.
+ string current_schema = 1;
+
+ // The expected SDL schema after normalizing.
+ string expected_schema = 2;
+}
\ No newline at end of file