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(branch): keep empty blocks for TiDB (#10405)
rebelice9b534121e4d7
diff --git a/backend/plugin/parser/tidb/split.go b/backend/plugin/parser/tidb/split.goindex 88bd3c5c4c..f80cbac7c6 100644--- a/backend/plugin/parser/tidb/split.go+++ b/backend/plugin/parser/tidb/split.go@@ -19,3 +19,14 @@ func SplitSQL(statement string) ([]base.SingleSQL, error) {}return list, nil}++// SplitSQLKeepEmptyBlocks splits the given SQL statement into multiple SQL statements.+// TODO: remove SplitSQL, and rename this to SplitSQL.+func SplitSQLKeepEmptyBlocks(statement string) ([]base.SingleSQL, error) {+ t := tokenizer.NewTokenizer(statement, tokenizer.KeepEmptyBlocks())+ list, err := t.SplitTiDBMultiSQL()+ if err != nil {+ return nil, err+ }+ return list, nil+}diff --git a/backend/plugin/parser/tidb/strings.go b/backend/plugin/parser/tidb/strings.goindex e66fcedfb1..66d4254c9d 100644--- a/backend/plugin/parser/tidb/strings.go+++ b/backend/plugin/parser/tidb/strings.go@@ -430,7 +430,7 @@ func (s *StringsManipulator) Manipulate(actions ...StringsManipulatorAction) (sttableActions[tableName] = append(tableActions[tableName], action)}- stmts, err := SplitSQL(s.s)+ stmts, err := SplitSQLKeepEmptyBlocks(s.s)if err != nil {return "", errors.Wrap(err, "failed to split sql")}@@ -498,6 +498,9 @@ func (s *StringsManipulator) Manipulate(actions ...StringsManipulatorAction) (st}}+ // Add a empty line at the end of the file+ results = append(results, "")+return strings.Join(results, "\n"), nil}@@ -555,9 +558,6 @@ func (r *rewriter) generateStatement() (string, error) {if _, err := buf.WriteString(r.suffixString); err != nil {return "", errors.Wrap(err, "failed to write string")}- if err := buf.WriteByte('\n'); err != nil {- return "", errors.Wrap(err, "failed to write byte")- }return buf.String(), nil}diff --git a/backend/plugin/parser/tidb/test-data/test_strings_manipulate.yaml b/backend/plugin/parser/tidb/test-data/test_strings_manipulate.yamlindex 0521811101..d7ca634879 100644--- a/backend/plugin/parser/tidb/test-data/test_strings_manipulate.yaml+++ b/backend/plugin/parser/tidb/test-data/test_strings_manipulate.yaml@@ -14,7 +14,7 @@arguments:- t- '`age` int NOT NULL'- want: |-+ want: |-- Table structure for `t`CREATE TABLE `t` (`id` int /* this is comment */,@@ -22,7 +22,6 @@`age` int NOT NULL,PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */);--- Table structure for `t1`CREATE TABLE `t1` (`id` int@@ -92,7 +91,7 @@arguments:- t1- age int NOT NULL- want: |-+ want: |-- Table structure for `t`CREATE TABLE `t` (`id` int NOT NULL,@@ -101,13 +100,11 @@UNIQUE KEY `name` (`id`, `name`),UNIQUE KEY `id` (`id`)) COMMENT 'this is comment' ;--- Table structure for `t1`CREATE TABLE `t1` (`id` int,age int NOT NULL) COMMENT 'this is comment 2';--- Table structure for `t2`CREATE TABLE `t2` (`id` intdiff --git a/backend/plugin/schema/tidb/testdata/get_design_schema.yaml b/backend/plugin/schema/tidb/testdata/get_design_schema.yamlindex 3dc68b723e..fd3962706c 100644--- a/backend/plugin/schema/tidb/testdata/get_design_schema.yaml+++ b/backend/plugin/schema/tidb/testdata/get_design_schema.yaml@@ -281,11 +281,10 @@}]}- result: |+ result: |+CREATE TABLE `t` (`a` int NOT NULL) ;-CREATE TABLE `t4` (`a` varchar(10) NOT NULL DEFAULT 'default value' COMMENT 'this is comment, aha',`c` int NOT NULL DEFAULT 1 COMMENT 'col_b',@@ -297,27 +296,23 @@CONSTRAINT `fk1` FOREIGN KEY (`b`) REFERENCES `t2` (`b`),UNIQUE KEY `uk_a` (`b`));-CREATE TABLE `users` (`id` int(11) NOT NULL COMMENT 'ID',`age` varbinary(500) NULL,`name` binary(10) NULL,PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'hello';-CREATE TABLE `rds` (`id` bigint(20) NOT NULL COMMENT 'ID',`binlog_format` enum('ROW','MIXED','STATEMENT',''),`c1` int AUTO_INCREMENT,`x1` blob NULL) COMMENT 'hello' ;-create table t5(a bigint NOT NULL /*T![auto_rand] AUTO_RANDOM(6, 54) */,primary key (a),UNIQUE KEY `udx_a` (`a`));----- Table structure for `t6`--@@ -336,6 +331,7 @@PRIMARY KEY (`b`),CONSTRAINT `fk1` FOREIGN KEY (`b`) REFERENCES `t4` (`b`));+- baseline: |-CREATE TABLE `t1` (`a` int primary key@@ -406,15 +402,12 @@CREATE TABLE `t1` (`a` int primary key AUTO_INCREMENT);-CREATE TABLE `t2` (`a` int primary key AUTO_INCREMENT);-CREATE TABLE `t3` (`a` int primary key AUTO_INCREMENT);-CREATE TABLE `t4` (`a` int primary key DEFAULT 1);