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: implement DifferPreview (#7521)
rebelice7ad613b9ca51
diff --git a/backend/api/v1/schema_design_service.go b/backend/api/v1/schema_design_service.goindex 7ed3390be5..3cb46dcb38 100644--- a/backend/api/v1/schema_design_service.go+++ b/backend/api/v1/schema_design_service.go@@ -1087,7 +1087,11 @@ func (t *mysqlTransformer) EnterColumnDefinition(ctx *mysql.ColumnDefinitionContfunc getDesignSchema(engine v1pb.Engine, baselineSchema string, to *v1pb.DatabaseMetadata) (string, error) {switch engine {case v1pb.Engine_MYSQL:- return getMySQLDesignSchema(baselineSchema, to)+ result, err := getMySQLDesignSchema(baselineSchema, to)+ if err != nil {+ return "", status.Errorf(codes.Internal, "failed to generate design schema: %v", err)+ }+ return result, nildefault:return "", status.Errorf(codes.InvalidArgument, fmt.Sprintf("unsupported engine: %v", engine))}@@ -1101,16 +1105,32 @@ func getMySQLDesignSchema(baselineSchema string, to *v1pb.DatabaseMetadata) (str}listener := &mysqlDesignSchemaGenerator{- to: toState,+ lastTokenIndex: 0,+ to: toState,}for _, stmt := range list {+ listener.lastTokenIndex = 0antlr.ParseTreeWalkerDefault.Walk(listener, stmt.Tree)+ if listener.err != nil {+ break+ }++ if _, err := listener.result.WriteString(+ stmt.Tokens.GetTextFromInterval(antlr.Interval{+ Start: listener.lastTokenIndex,+ Stop: stmt.Tokens.Size() - 1,+ }),+ ); err != nil {+ return "", err+ }}if listener.err != nil {return "", listener.err}+ firstTable := true+// Follow the order of the input schemas.for _, schema := range to.Schemas {schemaState, ok := toState.schemas[schema.Name]@@ -1123,6 +1143,12 @@ func getMySQLDesignSchema(baselineSchema string, to *v1pb.DatabaseMetadata) (strif !ok {continue}+ if firstTable {+ firstTable = false+ if _, err := listener.result.WriteString("\n\n"); err != nil {+ return "", err+ }+ }if err := table.toString(&listener.result); err != nil {return "", err}@@ -1142,6 +1168,8 @@ type mysqlDesignSchemaGenerator struct {columnDefine strings.BuildertableConstraints strings.Buildererr error++ lastTokenIndex int}// EnterCreateTable is called when production createTable is entered.@@ -1162,6 +1190,17 @@ func (g *mysqlDesignSchemaGenerator) EnterCreateTable(ctx *mysql.CreateTableConttable, ok := schema.tables[tableName]if !ok {+ g.lastTokenIndex = ctx.GetParser().GetTokenStream().Size() - 1+ return+ }++ if _, err := g.result.WriteString(+ ctx.GetParser().GetTokenStream().GetTextFromInterval(antlr.Interval{+ Start: g.lastTokenIndex,+ Stop: ctx.GetStart().GetTokenIndex() - 1,+ }),+ ); err != nil {+ g.err = errreturn}@@ -1171,10 +1210,6 @@ func (g *mysqlDesignSchemaGenerator) EnterCreateTable(ctx *mysql.CreateTableContg.tableConstraints.Reset()delete(schema.tables, tableName)- if _, err := g.result.WriteString("CREATE "); err != nil {- g.err = err- return- }if _, err := g.result.WriteString(ctx.GetParser().GetTokenStream().GetTextFromInterval(antlr.Interval{Start: ctx.GetStart().GetTokenIndex(),Stop: ctx.TableElementList().GetStart().GetTokenIndex() - 1,@@ -1260,19 +1295,17 @@ func (g *mysqlDesignSchemaGenerator) ExitCreateTable(ctx *mysql.CreateTableConteif _, err := g.result.WriteString(ctx.GetParser().GetTokenStream().GetTextFromInterval(antlr.Interval{Start: ctx.TableElementList().GetStop().GetTokenIndex() + 1,- Stop: ctx.GetStop().GetTokenIndex(),+ // Write all tokens until the end of the statement.+ // Because we listen one statement at a time, we can safely use the last token index.+ Stop: ctx.GetParser().GetTokenStream().Size() - 1,})); err != nil {g.err = errreturn}- if _, err := g.result.WriteString(";\n"); err != nil {- g.err = err- return- }-g.currentTable = nilg.firstElementInTable = false+ g.lastTokenIndex = ctx.GetParser().GetTokenStream().Size() - 1}type columnAttr struct {@@ -1492,7 +1525,7 @@ func (g *mysqlDesignSchemaGenerator) EnterColumnDefinition(ctx *mysql.ColumnDefi// compare column typetypeCtx := ctx.FieldDefinition().DataType()columnType := ctx.GetParser().GetTokenStream().GetTextFromRuleContext(typeCtx)- if columnType != column.tp {+ if !strings.EqualFold(columnType, column.tp) {if _, err := g.columnDefine.WriteString(ctx.GetParser().GetTokenStream().GetTextFromInterval(antlr.Interval{Start: ctx.GetStart().GetTokenIndex(),Stop: typeCtx.GetStart().GetTokenIndex() - 1,@@ -1500,7 +1533,8 @@ func (g *mysqlDesignSchemaGenerator) EnterColumnDefinition(ctx *mysql.ColumnDefig.err = errreturn}- if _, err := g.columnDefine.WriteString(column.tp); err != nil {+ // write lower case column type for MySQL+ if _, err := g.columnDefine.WriteString(strings.ToLower(column.tp)); err != nil {g.err = errreturn}diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.goindex 996f5aa521..d25b1f59db 100644--- a/backend/api/v1/sql_service.go+++ b/backend/api/v1/sql_service.go@@ -2356,3 +2356,15 @@ func encodeToBase64String(statement string) string {base64Encoded := base64.StdEncoding.EncodeToString([]byte(statement))return base64Encoded}++// DifferPreview returns the diff preview of the given SQL statement and metadata.+func (*SQLService) DifferPreview(_ context.Context, request *v1pb.DifferPreviewRequest) (*v1pb.DifferPreviewResponse, error) {+ schema, err := getDesignSchema(request.Engine, request.OldSchema, request.NewMetadata)+ if err != nil {+ return nil, err+ }++ return &v1pb.DifferPreviewResponse{+ Schema: schema,+ }, nil+}diff --git a/backend/api/v1/testdata/design.yaml b/backend/api/v1/testdata/design.yamlindex 5332c9ff0f..30f46b3a1f 100644--- a/backend/api/v1/testdata/design.yaml+++ b/backend/api/v1/testdata/design.yaml@@ -191,6 +191,7 @@PRIMARY KEY (`a`, `b`, `c`),CONSTRAINT `fk1` FOREIGN KEY (`b`) REFERENCES `t2` (`b`));+CREATE TABLE `t2` (`b` int NULL,`a` int NULL,diff --git a/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml b/backend/plugin/advisor/catalog/test/mysql_walk_through.yamlindex 14be99235c..a48f3a720d 100644--- a/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml+++ b/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml@@ -12,7 +12,7 @@err:type: 407content: BLOB, TEXT, GEOMETRY or JSON column `a` can't have a default value- line: 3+ line: 2payload: null- statement: ' CREATE TABLE t(a TEXT DEFAULT ''1'')'want: null@@ -28,7 +28,7 @@err:type: 406content: Invalid default value for column `a`- line: 3+ line: 2payload: null- statement: ' CREATE TABLE t(a INT NOT NULL DEFAULT NULL)'want: null@@ -49,65 +49,63 @@err:type: 404content: There can be only one auto column for table `t`- line: 2+ line: 1payload: null- statement: ' CREATE TABLE t as select * from t1;'want: nullerr:type: 303- content: |-- Disallow the CREATE TABLE AS statement but "CREATE TABLE t as select * from t1- ;" uses- line: 2+ content: Disallow the CREATE TABLE AS statement but "CREATE TABLE t as select * from t1;" uses+ line: 1payload: null- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tCREATE INDEX idx_c on t(c);\n\t\t\t"want: nullerr:type: 402content: Column `c` does not exist in table `t`- line: 4+ line: 3payload: null- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t MODIFY COLUMN c int;\n\t\t\t"want: nullerr:type: 402content: Column `c` does not exist in table `t`- line: 4+ line: 3payload: null- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t CHANGE COLUMN c aa int;\n\t\t\t"want: nullerr:type: 402content: Column `c` does not exist in table `t`- line: 4+ line: 3payload: null- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t DROP COLUMN c;\n\t\t\t"want: nullerr:type: 402content: Column `c` does not exist in table `t`- line: 4+ line: 3payload: null- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t RENAME COLUMN c TO cc;\n\t\t\t"want: nullerr:type: 402content: Column `c` does not exist in table `t`- line: 4+ line: 3payload: null- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t RENAME COLUMN c TO cc;\n\t\t\t"want: nullerr:type: 402content: Column `c` does not exist in table `t`- line: 4+ line: 3payload: null- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t ALTER COLUMN c DROP DEFAULT;\n\t\t\t"want: nullerr:type: 402content: Column `c` does not exist in table `t`- line: 4+ line: 3payload: null- statement: |-ALTER DATABASE CHARACTER SET = utf8mb4;@@ -119,10 +117,13 @@tables: []views: []functions: []+ streams: []+ tasks: []characterset: utf8mb4collation: utf8mb4_polish_ciextensions: []datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE t(@@ -152,6 +153,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default: null@@ -160,6 +163,8 @@characterset: utf8mb4collation: ""comment: ""+ classification: ""+ usercomment: ""- name: cposition: 3default: null@@ -168,6 +173,8 @@characterset: ""collation: ""comment: This is a comment+ classification: ""+ usercomment: ""- name: dposition: 4default: null@@ -176,6 +183,8 @@characterset: ""collation: utf8mb4_polish_cicomment: ""+ classification: ""+ usercomment: ""indexes:- name: PRIMARYexpressions:@@ -237,6 +246,8 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []- name: t_copycolumns:@@ -249,6 +260,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default: null@@ -257,6 +270,8 @@characterset: utf8mb4collation: ""comment: ""+ classification: ""+ usercomment: ""- name: cposition: 3default: null@@ -265,6 +280,8 @@characterset: ""collation: ""comment: This is a comment+ classification: ""+ usercomment: ""- name: dposition: 4default: null@@ -273,6 +290,8 @@characterset: ""collation: utf8mb4_polish_cicomment: ""+ classification: ""+ usercomment: ""indexes:- name: PRIMARYexpressions:@@ -334,13 +353,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE t(@@ -369,6 +393,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default: null@@ -377,6 +403,8 @@characterset: utf8mb4collation: ""comment: ""+ classification: ""+ usercomment: ""- name: cposition: 3default: null@@ -385,6 +413,8 @@characterset: ""collation: ""comment: This is a comment+ classification: ""+ usercomment: ""- name: dposition: 4default: null@@ -393,6 +423,8 @@characterset: ""collation: utf8mb4_polish_cicomment: ""+ classification: ""+ usercomment: ""indexes:- name: PRIMARYexpressions:@@ -454,13 +486,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE t(@@ -483,6 +520,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default: null@@ -491,6 +530,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes:- name: PRIMARYexpressions:@@ -509,13 +550,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE t1(a int, b int, c int);@@ -528,17 +574,20 @@tables: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []datashare: false+ servicename: ""err: null- statement: ' DROP TABLE t1, t2'want: nullerr:type: 302content: Table `t1` does not exist- line: 2+ line: 1payload: null- statement: |-CREATE TABLE t(a int);@@ -550,10 +599,13 @@tables: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE t(a int);@@ -573,6 +625,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -582,13 +636,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []datashare: false+ servicename: ""err: null- statement: |--- this is comment@@ -598,7 +657,7 @@err:type: 202content: Database `test` is deleted- line: 4+ line: 3payload: null- statement: |-CREATE TABLE t(@@ -640,6 +699,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: a_copyposition: 2default: null@@ -648,6 +709,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: a1position: 3default: null@@ -656,6 +719,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: d_copyposition: 4default: null@@ -664,6 +729,8 @@characterset: ""collation: utf8mb4_polish_cicomment: ""+ classification: ""+ usercomment: ""- name: eposition: 5default: null@@ -672,6 +739,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes:- name: b_3expressions:@@ -724,13 +793,18 @@datafree: 0createoptions: ""comment: This is a table comment+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE t(@@ -759,6 +833,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default: null@@ -767,6 +843,8 @@characterset: utf8mb4collation: ""comment: ""+ classification: ""+ usercomment: ""- name: cposition: 3default: null@@ -775,6 +853,8 @@characterset: ""collation: ""comment: This is a comment+ classification: ""+ usercomment: ""- name: dposition: 4default: null@@ -783,6 +863,8 @@characterset: ""collation: utf8mb4_polish_cicomment: ""+ classification: ""+ usercomment: ""indexes:- name: PRIMARYexpressions:@@ -844,13 +926,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE t(@@ -874,6 +961,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default: null@@ -882,6 +971,8 @@characterset: utf8mb4collation: ""comment: ""+ classification: ""+ usercomment: ""indexes:- name: PRIMARYexpressions:@@ -899,11 +990,16 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []datashare: false+ servicename: ""err: nulldiff --git a/backend/plugin/advisor/catalog/test/mysql_walk_through_for_incomplete.yaml b/backend/plugin/advisor/catalog/test/mysql_walk_through_for_incomplete.yamlindex df1706591a..f1244fec7f 100644--- a/backend/plugin/advisor/catalog/test/mysql_walk_through_for_incomplete.yaml+++ b/backend/plugin/advisor/catalog/test/mysql_walk_through_for_incomplete.yaml@@ -23,12 +23,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: ALTER TABLE t RENAME COLUMN a TO a_copywant:@@ -46,6 +52,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -55,12 +63,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: ALTER TABLE t RENAME TO t1want:@@ -79,12 +93,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: |-ALTER TABLE t ADD PRIMARY KEY (a);@@ -161,12 +181,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE t(@@ -195,6 +221,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default: null@@ -203,6 +231,8 @@characterset: utf8mb4collation: ""comment: ""+ classification: ""+ usercomment: ""- name: cposition: 3default: null@@ -211,6 +241,8 @@characterset: ""collation: ""comment: This is a comment+ classification: ""+ usercomment: ""- name: dposition: 4default: null@@ -219,6 +251,8 @@characterset: ""collation: utf8mb4_polish_cicomment: ""+ classification: ""+ usercomment: ""indexes:- name: PRIMARYexpressions:@@ -280,12 +314,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: DROP TABLE t1, t2want:@@ -295,9 +335,13 @@tables: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: INSERT INTO test values (1)want:@@ -307,7 +351,11 @@tables: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: nulldiff --git a/backend/plugin/advisor/catalog/test/pg_walk_through.yaml b/backend/plugin/advisor/catalog/test/pg_walk_through.yamlindex a6dbadcbdf..22070e4f34 100644--- a/backend/plugin/advisor/catalog/test/pg_walk_through.yaml+++ b/backend/plugin/advisor/catalog/test/pg_walk_through.yaml@@ -14,6 +14,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default: null@@ -22,6 +24,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -31,6 +35,8 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []- name: testcolumns:@@ -42,6 +48,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: nameposition: 2default: null@@ -50,6 +58,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -59,12 +69,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE public.t(a int, "B" int);@@ -85,6 +101,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: Bposition: 2default: null@@ -93,6 +111,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes:- name: t_a_B_idxexpressions:@@ -120,6 +140,8 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []- name: testcolumns:@@ -131,6 +153,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: nameposition: 2default: null@@ -139,6 +163,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -148,12 +174,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE public.t(@@ -178,6 +210,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default:@@ -187,6 +221,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: cposition: 3default: null@@ -195,6 +231,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes:- name: t_a_b_c_idxexpressions:@@ -239,6 +277,8 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []- name: testcolumns:@@ -250,6 +290,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: nameposition: 2default: null@@ -258,6 +300,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -267,12 +311,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE public.t(@@ -310,6 +360,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default: null@@ -318,6 +370,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: dposition: 4default: null@@ -326,6 +380,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes:- name: t_a_b_c_idxexpressions:@@ -378,6 +434,8 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []- name: testcolumns:@@ -389,6 +447,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: nameposition: 2default: null@@ -397,6 +457,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -406,12 +468,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE public.t(@@ -437,6 +505,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default:@@ -446,6 +516,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: cposition: 3default: null@@ -454,6 +526,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes:- name: t_a_b_c_idxexpressions:@@ -498,6 +572,8 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []- name: testcolumns:@@ -509,6 +585,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: nameposition: 2default: null@@ -517,6 +595,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -526,12 +606,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE public.t(@@ -557,6 +643,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: bposition: 2default:@@ -566,6 +654,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: cposition: 3default: null@@ -574,6 +664,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes:- name: t_a_b_c_idxexpressions:@@ -609,6 +701,8 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []- name: testcolumns:@@ -620,6 +714,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: nameposition: 2default: null@@ -628,6 +724,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -637,12 +735,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE public.t(@@ -668,6 +772,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: nameposition: 2default: null@@ -676,6 +782,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -685,12 +793,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: |-CREATE TABLE public.t(@@ -707,6 +821,8 @@characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: ALTER TABLE test DROP COLUMN id;want: null@@ -750,6 +866,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -759,12 +877,18 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: null- statement: |-create view v1 as select * from t;@@ -785,6 +909,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""- name: nameposition: 2default: null@@ -793,6 +919,8 @@characterset: ""collation: ""comment: ""+ classification: ""+ usercomment: ""indexes: []engine: ""collation: ""@@ -802,10 +930,16 @@datafree: 0createoptions: ""comment: ""+ classification: ""+ usercomment: ""foreignkeys: []views: []functions: []+ streams: []+ tasks: []characterset: ""collation: ""extensions: []+ datashare: false+ servicename: ""err: nulldiff --git a/backend/plugin/advisor/catalog/walk_through_test.go b/backend/plugin/advisor/catalog/walk_through_test.goindex e36ac0731f..e4721bfaa3 100644--- a/backend/plugin/advisor/catalog/walk_through_test.go+++ b/backend/plugin/advisor/catalog/walk_through_test.go@@ -199,6 +199,8 @@ func (d *DatabaseState) convertToSchemaMetadataList() []*storepb.SchemaMetadata// TODO(rebelice): convert views if needed.Views: []*storepb.ViewMetadata{},Functions: []*storepb.FunctionMetadata{},+ Streams: []*storepb.StreamMetadata{},+ Tasks: []*storepb.TaskMetadata{},}result = append(result, schemaMeta)diff --git a/backend/plugin/parser/sql/mysql.go b/backend/plugin/parser/sql/mysql.goindex 04a7df5e47..8c49b81307 100644--- a/backend/plugin/parser/sql/mysql.go+++ b/backend/plugin/parser/sql/mysql.go@@ -21,7 +21,6 @@ type MySQLParseResult struct {// ParseMySQL parses the given SQL statement and returns the AST.func ParseMySQL(statement string) ([]*MySQLParseResult, error) {- statement = strings.TrimRight(statement, " \r\n\t\f;") + "\n;"var err errorstatement, err = DealWithDelimiter(statement)if err != nil {@@ -341,6 +340,30 @@ func parseSingleStatement(statement string) (antlr.Tree, *antlr.CommonTokenStreareturn tree, stream, nil}+func mysqlAddSemicolonIfNeeded(sql string) string {+ lexer := parser.NewMySQLLexer(antlr.NewInputStream(sql))+ stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)+ stream.Fill()+ tokens := stream.GetAllTokens()+ for i := len(tokens) - 1; i >= 0; i-- {+ if tokens[i].GetChannel() != antlr.TokenDefaultChannel || tokens[i].GetTokenType() == parser.MySQLParserEOF {+ continue+ }++ // The last default channel token is a semicolon.+ if tokens[i].GetTokenType() == parser.MySQLParserSEMICOLON_SYMBOL {+ return sql+ }++ var result []string+ result = append(result, stream.GetTextFromInterval(antlr.NewInterval(0, tokens[i].GetTokenIndex())))+ result = append(result, ";")+ result = append(result, stream.GetTextFromInterval(antlr.NewInterval(tokens[i].GetTokenIndex()+1, tokens[len(tokens)-1].GetTokenIndex())))+ return strings.Join(result, "")+ }+ return sql+}+func parseInputStream(input *antlr.InputStream) ([]*MySQLParseResult, error) {var result []*MySQLParseResultlexer := parser.NewMySQLLexer(input)@@ -351,6 +374,10 @@ func parseInputStream(input *antlr.InputStream) ([]*MySQLParseResult, error) {return nil, err}+ if len(list) > 0 {+ list[len(list)-1].Text = mysqlAddSemicolonIfNeeded(list[len(list)-1].Text)+ }+for _, s := range list {tree, tokens, err := parseSingleStatement(s.Text)if err != nil {diff --git a/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue b/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vueindex c887f8864e..bc5301f35b 100644--- a/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue+++ b/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue@@ -265,6 +265,7 @@ import { computed, onMounted, reactive, ref, watch } from "vue";import { useI18n } from "vue-i18n";import EditSchemaDesignPanel from "@/components/SchemaDesigner/EditSchemaDesignPanel.vue";import { InstanceV1EngineIcon } from "@/components/v2";+import { sqlServiceClient } from "@/grpcweb";import {pushNotification,useDatabaseV1Store,@@ -331,6 +332,7 @@ const databaseDiffCache = reactive<}>>({});+const schemaDesignPreviewCache = reactive<Record<string, string>>({});const project = computed(() => {return useProjectV1Store().getProjectByUID(props.projectId);});@@ -345,7 +347,10 @@ const sourceDatabaseSchema = computed(() => {if (props.sourceSchemaType === "SCHEMA_HISTORY_VERSION") {return props.databaseSourceSchema?.changeHistory.schema || "";} else if (props.sourceSchemaType === "SCHEMA_DESIGN") {- return selectedSchemaDesign.value?.schema || "";+ const databaseId = state.selectedDatabaseId || "";+ return schemaDesignPreviewCache[+ databaseId + "|" + selectedSchemaDesign.value?.name+ ];} else if (props.sourceSchemaType === "RAW_SQL") {let statement = props.rawSqlState?.statement || "";if (props.rawSqlState?.sheetId) {@@ -495,6 +500,21 @@ watch(});+watch(+ () => [state.selectedDatabaseId, selectedSchemaDesign.value],+ async () => {+ const schema = await sqlServiceClient.differPreview({+ engine: engine.value,+ oldSchema: targetDatabaseSchema.value,+ newMetadata: selectedSchemaDesign.value?.schemaMetadata,+ });+ const databaseId = state.selectedDatabaseId || "";+ schemaDesignPreviewCache[+ databaseId + "|" + selectedSchemaDesign.value?.name+ ] = schema.schema;+ }+);+watch(() => [state.selectedDatabaseIdList, sourceDatabaseSchema.value],async (_, oldValue) => {