Skip to content

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

fix(structurer): align column position for filterDatabaseMetadata and parseToMetadata for MySQL (#10444)

h3n4l4386ff04968f
diff --git a/backend/plugin/schema/mysql/state.go b/backend/plugin/schema/mysql/state.go
index c3518e9af4..6858c3e218 100644
--- a/backend/plugin/schema/mysql/state.go
+++ b/backend/plugin/schema/mysql/state.go
@@ -235,6 +235,10 @@ func (t *tableState) convertToTableMetadata() *storepb.TableMetadata {
for _, column := range columnStates {
columns = append(columns, column.convertToColumnMetadata())
}
+ // Backfill all the column positions.
+ for i, column := range columns {
+ column.Position = int32(i + 1)
+ }
indexStates := []*indexState{}
for _, index := range t.indexes {
diff --git a/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml b/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml
index 93ff6de6bf..47fea3045e 100644
--- a/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml
+++ b/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml
@@ -15,97 +15,101 @@
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci 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",
+ "position": 1,
+ "type": "int",
+ "comment": "this is comment"
},
{
- "name": "b",
- "type": "VARCHAR(20)"
+ "name": "b",
+ "position": 2,
+ "type": "VARCHAR(20)"
},
{
- "name": "c",
- "type": "int"
+ "name": "c",
+ "position": 3,
+ "type": "int"
},
{
- "name": "d",
- "nullable": true,
- "type": "text"
+ "name": "d",
+ "position": 4,
+ "nullable": true,
+ "type": "text"
}
],
- "indexes": [
+ "indexes": [
{
- "name": "PRIMARY",
- "expressions": [
+ "name": "PRIMARY",
+ "expressions": [
"a"
],
- "unique": true,
- "primary": true,
- "visible": true
+ "unique": true,
+ "primary": true,
+ "visible": true
},
{
- "name": "t_c_uniq_idx",
- "expressions": [
+ "name": "t_c_uniq_idx",
+ "expressions": [
"c"
],
- "type": "BTREE",
- "unique": true,
- "visible": true
+ "type": "BTREE",
+ "unique": true,
+ "visible": true
},
{
- "name": "t_c_plus_5_uniq_idx",
- "expressions": [
+ "name": "t_c_plus_5_uniq_idx",
+ "expressions": [
"((`c` + 5))"
],
- "type": "BTREE",
- "unique": true,
- "visible": true
+ "type": "BTREE",
+ "unique": true,
+ "visible": true
},
{
- "name": "t_c_plus_5_t_c_plus_3_uniq_idx",
- "expressions": [
+ "name": "t_c_plus_5_t_c_plus_3_uniq_idx",
+ "expressions": [
"((`c` + 5))",
"((`c` + 3))"
],
- "type": "BTREE",
- "unique": true,
- "visible": true
+ "type": "BTREE",
+ "unique": true,
+ "visible": true
},
{
- "name": "idx_c",
- "expressions": [
+ "name": "idx_c",
+ "expressions": [
"c"
],
- "type": "BTREE",
- "visible": true
+ "type": "BTREE",
+ "visible": true
},
{
- "name": "idx_d",
- "expressions": [
+ "name": "idx_d",
+ "expressions": [
"d"
],
- "type": "BTREE",
- "visible": true
+ "type": "BTREE",
+ "visible": true
},
{
- "name": "t_d_fulltext_idx",
- "expressions": [
+ "name": "t_d_fulltext_idx",
+ "expressions": [
"d"
],
- "type": "FULLTEXT",
- "visible": true
+ "type": "FULLTEXT",
+ "visible": true
}
],
- "engine": "InnoDB",
- "collation": "utf8mb4_0900_ai_ci",
- "comment": "this is comment with ' escaped"
+ "engine": "InnoDB",
+ "collation": "utf8mb4_0900_ai_ci",
+ "comment": "this is comment with ' escaped"
}
]
}
@@ -123,76 +127,80 @@
create table t2(b int NOT NULL default NULL, primary key (b));
metadata: |-
{
- "schemas": [
+ "schemas": [
{
- "tables": [
+ "tables": [
{
- "name": "t",
- "columns": [
- {
- "name": "c",
- "defaultExpression": "AUTO_INCREMENT",
- "nullable": true,
- "type": "int"
+ "name": "t",
+ "columns": [
+ {
+ "name": "c",
+ "position": 1,
+ "defaultExpression": "AUTO_INCREMENT",
+ "nullable": true,
+ "type": "int"
},
{
- "name": "a",
- "defaultExpression": "1",
- "nullable": true,
- "type": "int",
- "comment": "abcdefg"
+ "name": "a",
+ "position": 2,
+ "defaultExpression": "1",
+ "nullable": true,
+ "type": "int",
+ "comment": "abcdefg"
},
{
- "name": "b",
- "defaultNull": true,
- "nullable": true,
- "type": "varchar(20)"
+ "name": "b",
+ "position": 3,
+ "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",
+ "position": 1,
+ "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
}
]
}