Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(mysql/structurer): generate remaining index/key (#10212)
h3n4l821344ee9e03
diff --git a/backend/plugin/schema/mysql/get_design_schema.go b/backend/plugin/schema/mysql/get_design_schema.goindex b344e62aaf..0aeb22695f 100644--- a/backend/plugin/schema/mysql/get_design_schema.go+++ b/backend/plugin/schema/mysql/get_design_schema.go@@ -190,6 +190,29 @@ func (g *mysqlDesignSchemaGenerator) ExitCreateTable(ctx *mysql.CreateTableConteif err := g.currentTable.indexes["PRIMARY"].toString(&g.tableConstraints); err != nil {return}+ delete(g.currentTable.indexes, "PRIMARY")+ }++ var indexes []*indexState+ for _, index := range g.currentTable.indexes {+ indexes = append(indexes, index)+ }+ sort.Slice(indexes, func(i, j int) bool {+ return indexes[i].id < indexes[j].id+ })+ for _, index := range indexes {+ if g.firstElementInTable {+ g.firstElementInTable = false+ } else {+ if _, err := g.columnDefine.WriteString(",\n "); err != nil {+ g.err = err+ return+ }+ }+ if err := index.toString(&g.tableConstraints); err != nil {+ g.err = err+ return+ }}var fks []*foreignKeyStatediff --git a/backend/plugin/schema/mysql/state.go b/backend/plugin/schema/mysql/state.goindex 62baa79824..416abe5076 100644--- a/backend/plugin/schema/mysql/state.go+++ b/backend/plugin/schema/mysql/state.go@@ -341,6 +341,7 @@ type indexState struct {primary boolunique booltp string+ comment string}func (i *indexState) convertToIndexMetadata() *storepb.IndexMetadata {@@ -349,8 +350,10 @@ func (i *indexState) convertToIndexMetadata() *storepb.IndexMetadata {Expressions: i.keys,Primary: i.primary,Unique: i.unique,+ Comment: i.comment,// Unsupported, for tests only.Visible: true,+ Type: i.tp,}}@@ -362,6 +365,7 @@ func convertToIndexState(id int, index *storepb.IndexMetadata) *indexState {primary: index.Primary,unique: index.Unique,tp: index.Type,+ comment: index.Comment,}}@@ -435,6 +439,12 @@ func (i *indexState) toString(buf *strings.Builder) error {return err}}++ if i.comment != "" {+ if _, err := buf.WriteString(fmt.Sprintf(" COMMENT '%s'", i.comment)); err != nil {+ return err+ }+ }}return nil}diff --git a/backend/plugin/schema/mysql/testdata/get_design_schema.yaml b/backend/plugin/schema/mysql/testdata/get_design_schema.yamlindex 5e2ff98479..2c5950d813 100644--- a/backend/plugin/schema/mysql/testdata/get_design_schema.yaml+++ b/backend/plugin/schema/mysql/testdata/get_design_schema.yaml@@ -27,6 +27,18 @@"name": "a","type": "int"}+ ],+ "indexes": [+ {+ "name": "t_a_uniq_idx",+ "expressions": [+ "a"+ ],+ "unique": true,+ "primary": false,+ "visible": true,+ "comment": "this is my comment ''!!"+ }]},{@@ -204,7 +216,8 @@}result: |+CREATE TABLE `t` (- `a` int NOT NULL+ `a` int NOT NULL,+ UNIQUE KEY `t_a_uniq_idx` (`a`) COMMENT 'this is my comment ''!!') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;CREATE TABLE `t4` (`a` varchar(10) NOT NULL DEFAULT 'default value' COMMENT 'this is comment, aha',diff --git a/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml b/backend/plugin/schema/mysql/testdata/parse_to_metadata.yamlindex 92b27ea9a7..d03b8c4e16 100644--- a/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml+++ b/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml@@ -55,6 +55,7 @@"expressions": ["c"],+ "type": "BTREE","unique": true,"visible": true},@@ -63,6 +64,7 @@"expressions": ["((`c` + 5))"],+ "type": "BTREE","unique": true,"visible": true},@@ -72,6 +74,7 @@"((`c` + 5))","((`c` + 3))"],+ "type": "BTREE","unique": true,"visible": true},@@ -80,6 +83,7 @@"expressions": ["c"],+ "type": "BTREE","visible": true},{@@ -87,6 +91,7 @@"expressions": ["d"],+ "type": "BTREE","visible": true},{@@ -94,6 +99,7 @@"expressions": ["d"],+ "type": "FULLTEXT","visible": true}],