Skip to content

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

fix(structurer): remove field length and direction in index expressions (#10181)

h3n4l6e10523aa738
diff --git a/backend/plugin/schema/mysql/structurer.go b/backend/plugin/schema/mysql/structurer.go
index 4f633cfa88..88872b2c3b 100644
--- a/backend/plugin/schema/mysql/structurer.go
+++ b/backend/plugin/schema/mysql/structurer.go
@@ -798,9 +798,6 @@ func extractKeyListWithExpression(ctx mysql.IKeyListWithExpressionContext) []str
for _, 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())
diff --git a/backend/plugin/schema/mysql/testdata/get_design_schema.yaml b/backend/plugin/schema/mysql/testdata/get_design_schema.yaml
index 93e64a9758..5e2ff98479 100644
--- a/backend/plugin/schema/mysql/testdata/get_design_schema.yaml
+++ b/backend/plugin/schema/mysql/testdata/get_design_schema.yaml
@@ -119,78 +119,84 @@
},
{
"name": "t5",
- "engine": "InnoDB",
"columns": [
{
- "name": "id",
+ "name": "a",
"type": "int",
- "position": 1
+ "comment": "this is comment"
},
{
- "name": "a",
- "type": "int",
- "nullable": true,
- "position": 2,
- "defaultNull": true
+ "name": "b",
+ "type": "VARCHAR(20)"
+ },
+ {
+ "name": "c",
+ "type": "int"
},
{
- "name": "title",
- "type": "text",
+ "name": "d",
"nullable": true,
- "position": 3,
- "collation": "utf8mb4_general_ci",
- "defaultNull": true,
- "characterSet": "utf8mb4"
+ "type": "text"
}
],
"indexes": [
{
"name": "PRIMARY",
- "type": "BTREE",
+ "expressions": [
+ "a"
+ ],
"unique": true,
"primary": true,
- "visible": true,
- "expressions": [
- "id"
- ]
+ "visible": true
},
{
- "name": "t5_a_plus_5_t_a_plus_3_uniq_idx",
- "type": "BTREE",
+ "name": "t_c_uniq_idx",
+ "expressions": [
+ "c"
+ ],
"unique": true,
- "visible": true,
+ "visible": true
+ },
+ {
+ "name": "t_c_plus_5_uniq_idx",
"expressions": [
- "((`a` + 5))",
- "((`a` + 3))"
- ]
+ "((`c` + 5))"
+ ],
+ "unique": true,
+ "visible": true
},
{
- "name": "t5_a_plus_5_uniq_idx",
- "type": "BTREE",
+ "name": "t_c_plus_5_t_c_plus_3_uniq_idx",
+ "expressions": [
+ "((`c` + 5))",
+ "((`c` + 3))"
+ ],
"unique": true,
- "visible": true,
+ "visible": true
+ },
+ {
+ "name": "idx_c",
"expressions": [
- "((`a` + 5))"
- ]
+ "c"
+ ],
+ "visible": true
},
{
- "name": "t5_a_uniq_idx",
- "type": "BTREE",
- "unique": true,
- "visible": true,
+ "name": "idx_d",
"expressions": [
- "a"
- ]
+ "d"
+ ],
+ "visible": true
},
{
- "name": "t5_title_fulltext_idx",
- "type": "FULLTEXT",
- "visible": true,
+ "name": "t_d_fulltext_idx",
"expressions": [
- "title"
- ]
+ "d"
+ ],
+ "visible": true
}
- ]
+ ],
+ "comment": "this is comment with ' escaped"
}
]
}
@@ -216,15 +222,18 @@
CONSTRAINT `fk1` FOREIGN KEY (`b`) REFERENCES `t4` (`b`)
);
CREATE TABLE `t5` (
- `id` int NOT NULL,
- `a` int NULL DEFAULT NULL,
- `title` text NULL DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `t5_a_plus_5_t_a_plus_3_uniq_idx` (((`a` + 5)),((`a` + 3))) USING BTREE,
- UNIQUE KEY `t5_a_plus_5_uniq_idx` (((`a` + 5))) USING BTREE,
- UNIQUE KEY `t5_a_uniq_idx` (`a`) USING BTREE,
- FULLTEXT KEY `t5_title_fulltext_idx` (`title`)
- );
+ `a` int NOT NULL COMMENT 'this is comment',
+ `b` VARCHAR(20) NOT NULL,
+ `c` int NOT NULL,
+ `d` text NULL,
+ PRIMARY KEY (`a`),
+ UNIQUE KEY `t_c_uniq_idx` (`c`),
+ UNIQUE KEY `t_c_plus_5_uniq_idx` (((`c` + 5))),
+ UNIQUE KEY `t_c_plus_5_t_c_plus_3_uniq_idx` (((`c` + 5)),((`c` + 3))),
+ KEY `idx_c` (`c`),
+ KEY `idx_d` (`d`),
+ KEY `t_d_fulltext_idx` (`d`)
+ ) COMMENT 'this is comment with '' escaped';
- baseline: |-
CREATE TABLE `t` (
diff --git a/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml b/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml
index 4b1eb28d2f..92b27ea9a7 100644
--- a/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml
+++ b/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml
@@ -3,63 +3,101 @@
(
`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`)
+ `c` int NOT NULL,
+ `d` text NULL,
+ PRIMARY KEY (`a`),
+ UNIQUE KEY `t_c_uniq_idx` (`c` DESC),
+ UNIQUE KEY `t_c_plus_5_uniq_idx` (((`c` + 5)) DESC),
+ UNIQUE KEY `t_c_plus_5_t_c_plus_3_uniq_idx` (((`c` + 5)) DESC,((`c` + 3))),
+ KEY `idx_c` (`c`),
+ KEY `idx_d` (`d`(10)),
+ FULLTEXT KEY `t_d_fulltext_idx` (`d`)
) 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"
+ "name": "a",
+ "type": "int",
+ "comment": "this is comment"
},
{
- "name": "b",
- "type": "VARCHAR(20)"
+ "name": "b",
+ "type": "VARCHAR(20)"
+ },
+ {
+ "name": "c",
+ "type": "int"
+ },
+ {
+ "name": "d",
+ "nullable": true,
+ "type": "text"
}
],
- "indexes": [
+ "indexes": [
{
- "name": "idx",
- "expressions": [
- "((`a` + 20))"
+ "name": "PRIMARY",
+ "expressions": [
+ "a"
],
- "visible": true
+ "unique": true,
+ "primary": true,
+ "visible": true
},
{
- "name": "idx2",
- "expressions": [
- "a"
+ "name": "t_c_uniq_idx",
+ "expressions": [
+ "c"
],
- "unique": true,
- "visible": true
+ "unique": true,
+ "visible": true
},
{
- "name": "idx_length",
- "expressions": [
- "`b`(10) DESC"
+ "name": "t_c_plus_5_uniq_idx",
+ "expressions": [
+ "((`c` + 5))"
],
- "visible": true
+ "unique": true,
+ "visible": true
},
{
- "name": "PRIMARY",
- "expressions": [
- "a"
+ "name": "t_c_plus_5_t_c_plus_3_uniq_idx",
+ "expressions": [
+ "((`c` + 5))",
+ "((`c` + 3))"
+ ],
+ "unique": true,
+ "visible": true
+ },
+ {
+ "name": "idx_c",
+ "expressions": [
+ "c"
+ ],
+ "visible": true
+ },
+ {
+ "name": "idx_d",
+ "expressions": [
+ "d"
+ ],
+ "visible": true
+ },
+ {
+ "name": "t_d_fulltext_idx",
+ "expressions": [
+ "d"
],
- "unique": true,
- "primary": true,
- "visible": true
+ "visible": true
}
],
- "comment": "this is comment with ' escaped"
+ "comment": "this is comment with ' escaped"
}
]
}
@@ -77,76 +115,76 @@
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"
+ "name": "a",
+ "defaultExpression": "1",
+ "nullable": true,
+ "type": "int",
+ "comment": "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",
- "foreignKeys": [
+ "comment": "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
}
]
}