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(transformer): consider length and direction for mysql schema string transformer (#10090)
h3n4l05f3f7915362
diff --git a/backend/api/v1/schema_design_transformer.go b/backend/api/v1/schema_design_transformer.goindex dbf81a8fff..399c80742c 100644--- a/backend/api/v1/schema_design_transformer.go+++ b/backend/api/v1/schema_design_transformer.go@@ -763,6 +763,9 @@ func extractKeyListWithExpression(ctx mysql.IKeyListWithExpressionContext) []strfor _, key := range ctx.AllKeyPartOrExpression() {if key.KeyPart() != nil {keyText := mysqlparser.NormalizeMySQLIdentifier(key.KeyPart().Identifier())+ if key.KeyPart().FieldLength() != nil || key.KeyPart().Direction() != nil {+ keyText = key.GetParser().GetTokenStream().GetTextFromRuleContext(key.KeyPart())+ }result = append(result, keyText)} else if key.ExprWithParentheses() != nil {keyText := key.GetParser().GetTokenStream().GetTextFromRuleContext(key.ExprWithParentheses())@@ -776,6 +779,9 @@ func extractKeyList(ctx mysql.IKeyListContext) []string {var result []stringfor _, key := range ctx.AllKeyPart() {keyText := mysqlparser.NormalizeMySQLIdentifier(key.Identifier())+ if key.FieldLength() != nil || key.Direction() != nil {+ keyText = key.GetParser().GetTokenStream().GetTextFromRuleContext(key)+ }result = append(result, keyText)}return resultdiff --git a/backend/api/v1/testdata/schema.yaml b/backend/api/v1/testdata/schema.yamlindex b70f9bfbee..d17969ffb6 100644--- a/backend/api/v1/testdata/schema.yaml+++ b/backend/api/v1/testdata/schema.yaml@@ -3,53 +3,66 @@create table t(`a` int NOT NULL COMMENT 'this is comment',+ `b` VARCHAR(20) NOT NULL,KEY `idx` (((`a` + 20))),UNIQUE KEY `idx2` (`a`),+ KEY `idx_length` (`b`(10) DESC),PRIMARY KEY (`a`)) COMMENT 'this is comment with '' escaped';metadata: |-{- "schemas": [+ "schemas": [{- "tables": [+ "tables": [{- "name": "t",- "columns": [+ "name": "t",+ "columns": [{- "name": "a",- "type": "int",- "comment": "this is comment",- "userComment": "this is comment"+ "name": "a",+ "type": "int",+ "comment": "this is comment",+ "userComment": "this is comment"+ },+ {+ "name": "b",+ "type": "VARCHAR(20)"}],- "indexes": [+ "indexes": [{- "name": "idx",- "expressions": [+ "name": "idx",+ "expressions": ["((`a` + 20))"],- "visible": true+ "visible": true},{- "name": "idx2",- "expressions": [+ "name": "idx2",+ "expressions": ["a"],- "unique": true,- "visible": true+ "unique": true,+ "visible": true+ },+ {+ "name": "idx_length",+ "expressions": [+ "`b`(10) DESC"+ ],+ "visible": true},{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["a"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true}],- "comment": "this is comment with ' escaped",- "userComment": "this is comment with ' escaped"+ "comment": "this is comment with ' escaped",+ "userComment": "this is comment with ' escaped"}]}@@ -68,78 +81,78 @@create table t2(b int NOT NULL default NULL, primary key (b));metadata: |-{- "schemas": [+ "schemas": [{- "tables": [+ "tables": [{- "name": "t",- "columns": [+ "name": "t",+ "columns": [{- "name": "c",- "defaultExpression": "AUTO_INCREMENT",- "nullable": true,- "type": "int"+ "name": "c",+ "defaultExpression": "AUTO_INCREMENT",+ "nullable": true,+ "type": "int"},{- "name": "a",- "defaultExpression": "1",- "nullable": true,- "type": "int",- "comment": "abcdefg",- "userComment": "abcdefg"+ "name": "a",+ "defaultExpression": "1",+ "nullable": true,+ "type": "int",+ "comment": "abcdefg",+ "userComment": "abcdefg"},{- "name": "b",- "defaultNull": true,- "nullable": true,- "type": "varchar(20)"+ "name": "b",+ "defaultNull": true,+ "nullable": true,+ "type": "varchar(20)"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["a","b"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true}],- "comment": "this is comment with ' escaped",- "userComment": "this is comment with ' escaped",- "foreignKeys": [+ "comment": "this is comment with ' escaped",+ "userComment": "this is comment with ' escaped",+ "foreignKeys": [{- "name": "fk1",- "columns": [+ "name": "fk1",+ "columns": ["a"],- "referencedTable": "t2",- "referencedColumns": [+ "referencedTable": "t2",+ "referencedColumns": ["b"]}]},{- "name": "t2",- "columns": [+ "name": "t2",+ "columns": [{- "name": "b",- "defaultNull": true,- "type": "int"+ "name": "b",+ "defaultNull": true,+ "type": "int"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["b"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true}]}