Skip to content

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

fix(sync): sync tidb index check expression name first (#10556)

h3n4lc5f465812b4b
diff --git a/backend/plugin/db/tidb/sync.go b/backend/plugin/db/tidb/sync.go
index 29fcaed336..224d9b25c1 100644
--- a/backend/plugin/db/tidb/sync.go
+++ b/backend/plugin/db/tidb/sync.go
@@ -147,7 +147,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchema
TABLE_NAME,
INDEX_NAME,
COLUMN_NAME,
- '',
+ EXPRESSION,
SEQ_IN_INDEX,
INDEX_TYPE,
CASE NON_UNIQUE WHEN 0 THEN 1 ELSE 0 END AS IS_UNIQUE,
@@ -180,12 +180,12 @@ func (driver *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchema
); err != nil {
return nil, err
}
- if columnName.Valid {
- expression = columnName.String
- } else if expressionName.Valid {
- // It's a bit late or not necessary to differentiate the column name or expression.
- // We add parentheses around expression.
+ // TiDB use string "NULL" instead of NULL, so we check expression first which is
+ // different between TiDB and MySQL.
+ if expressionName.Valid {
expression = fmt.Sprintf("(%s)", expressionName.String)
+ } else if columnName.Valid {
+ expression = columnName.String
}
key := db.TableKey{Schema: "", Table: tableName}