Skip to content

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

chore: bump omni to 6ee3f142 and adapt to its changes (#21703)

rebelice61db34cc1782
diff --git a/backend/plugin/advisor/mysql/rule_index_key_number_limit.go b/backend/plugin/advisor/mysql/rule_index_key_number_limit.go
index b752e69a16..115bbb045a 100644
--- a/backend/plugin/advisor/mysql/rule_index_key_number_limit.go
+++ b/backend/plugin/advisor/mysql/rule_index_key_number_limit.go
@@ -113,7 +113,7 @@ func (r *indexKeyNumberLimitOmniRule) handleConstraint(tableName string, constra
return
}
- indexName := constraint.Name
+ indexName := omniConstraintName(constraint)
if indexName == "" && constraint.Type == ast.ConstrPrimaryKey {
indexName = extractPKNameFromText(r.StmtText)
}
diff --git a/backend/plugin/advisor/mysql/rule_index_no_duplicate_column.go b/backend/plugin/advisor/mysql/rule_index_no_duplicate_column.go
index be771c6ef2..bf4b2500e7 100644
--- a/backend/plugin/advisor/mysql/rule_index_no_duplicate_column.go
+++ b/backend/plugin/advisor/mysql/rule_index_no_duplicate_column.go
@@ -146,7 +146,7 @@ func (r *indexNoDuplicateColumnOmniRule) handleConstraint(tableName string, cons
return
}
- indexName := constraint.Name
+ indexName := omniConstraintName(constraint)
// Workaround: omni parser doesn't capture PRIMARY KEY constraint names.
// Extract from statement text as a fallback.
if indexName == "" && constraint.Type == ast.ConstrPrimaryKey {
diff --git a/backend/plugin/advisor/mysql/rule_naming_foreign_key_convention.go b/backend/plugin/advisor/mysql/rule_naming_foreign_key_convention.go
index 76042362e6..b42b38abff 100644
--- a/backend/plugin/advisor/mysql/rule_naming_foreign_key_convention.go
+++ b/backend/plugin/advisor/mysql/rule_naming_foreign_key_convention.go
@@ -171,7 +171,7 @@ func (*namingFKOmniRule) handleConstraint(tableName string, constraint *ast.Cons
return nil
}
- indexName := constraint.Name
+ indexName := omniConstraintName(constraint)
referencingColumnList := constraint.Columns
referencedTable := ""
diff --git a/backend/plugin/advisor/mysql/rule_naming_identifier_no_keyword.go b/backend/plugin/advisor/mysql/rule_naming_identifier_no_keyword.go
index 2f0d54988d..a9a021b43d 100644
--- a/backend/plugin/advisor/mysql/rule_naming_identifier_no_keyword.go
+++ b/backend/plugin/advisor/mysql/rule_naming_identifier_no_keyword.go
@@ -76,9 +76,7 @@ func (r *namingIdentifierNoKeywordOmniRule) checkCreateTable(n *ast.CreateTableS
if constraint == nil {
continue
}
- if constraint.Name != "" {
- r.checkIdentifierAtLine(constraint.Name, r.LocToLine(constraint.Loc))
- }
+ r.checkConstraintNames(constraint, r.LocToLine(constraint.Loc))
}
}
@@ -105,8 +103,8 @@ func (r *namingIdentifierNoKeywordOmniRule) checkAlterTable(n *ast.AlterTableStm
r.checkIdentifierAtLine(cmd.Column.Name, r.LocToLine(n.Loc))
}
case ast.ATAddConstraint, ast.ATAddIndex:
- if cmd.Constraint != nil && cmd.Constraint.Name != "" {
- r.checkIdentifierAtLine(cmd.Constraint.Name, r.LocToLine(n.Loc))
+ if cmd.Constraint != nil {
+ r.checkConstraintNames(cmd.Constraint, r.LocToLine(n.Loc))
}
case ast.ATRenameIndex:
if cmd.NewName != "" {
@@ -123,6 +121,16 @@ func (r *namingIdentifierNoKeywordOmniRule) checkCreateIndex(n *ast.CreateIndexS
}
}
+// checkConstraintNames checks the CONSTRAINT symbol and, for FOREIGN KEY, the
+// name written after FOREIGN KEY.
+func (r *namingIdentifierNoKeywordOmniRule) checkConstraintNames(c *ast.Constraint, lineNumber int32) {
+ for _, name := range []string{c.Name, c.IndexName} {
+ if name != "" {
+ r.checkIdentifierAtLine(name, lineNumber)
+ }
+ }
+}
+
func (r *namingIdentifierNoKeywordOmniRule) checkIdentifierAtLine(identifier string, lineNumber int32) {
// Strip backticks if present.
identifier = strings.Trim(identifier, "`")
diff --git a/backend/plugin/advisor/mysql/test/naming_identifier_no_keyword.yaml b/backend/plugin/advisor/mysql/test/naming_identifier_no_keyword.yaml
index 70577e883f..c3b0abe618 100644
--- a/backend/plugin/advisor/mysql/test/naming_identifier_no_keyword.yaml
+++ b/backend/plugin/advisor/mysql/test/naming_identifier_no_keyword.yaml
@@ -63,3 +63,23 @@
endposition: null
- statement: CREATE TABLE master_server_id(id int);
- statement: CREATE TABLE master_compression_algorithm(id int);
+- statement: CREATE TABLE t(a int, CONSTRAINT fk_t_a FOREIGN KEY `execute` (a) REFERENCES p (id))
+ want:
+ - status: 2
+ code: 308
+ title: NAMING_IDENTIFIER_NO_KEYWORD
+ content: Identifier "execute" is a keyword and should be avoided
+ startposition:
+ line: 1
+ column: 0
+ endposition: null
+- statement: ALTER TABLE t ADD FOREIGN KEY `execute` (a) REFERENCES p (id)
+ want:
+ - status: 2
+ code: 308
+ title: NAMING_IDENTIFIER_NO_KEYWORD
+ content: Identifier "execute" is a keyword and should be avoided
+ startposition:
+ line: 1
+ column: 0
+ endposition: null
diff --git a/backend/plugin/advisor/mysql/test/naming_index_fk.yaml b/backend/plugin/advisor/mysql/test/naming_index_fk.yaml
index e561599485..678c433581 100644
--- a/backend/plugin/advisor/mysql/test/naming_index_fk.yaml
+++ b/backend/plugin/advisor/mysql/test/naming_index_fk.yaml
@@ -64,3 +64,14 @@
line: 4
column: 0
endposition: null
+- statement: CREATE TABLE book(id INT, author_id INT, CONSTRAINT fk_book_author_id_author_id FOREIGN KEY fk1 (author_id) REFERENCES author (id));
+- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY fk_tech_book_author_id_author_id (author_id) REFERENCES author (id);
+ want:
+ - status: 2
+ code: 305
+ title: NAMING_INDEX_FK
+ content: Foreign key in table `tech_book` mismatches the naming convention, expect "^$|^fk_tech_book_author_id_author_id$" but found `fk_author_id`
+ startposition:
+ line: 1
+ column: 0
+ endposition: null
diff --git a/backend/plugin/advisor/mysql/utils.go b/backend/plugin/advisor/mysql/utils.go
index 5a824de8ec..cc320bcb7c 100644
--- a/backend/plugin/advisor/mysql/utils.go
+++ b/backend/plugin/advisor/mysql/utils.go
@@ -190,6 +190,15 @@ func omniConstraintsByType(constraints []*ast.Constraint, typ ast.ConstraintType
return result
}
+// omniConstraintName returns the CONSTRAINT symbol, else the name written after
+// FOREIGN KEY, which omni keeps in IndexName.
+func omniConstraintName(c *ast.Constraint) string {
+ if c.Name != "" {
+ return c.Name
+ }
+ return c.IndexName
+}
+
// omniDataTypeNameCompact returns a compact, lowercase type name string.
func omniDataTypeNameCompact(dt *ast.DataType) string {
if dt == nil {
diff --git a/backend/plugin/advisor/tidb/advisor_naming_foreign_key_convention.go b/backend/plugin/advisor/tidb/advisor_naming_foreign_key_convention.go
index 5f5089b561..2311cc34e9 100644
--- a/backend/plugin/advisor/tidb/advisor_naming_foreign_key_convention.go
+++ b/backend/plugin/advisor/tidb/advisor_naming_foreign_key_convention.go
@@ -102,7 +102,7 @@ func buildFKMetaData(tableName string, constraint *ast.Constraint, line int) *in
advisor.ReferencedColumnNameTemplateToken: strings.Join(referencedColumnList, "_"),
}
return &indexMetaData{
- indexName: constraint.Name,
+ indexName: omniConstraintName(constraint),
tableName: tableName,
metaData: metaData,
line: line,
diff --git a/backend/plugin/advisor/tidb/test/naming_index_fk.yaml b/backend/plugin/advisor/tidb/test/naming_index_fk.yaml
index 1728a2f6c8..a0625f5384 100644
--- a/backend/plugin/advisor/tidb/test/naming_index_fk.yaml
+++ b/backend/plugin/advisor/tidb/test/naming_index_fk.yaml
@@ -45,3 +45,16 @@
line: 1
column: 0
endposition: null
+- statement: CREATE TABLE book(id INT, author_id INT, CONSTRAINT fk_book_author_id_author_id FOREIGN KEY fk1 (author_id) REFERENCES author (id))
+ changeType: 1
+- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY fk_tech_book_author_id_author_id (author_id) REFERENCES author (id)
+ changeType: 1
+ want:
+ - status: 2
+ code: 305
+ title: NAMING_INDEX_FK
+ content: Foreign key in table `tech_book` mismatches the naming convention, expect "^$|^fk_tech_book_author_id_author_id$" but found `fk_author_id`
+ startposition:
+ line: 1
+ column: 0
+ endposition: null
diff --git a/backend/plugin/advisor/tidb/test/naming_index_uk.yaml b/backend/plugin/advisor/tidb/test/naming_index_uk.yaml
index 13a7900886..4f7ca3b667 100644
--- a/backend/plugin/advisor/tidb/test/naming_index_uk.yaml
+++ b/backend/plugin/advisor/tidb/test/naming_index_uk.yaml
@@ -95,3 +95,5 @@
line: 1
column: 0
endposition: null
+- statement: ALTER TABLE tech_book ADD CONSTRAINT uk_tech_book_id_name UNIQUE KEY uk1 (id, name)
+ changeType: 1
diff --git a/backend/plugin/advisor/tidb/utils.go b/backend/plugin/advisor/tidb/utils.go
index 11151274d3..a07b5b8ca5 100644
--- a/backend/plugin/advisor/tidb/utils.go
+++ b/backend/plugin/advisor/tidb/utils.go
@@ -516,8 +516,8 @@ func omniConstraintAdviceName(c *omniast.Constraint) string {
if c == nil {
return ""
}
- if c.Name != "" {
- return c.Name
+ if name := omniConstraintName(c); name != "" {
+ return name
}
if c.Type == omniast.ConstrPrimaryKey {
return "PRIMARY"
@@ -525,6 +525,15 @@ func omniConstraintAdviceName(c *omniast.Constraint) string {
return ""
}
+// omniConstraintName returns the CONSTRAINT symbol, else the name written after
+// FOREIGN KEY, which omni keeps in IndexName.
+func omniConstraintName(c *omniast.Constraint) string {
+ if c.Name != "" {
+ return c.Name
+ }
+ return c.IndexName
+}
+
// omniDataTypeNameCompact returns a compact, lowercase type-name string
// for use in advice content + allowlist comparisons. Mirrors the mysql
// helper of the same name (mysql/utils.go). Length/scale info is
diff --git a/go.mod b/go.mod
index 4f5488bf19..8c8adee48b 100644
--- a/go.mod
+++ b/go.mod
@@ -36,7 +36,7 @@ require (
github.com/bmatcuk/doublestar/v4 v4.10.0
github.com/bytebase/gomongo v0.0.0-20260730033313-67ba6e249735
github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0
- github.com/bytebase/omni v0.0.0-20261028062602-59f0194f8502
+ github.com/bytebase/omni v0.0.0-20261029055909-6ee3f1424d2b
github.com/caarlos0/env/v11 v11.4.1
github.com/cenkalti/backoff/v7 v7.0.0
github.com/cockroachdb/cockroach-go/v2 v2.4.3
diff --git a/go.sum b/go.sum
index dc847b0911..55b314b4e4 100644
--- a/go.sum
+++ b/go.sum
@@ -252,8 +252,8 @@ github.com/bytebase/gomongo v0.0.0-20260730033313-67ba6e249735 h1:v8y6mXeHmYVsdM
github.com/bytebase/gomongo v0.0.0-20260730033313-67ba6e249735/go.mod h1:vTHjcvfn8Pmf65WjnV1ytTCYyC7xNhFjrniv4YWvtA8=
github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0 h1:bJ8NSf2K+pccl5m/wuu97fiYjDwpJH6IzURAq/3XA2U=
github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0/go.mod h1:BEWMfiZtqshdmulKJcIsWb45MUaEvDO4CROcgi8dfFg=
-github.com/bytebase/omni v0.0.0-20261028062602-59f0194f8502 h1:sVl3/7PRraXNpT3i0vfDHkwfCcosLEwvakDIg2OZZyM=
-github.com/bytebase/omni v0.0.0-20261028062602-59f0194f8502/go.mod h1:9XZE1hqtvr09Oc+DdLu1/yCb8MDcoy/EPdA4AONDHlE=
+github.com/bytebase/omni v0.0.0-20261029055909-6ee3f1424d2b h1:t2hCLnkWNWR5ycV/qygvNGiCpvkUcoggxwtXc4ytzo4=
+github.com/bytebase/omni v0.0.0-20261029055909-6ee3f1424d2b/go.mod h1:9XZE1hqtvr09Oc+DdLu1/yCb8MDcoy/EPdA4AONDHlE=
github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767 h1:YuR5G3LcxpO5ScSTA+Kdirxg9RW4TRc/v1t7N2Hfmbw=
github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
github.com/bytebase/pkcs8 v0.0.0-20240612095628-fcd0a7484c94 h1:6PNsuNmSqCuR8Z616uQLzDIvujWCFsKzeVc3ECmVubk=