Skip to content

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

chore(mysql): use omni keyword API in advisor (#20214)

rebelicefe50dc9e8157
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 8470816122..70577e883f 100644
--- a/backend/plugin/advisor/mysql/test/naming_identifier_no_keyword.yaml
+++ b/backend/plugin/advisor/mysql/test/naming_identifier_no_keyword.yaml
@@ -61,3 +61,5 @@
line: 1
column: 0
endposition: null
+- statement: CREATE TABLE master_server_id(id int);
+- statement: CREATE TABLE master_compression_algorithm(id int);
diff --git a/backend/plugin/advisor/mysql/utils.go b/backend/plugin/advisor/mysql/utils.go
index d301ad008a..9e0eec731a 100644
--- a/backend/plugin/advisor/mysql/utils.go
+++ b/backend/plugin/advisor/mysql/utils.go
@@ -6,7 +6,7 @@ import (
"slices"
"strings"
- "github.com/bytebase/parser/mysql"
+ mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
)
type columnSet map[string]bool
@@ -68,12 +68,6 @@ func (t tableColumnTypes) delete(tableName string, columnName string) {
}
// isKeyword checks if the keyword is a MySQL keyword.
-// TODO: We should check with map instead of linear search.
func isKeyword(suspect string) bool {
- for _, item := range mysql.Keywords80 {
- if strings.EqualFold(suspect, item.Keyword) {
- return true
- }
- }
- return false
+ return mysqlparser.IsKeyword(suspect)
}
diff --git a/backend/plugin/advisor/tidb/utils.go b/backend/plugin/advisor/tidb/utils.go
index 34122186d5..d3904e39c2 100644
--- a/backend/plugin/advisor/tidb/utils.go
+++ b/backend/plugin/advisor/tidb/utils.go
@@ -12,7 +12,6 @@ import (
"unicode"
"github.com/pingcap/tidb/pkg/parser/ast"
- "github.com/pingcap/tidb/pkg/parser/format"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/parser/types"
"github.com/pkg/errors"
@@ -88,15 +87,6 @@ func (t tableNewColumn) delete(tableName, columnName string) {
delete(t[tableName], columnName)
}
-func restoreNode(node ast.Node, flag format.RestoreFlags) (string, error) {
- var buffer strings.Builder
- ctx := format.NewRestoreCtx(flag, &buffer)
- if err := node.Restore(ctx); err != nil {
- return "", err
- }
- return buffer.String(), nil
-}
-
func needDefault(column *ast.ColumnDef) bool {
for _, option := range column.Options {
switch option.Tp {
diff --git a/backend/plugin/parser/mysql/omni.go b/backend/plugin/parser/mysql/omni.go
index f5535d83b1..d8c55ddcf9 100644
--- a/backend/plugin/parser/mysql/omni.go
+++ b/backend/plugin/parser/mysql/omni.go
@@ -60,6 +60,11 @@ func ParseMySQLOmni(sql string) (*ast.List, error) {
return mysqlparser.Parse(sql)
}
+// IsKeyword reports whether s is a registered MySQL keyword.
+func IsKeyword(s string) bool {
+ return mysqlparser.IsKeyword(s)
+}
+
// GetOmniNode extracts the omni AST node from a base.AST interface.
// Returns the node and true if it is an OmniAST, nil and false otherwise.
func GetOmniNode(a base.AST) (ast.Node, bool) {