Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: remove Simple Advisor Task Checker and parse once for sql review (#6846)
rebelicea474f69b1cd4
diff --git a/backend/legacyapi/task_check_run.go b/backend/legacyapi/task_check_run.goindex 3a52aaf234..2305ed5012 100644--- a/backend/legacyapi/task_check_run.go+++ b/backend/legacyapi/task_check_run.go@@ -59,8 +59,6 @@ type TaskCheckType stringconst (// TaskCheckDatabaseStatementFakeAdvise is the task check type for fake advise.TaskCheckDatabaseStatementFakeAdvise TaskCheckType = "bb.task-check.database.statement.fake-advise"- // TaskCheckDatabaseStatementSyntax is the task check type for statement syntax.- TaskCheckDatabaseStatementSyntax TaskCheckType = "bb.task-check.database.statement.syntax"// TaskCheckDatabaseStatementCompatibility is the task check type for statement compatibility.TaskCheckDatabaseStatementCompatibility TaskCheckType = "bb.task-check.database.statement.compatibility"// TaskCheckDatabaseStatementAdvise is the task check type for schema system review policy.@@ -130,20 +128,6 @@ type TaskCheckRun struct {Payload string `jsonapi:"attr,payload"`}-// IsSyntaxCheckSupported checks the engine type if syntax check supports it.-func IsSyntaxCheckSupported(dbType db.Type) bool {- if dbType == db.Postgres || dbType == db.MySQL || dbType == db.TiDB || dbType == db.MariaDB || dbType == db.Oracle || dbType == db.OceanBase || dbType == db.Snowflake {- advisorDB, err := advisorDB.ConvertToAdvisorDBType(string(dbType))- if err != nil {- return false- }-- return advisor.IsSyntaxCheckSupported(advisorDB)- }-- return false-}-// IsSQLReviewSupported checks the engine type if SQL review supports it.func IsSQLReviewSupported(dbType db.Type) bool {if dbType == db.Postgres || dbType == db.MySQL || dbType == db.TiDB || dbType == db.MariaDB || dbType == db.Oracle || dbType == db.OceanBase || dbType == db.Snowflake {diff --git a/backend/plugin/advisor/advisor.go b/backend/plugin/advisor/advisor.goindex 6f470acde6..8d3bcd7748 100644--- a/backend/plugin/advisor/advisor.go+++ b/backend/plugin/advisor/advisor.go@@ -481,6 +481,7 @@ type Context struct {SyntaxMode SyntaxMode// SQL review rule special fields.+ AST anyRule *SQLReviewRuleCatalog *catalog.FinderDriver *sql.DBdiff --git a/backend/plugin/advisor/generator/mysql.template b/backend/plugin/advisor/generator/mysql.templateindex bc7d2025eb..ca076797b1 100644--- a/backend/plugin/advisor/generator/mysql.template+++ b/backend/plugin/advisor/generator/mysql.template@@ -25,10 +25,10 @@ type %AdvisorName struct {}// Check checks for %AdvisorComment-func (*%AdvisorName) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*%AdvisorName) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/generator/oracle.template b/backend/plugin/advisor/generator/oracle.templateindex e227b7ae39..d6aa46f52c 100644--- a/backend/plugin/advisor/generator/oracle.template+++ b/backend/plugin/advisor/generator/oracle.template@@ -22,10 +22,10 @@ type %AdvisorName struct {}// Check checks for %AdvisorComment-func (*%AdvisorName) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*%AdvisorName) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/generator/postgresql.template b/backend/plugin/advisor/generator/postgresql.templateindex f991608528..bed34ce21a 100644--- a/backend/plugin/advisor/generator/postgresql.template+++ b/backend/plugin/advisor/generator/postgresql.template@@ -22,7 +22,7 @@ type %AdvisorName struct {}// Check checks for %AdvisorComment-func (*%AdvisorName) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {+func (*%AdvisorName) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {stmtList, errAdvice := parseStatement(statement)if errAdvice != nil {return errAdvice, nildiff --git a/backend/plugin/advisor/generator/snowflake.template b/backend/plugin/advisor/generator/snowflake.templateindex 77302ba7b9..4f121d132e 100644--- a/backend/plugin/advisor/generator/snowflake.template+++ b/backend/plugin/advisor/generator/snowflake.template@@ -22,10 +22,10 @@ type %AdvisorName struct {}// Check checks for %AdvisorComment-func (*%AdvisorName) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*%AdvisorName) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_charset_allowlist.go b/backend/plugin/advisor/mysql/advisor_charset_allowlist.goindex 7cc55445e8..46dd087277 100644--- a/backend/plugin/advisor/mysql/advisor_charset_allowlist.go+++ b/backend/plugin/advisor/mysql/advisor_charset_allowlist.go@@ -7,6 +7,7 @@ import ("strings""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -29,12 +30,11 @@ type CharsetAllowlistAdvisor struct {}// Check checks for charset allowlist.-func (*CharsetAllowlistAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*CharsetAllowlistAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}-level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)if err != nil {return nil, errdiff --git a/backend/plugin/advisor/mysql/advisor_collation_allowlist.go b/backend/plugin/advisor/mysql/advisor_collation_allowlist.goindex d402a7d697..664b065013 100644--- a/backend/plugin/advisor/mysql/advisor_collation_allowlist.go+++ b/backend/plugin/advisor/mysql/advisor_collation_allowlist.go@@ -7,6 +7,7 @@ import ("strings""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -29,10 +30,10 @@ type CollationAllowlistAdvisor struct {}// Check checks for collation allowlist.-func (*CollationAllowlistAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*CollationAllowlistAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_colum_require_default.go b/backend/plugin/advisor/mysql/advisor_colum_require_default.goindex 54a62f8a55..ff8b1b66d4 100644--- a/backend/plugin/advisor/mysql/advisor_colum_require_default.go+++ b/backend/plugin/advisor/mysql/advisor_colum_require_default.go@@ -8,6 +8,7 @@ import ("github.com/pingcap/tidb/parser/ast""github.com/pingcap/tidb/parser/mysql""github.com/pingcap/tidb/parser/types"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -30,10 +31,10 @@ type ColumRequireDefaultAdvisor struct {}// Check checks for column default requirement.-func (*ColumRequireDefaultAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumRequireDefaultAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go b/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.goindex b7debba319..b9da51c0a8 100644--- a/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go+++ b/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type ColumnAutoIncrementInitialValueAdvisor struct {}// Check checks for auto-increment column initial value.-func (*ColumnAutoIncrementInitialValueAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnAutoIncrementInitialValueAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.goindex 74bebb74c6..80f9b65e4f 100644--- a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go+++ b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go@@ -8,6 +8,7 @@ import ("github.com/pingcap/tidb/parser/ast""github.com/pingcap/tidb/parser/mysql""github.com/pingcap/tidb/parser/types"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -30,10 +31,10 @@ type ColumnAutoIncrementMustIntegerAdvisor struct {}// Check checks for auto-increment column type.-func (*ColumnAutoIncrementMustIntegerAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnAutoIncrementMustIntegerAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.goindex f8ee02164d..0e45f870ae 100644--- a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go+++ b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go@@ -7,6 +7,7 @@ import ("github.com/pingcap/tidb/parser/ast""github.com/pingcap/tidb/parser/mysql"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -29,10 +30,10 @@ type ColumnAutoIncrementMustUnsignedAdvisor struct {}// Check checks for unsigned auto-increment column.-func (*ColumnAutoIncrementMustUnsignedAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnAutoIncrementMustUnsignedAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_comment_convention.go b/backend/plugin/advisor/mysql/advisor_column_comment_convention.goindex a7e0c08dc5..f77002df69 100644--- a/backend/plugin/advisor/mysql/advisor_column_comment_convention.go+++ b/backend/plugin/advisor/mysql/advisor_column_comment_convention.go@@ -7,6 +7,7 @@ import ("github.com/pingcap/tidb/parser/ast""github.com/pingcap/tidb/parser/format"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -29,10 +30,10 @@ type ColumnCommentConventionAdvisor struct {}// Check checks for column comment convention.-func (*ColumnCommentConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnCommentConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go b/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.goindex 9f99244574..e244805327 100644--- a/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go+++ b/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go@@ -9,6 +9,7 @@ import ("github.com/pingcap/tidb/parser/ast""github.com/pingcap/tidb/parser/mysql"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -36,10 +37,10 @@ type ColumnCurrentTimeCountLimitAdvisor struct {}// Check checks for current time column count limit.-func (*ColumnCurrentTimeCountLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnCurrentTimeCountLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go b/backend/plugin/advisor/mysql/advisor_column_disallow_changing.goindex 3ba284b939..87e07701f1 100644--- a/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type ColumnDisallowChangingAdvisor struct {}// Check checks for disallow CHANGE COLUMN statement.-func (*ColumnDisallowChangingAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnDisallowChangingAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.goindex 75646d66fb..1dc0934151 100644--- a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type ColumnDisallowChangingOrderAdvisor struct {}// Check checks for disallow changing column order.-func (*ColumnDisallowChangingOrderAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnDisallowChangingOrderAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.goindex e5e981c926..44bd10a157 100644--- a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go@@ -7,6 +7,7 @@ import ("strings""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"@@ -30,10 +31,10 @@ type ColumnDisallowChangingTypeAdvisor struct {}// Check checks for disallow changing column type..-func (*ColumnDisallowChangingTypeAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnDisallowChangingTypeAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go b/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.goindex e5bd87e17a..74f74920b5 100644--- a/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type ColumnDisallowSetCharsetAdvisor struct {}// Check checks for disallow set column charset.-func (*ColumnDisallowSetCharsetAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnDisallowSetCharsetAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go b/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.goindex f15468b9e5..2a052f027c 100644--- a/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go+++ b/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go@@ -7,6 +7,7 @@ import ("github.com/pingcap/tidb/parser/ast""github.com/pingcap/tidb/parser/mysql"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -29,10 +30,10 @@ type ColumnMaximumCharacterLengthAdvisor struct {}// Check checks for maximum character length.-func (*ColumnMaximumCharacterLengthAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnMaximumCharacterLengthAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_no_null.go b/backend/plugin/advisor/mysql/advisor_column_no_null.goindex 8083c2f942..0b302fac5d 100644--- a/backend/plugin/advisor/mysql/advisor_column_no_null.go+++ b/backend/plugin/advisor/mysql/advisor_column_no_null.go@@ -5,6 +5,7 @@ import ("sort""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"@@ -28,10 +29,10 @@ type ColumnNoNullAdvisor struct {}// Check checks for column no NULL value.-func (*ColumnNoNullAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnNoNullAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_required.go b/backend/plugin/advisor/mysql/advisor_column_required.goindex 5ee55a50cd..8011ff1f47 100644--- a/backend/plugin/advisor/mysql/advisor_column_required.go+++ b/backend/plugin/advisor/mysql/advisor_column_required.go@@ -6,6 +6,7 @@ import ("strings""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type ColumnRequirementAdvisor struct {}// Check checks for the column requirement.-func (*ColumnRequirementAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnRequirementAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go b/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.goindex 87e0e038db..456fa7cc1c 100644--- a/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go+++ b/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type ColumnSetDefaultForNotNullAdvisor struct {}// Check checks for set default value for not null column.-func (*ColumnSetDefaultForNotNullAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnSetDefaultForNotNullAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_column_type_restriction.go b/backend/plugin/advisor/mysql/advisor_column_type_restriction.goindex 5a4abfd8d7..1b03fb8b5b 100644--- a/backend/plugin/advisor/mysql/advisor_column_type_restriction.go+++ b/backend/plugin/advisor/mysql/advisor_column_type_restriction.go@@ -7,6 +7,7 @@ import ("strings""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -29,10 +30,10 @@ type ColumnTypeRestrictionAdvisor struct {}// Check checks for column type restriction.-func (*ColumnTypeRestrictionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnTypeRestrictionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go b/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.goindex 613137f157..7af5a8a8e2 100644--- a/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go+++ b/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go@@ -4,6 +4,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"@@ -27,10 +28,10 @@ type DatabaseAllowDropIfEmptyAdvisor struct {}// Check checks for drop table naming convention.-func (*DatabaseAllowDropIfEmptyAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*DatabaseAllowDropIfEmptyAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go b/backend/plugin/advisor/mysql/advisor_index_key_number_limit.goindex 6a98f13876..a5a718ec0f 100644--- a/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go+++ b/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type IndexKeyNumberLimitAdvisor struct {}// Check checks for index key number limit.-func (*IndexKeyNumberLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*IndexKeyNumberLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go b/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.goindex c2156ee39e..2eba803b76 100644--- a/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go+++ b/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type IndexNoDuplicateColumnAdvisor struct {}// Check checks for no duplicate columns in index.-func (*IndexNoDuplicateColumnAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*IndexNoDuplicateColumnAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_index_pk_type.go b/backend/plugin/advisor/mysql/advisor_index_pk_type.goindex 1bcfbb5de6..9ef04a31d6 100644--- a/backend/plugin/advisor/mysql/advisor_index_pk_type.go+++ b/backend/plugin/advisor/mysql/advisor_index_pk_type.go@@ -32,10 +32,10 @@ type IndexPkTypeAdvisor struct {}// Check checks for correct type of PK.-func (*IndexPkTypeAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*IndexPkTypeAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go b/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.goindex 575f5b06e8..a76efa9494 100644--- a/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go+++ b/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go@@ -31,10 +31,10 @@ type IndexPrimaryKeyTypeAllowlistAdvisor struct {}// Check checks for primary key type allowlist.-func (*IndexPrimaryKeyTypeAllowlistAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*IndexPrimaryKeyTypeAllowlistAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go b/backend/plugin/advisor/mysql/advisor_index_total_number_limit.goindex 8dc124f4d7..c7a6c4cb4b 100644--- a/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go+++ b/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go@@ -7,6 +7,7 @@ import ("sort""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"@@ -30,10 +31,10 @@ type IndexTotalNumberLimitAdvisor struct {}// Check checks for index total number limit.-func (*IndexTotalNumberLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*IndexTotalNumberLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go b/backend/plugin/advisor/mysql/advisor_index_type_no_blob.goindex 02cdc1500c..02dc49d4cf 100644--- a/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go+++ b/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go@@ -33,10 +33,10 @@ type IndexTypeNoBlobAdvisor struct {}// Check checks for index type no blob.-func (*IndexTypeNoBlobAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*IndexTypeNoBlobAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go b/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.goindex 9fb1d13f1d..244a2215b6 100644--- a/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go+++ b/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type InsertDisallowOrderByRandAdvisor struct {}// Check checks for to disallow order by rand in INSERT statements.-func (*InsertDisallowOrderByRandAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*InsertDisallowOrderByRandAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go b/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.goindex f67685c6cf..eace2dc57d 100644--- a/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go+++ b/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type InsertMustSpecifyColumnAdvisor struct {}// Check checks for to enforce column specified.-func (*InsertMustSpecifyColumnAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*InsertMustSpecifyColumnAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_insert_row_limit.go b/backend/plugin/advisor/mysql/advisor_insert_row_limit.goindex 2375bde667..335ba02eb2 100644--- a/backend/plugin/advisor/mysql/advisor_insert_row_limit.go+++ b/backend/plugin/advisor/mysql/advisor_insert_row_limit.go@@ -31,10 +31,10 @@ type InsertRowLimitAdvisor struct {}// Check checks for to limit INSERT rows.-func (*InsertRowLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*InsertRowLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_migration_compatibility.go b/backend/plugin/advisor/mysql/advisor_migration_compatibility.goindex 96d14e2c9a..4463b4e313 100644--- a/backend/plugin/advisor/mysql/advisor_migration_compatibility.go+++ b/backend/plugin/advisor/mysql/advisor_migration_compatibility.go@@ -3,6 +3,8 @@ package mysqlimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -26,10 +28,10 @@ type CompatibilityAdvisor struct {}// Check checks schema backward compatibility.-func (*CompatibilityAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*CompatibilityAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go b/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.goindex 56f5dd88ab..976383116a 100644--- a/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go+++ b/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go@@ -7,6 +7,7 @@ import ("regexp""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -29,10 +30,10 @@ type NamingAutoIncrementColumnAdvisor struct {}// Check checks for auto-increment naming convention.-func (*NamingAutoIncrementColumnAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*NamingAutoIncrementColumnAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_naming_column.go b/backend/plugin/advisor/mysql/advisor_naming_column.goindex 146870c876..9df3e0d0e3 100644--- a/backend/plugin/advisor/mysql/advisor_naming_column.go+++ b/backend/plugin/advisor/mysql/advisor_naming_column.go@@ -5,6 +5,7 @@ import ("regexp""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -27,10 +28,10 @@ type NamingColumnConventionAdvisor struct {}// Check checks for column naming convention.-func (*NamingColumnConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*NamingColumnConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go b/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.goindex f70d448e0b..3a3503f1e6 100644--- a/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go+++ b/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go@@ -5,6 +5,7 @@ import ("strings""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -27,10 +28,10 @@ type NamingFKConventionAdvisor struct {}// Check checks for foreign key naming convention.-func (*NamingFKConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*NamingFKConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_naming_index_convention.go b/backend/plugin/advisor/mysql/advisor_naming_index_convention.goindex c939bf548a..7dcb28e44c 100644--- a/backend/plugin/advisor/mysql/advisor_naming_index_convention.go+++ b/backend/plugin/advisor/mysql/advisor_naming_index_convention.go@@ -6,6 +6,7 @@ import ("strings""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"@@ -29,10 +30,10 @@ type NamingIndexConventionAdvisor struct {}// Check checks for index naming convention.-func (*NamingIndexConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*NamingIndexConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_naming_table.go b/backend/plugin/advisor/mysql/advisor_naming_table.goindex 6099436e90..ac298c0bd3 100644--- a/backend/plugin/advisor/mysql/advisor_naming_table.go+++ b/backend/plugin/advisor/mysql/advisor_naming_table.go@@ -5,6 +5,7 @@ import ("regexp""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -27,10 +28,10 @@ type NamingTableConventionAdvisor struct {}// Check checks for table naming convention.-func (*NamingTableConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*NamingTableConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go b/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.goindex cc427764ce..bf6b6c9053 100644--- a/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go+++ b/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go@@ -5,6 +5,7 @@ import ("strings""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"@@ -28,10 +29,10 @@ type NamingUKConventionAdvisor struct {}// Check checks for index naming convention.-func (*NamingUKConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*NamingUKConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go b/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.goindex cc910f58b0..190f1d3ba6 100644--- a/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go+++ b/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go@@ -31,10 +31,10 @@ type StatementAffectedRowLimitAdvisor struct {}// Check checks for UPDATE/DELETE affected row limit.-func (*StatementAffectedRowLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*StatementAffectedRowLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go b/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.goindex 16009a1344..87da26d2a9 100644--- a/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go+++ b/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go@@ -8,6 +8,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -30,10 +31,10 @@ type StatementDmlDryRunAdvisor struct {}// Check checks for DML dry run.-func (*StatementDmlDryRunAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*StatementDmlDryRunAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go b/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.goindex d972743f96..51d5d64f76 100644--- a/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go+++ b/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go@@ -7,6 +7,7 @@ import ("sort""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -29,10 +30,10 @@ type StatementMergeAlterTableAdvisor struct {}// Check checks for merging ALTER TABLE statements.-func (*StatementMergeAlterTableAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*StatementMergeAlterTableAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go b/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.goindex ad326f8aa2..2fd3b87940 100644--- a/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go+++ b/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type StatementDisallowCommitAdvisor struct {}// Check checks for index type no blob.-func (*StatementDisallowCommitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*StatementDisallowCommitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_stmt_disallow_limit.go b/backend/plugin/advisor/mysql/advisor_stmt_disallow_limit.goindex bf608f00c7..d54d13979b 100644--- a/backend/plugin/advisor/mysql/advisor_stmt_disallow_limit.go+++ b/backend/plugin/advisor/mysql/advisor_stmt_disallow_limit.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type DisallowLimitAdvisor struct {}// Check checks for no LIMIT clause in INSERT/UPDATE statement.-func (*DisallowLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*DisallowLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_stmt_disallow_order_by.go b/backend/plugin/advisor/mysql/advisor_stmt_disallow_order_by.goindex 2e6b0e2523..23eaf919ff 100644--- a/backend/plugin/advisor/mysql/advisor_stmt_disallow_order_by.go+++ b/backend/plugin/advisor/mysql/advisor_stmt_disallow_order_by.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type DisallowOrderByAdvisor struct {}// Check checks for no ORDER BY clause in DELETE/UPDATE statements.-func (*DisallowOrderByAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*DisallowOrderByAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go b/backend/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.goindex d5d60f06c3..cf028724df 100644--- a/backend/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go+++ b/backend/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go@@ -5,6 +5,7 @@ import ("github.com/pingcap/tidb/parser/ast""github.com/pingcap/tidb/parser/format"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -31,10 +32,10 @@ type NoLeadingWildcardLikeAdvisor struct {}// Check checks for no leading wildcard LIKE.-func (*NoLeadingWildcardLikeAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*NoLeadingWildcardLikeAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_stmt_no_select_all.go b/backend/plugin/advisor/mysql/advisor_stmt_no_select_all.goindex 6519cc63d1..edaf76bf2a 100644--- a/backend/plugin/advisor/mysql/advisor_stmt_no_select_all.go+++ b/backend/plugin/advisor/mysql/advisor_stmt_no_select_all.go@@ -4,6 +4,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -26,10 +27,10 @@ type NoSelectAllAdvisor struct {}// Check checks for no "select *".-func (*NoSelectAllAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*NoSelectAllAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_stmt_where_required.go b/backend/plugin/advisor/mysql/advisor_stmt_where_required.goindex 748b284a76..d5b4cbe352 100644--- a/backend/plugin/advisor/mysql/advisor_stmt_where_required.go+++ b/backend/plugin/advisor/mysql/advisor_stmt_where_required.go@@ -3,6 +3,8 @@ package mysqlimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -26,10 +28,10 @@ type WhereRequirementAdvisor struct {}// Check checks for the WHERE clause requirement.-func (*WhereRequirementAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*WhereRequirementAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_syntax.go b/backend/plugin/advisor/mysql/advisor_syntax.godeleted file mode 100644index 9a60a5d742..0000000000--- a/backend/plugin/advisor/mysql/advisor_syntax.go+++ /dev/null@@ -1,37 +0,0 @@-package mysql--import (- "github.com/bytebase/bytebase/backend/plugin/advisor"- "github.com/bytebase/bytebase/backend/plugin/advisor/db"-)--var (- _ advisor.Advisor = (*SyntaxAdvisor)(nil)-)--func init() {- advisor.Register(db.MySQL, advisor.MySQLSyntax, &SyntaxAdvisor{})- advisor.Register(db.TiDB, advisor.MySQLSyntax, &SyntaxAdvisor{})- advisor.Register(db.MariaDB, advisor.MySQLSyntax, &SyntaxAdvisor{})- advisor.Register(db.OceanBase, advisor.MySQLSyntax, &SyntaxAdvisor{})-}--// SyntaxAdvisor is the advisor for checking syntax.-type SyntaxAdvisor struct {-}--// Check parses the given statement and checks for warnings and errors.-func (*SyntaxAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- _, adviceList := parseStatement(statement, ctx.Charset, ctx.Collation)-- if len(adviceList) == 0 {- adviceList = append(adviceList, advisor.Advice{- Status: advisor.Success,- Code: advisor.Ok,- Title: "Syntax OK",- Content: "OK",- })- }-- return adviceList, nil-}diff --git a/backend/plugin/advisor/mysql/advisor_table_comment_convention.go b/backend/plugin/advisor/mysql/advisor_table_comment_convention.goindex f1aebcee6c..8b5b2c951e 100644--- a/backend/plugin/advisor/mysql/advisor_table_comment_convention.go+++ b/backend/plugin/advisor/mysql/advisor_table_comment_convention.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type TableCommentConventionAdvisor struct {}// Check checks for table comment convention.-func (*TableCommentConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*TableCommentConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go b/backend/plugin/advisor/mysql/advisor_table_disallow_partition.goindex d7af862ac6..8fb962ca9b 100644--- a/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go+++ b/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go@@ -6,6 +6,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +29,10 @@ type TableDisallowPartitionAdvisor struct {}// Check checks for disallow table partition.-func (*TableDisallowPartitionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*TableDisallowPartitionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.goindex 13d1dce861..757adf0d51 100644--- a/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go+++ b/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go@@ -5,6 +5,7 @@ import ("regexp""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -27,10 +28,10 @@ type TableDropNamingConventionAdvisor struct {}// Check checks for drop table naming convention.-func (*TableDropNamingConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*TableDropNamingConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_table_no_fk.go b/backend/plugin/advisor/mysql/advisor_table_no_fk.goindex 2c38d4685f..d1c8a15c9b 100644--- a/backend/plugin/advisor/mysql/advisor_table_no_fk.go+++ b/backend/plugin/advisor/mysql/advisor_table_no_fk.go@@ -4,6 +4,7 @@ import ("fmt""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -26,12 +27,11 @@ type TableNoFKAdvisor struct {}// Check checks table disallow foreign key.-func (*TableNoFKAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*TableNoFKAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}-level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)if err != nil {return nil, errdiff --git a/backend/plugin/advisor/mysql/advisor_table_require_pk.go b/backend/plugin/advisor/mysql/advisor_table_require_pk.goindex 30c84709a3..74b6cd2c18 100644--- a/backend/plugin/advisor/mysql/advisor_table_require_pk.go+++ b/backend/plugin/advisor/mysql/advisor_table_require_pk.go@@ -5,6 +5,7 @@ import ("strings""github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"@@ -32,10 +33,10 @@ type TableRequirePKAdvisor struct {}// Check checks table requires PK.-func (*TableRequirePKAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*TableRequirePKAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/advisor_use_innodb.go b/backend/plugin/advisor/mysql/advisor_use_innodb.goindex 17ccf07ff6..90805953bd 100644--- a/backend/plugin/advisor/mysql/advisor_use_innodb.go+++ b/backend/plugin/advisor/mysql/advisor_use_innodb.go@@ -6,6 +6,7 @@ import ("github.com/pingcap/tidb/parser/ast""github.com/pingcap/tidb/parser/format"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -31,10 +32,10 @@ type UseInnoDBAdvisor struct {}// Check checks for using InnoDB engine.-func (*UseInnoDBAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement, ctx.Charset, ctx.Collation)- if errAdvice != nil {- return errAdvice, nil+func (*UseInnoDBAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.StmtNode)+ if !ok {+ return nil, errors.Errorf("failed to convert to StmtNode")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/mysql/parser.go b/backend/plugin/advisor/mysql/parser.godeleted file mode 100644index 7ff5db46e4..0000000000--- a/backend/plugin/advisor/mysql/parser.go+++ /dev/null@@ -1,92 +0,0 @@-package mysql--import (- tidbparser "github.com/pingcap/tidb/parser"- "github.com/pingcap/tidb/parser/ast"-- "github.com/bytebase/bytebase/backend/plugin/advisor"- parser "github.com/bytebase/bytebase/backend/plugin/parser/sql"-)--// Wrapper for parser.New().-func newParser() *tidbparser.Parser {- p := tidbparser.New()-- // To support MySQL8 window function syntax.- // See https://github.com/bytebase/bytebase/issues/175.- p.EnableWindowFunc(true)-- return p-}--func parseStatement(statement string, charset string, collation string) ([]ast.StmtNode, []advisor.Advice) {- list, err := parser.SplitMySQL(statement)- if err != nil {- return nil, []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.Internal,- Title: "Syntax error",- Content: err.Error(),- Line: 1,- },- }- }-- p := newParser()- var returnNodes []ast.StmtNode- var adviceList []advisor.Advice- for _, item := range list {- nodes, _, err := p.Parse(item.Text, charset, collation)- if err != nil {- // TiDB parser doesn't fully support MySQL syntax, so we need to use MySQL parser to parse the statement.- // But MySQL parser has some performance issue, so we only use it to parse the statement after TiDB parser failed.- if _, err := parser.ParseMySQL(item.Text); err != nil {- if syntaxErr, ok := err.(*parser.SyntaxError); ok {- return nil, []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.StatementSyntaxError,- Title: advisor.SyntaxErrorTitle,- Content: syntaxErr.Message,- Line: syntaxErr.Line,- },- }- }- return nil, []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.Internal,- Title: "Parse error",- Content: err.Error(),- Line: 1,- },- }- }- // If MySQL parser can parse the statement, but TiDB parser can't, we just ignore the statement.- continue- }-- if len(nodes) != 1 {- continue- }-- node := nodes[0]- node.SetText(nil, item.Text)- node.SetOriginTextPosition(item.LastLine)- if n, ok := node.(*ast.CreateTableStmt); ok {- if err := parser.SetLineForMySQLCreateTableStmt(n); err != nil {- return nil, append(adviceList, advisor.Advice{- Status: advisor.Error,- Code: advisor.Internal,- Title: "Set line error",- Content: err.Error(),- Line: item.LastLine,- })- }- }- returnNodes = append(returnNodes, node)- }-- return returnNodes, adviceList-}diff --git a/backend/plugin/advisor/mysql/parser_test.go b/backend/plugin/advisor/mysql/parser_test.godeleted file mode 100644index 131f6c5eba..0000000000--- a/backend/plugin/advisor/mysql/parser_test.go+++ /dev/null@@ -1,15 +0,0 @@-package mysql--import (- "testing"-- "github.com/stretchr/testify/assert"- "github.com/stretchr/testify/require"-)--func TestMysql8WindowFunction(t *testing.T) {- parser := newParser()- _, warns, err := parser.Parse("SELECT row_number() OVER ( ORDER BY id ), id FROM xxx;", "utf8mb4", "utf8mb4_general_ci")- require.NoError(t, err)- assert.Empty(t, warns)-}diff --git a/backend/plugin/advisor/oracle/advisor_column_add_not_null_column_require_default.go b/backend/plugin/advisor/oracle/advisor_column_add_not_null_column_require_default.goindex 9b280ad8c1..fd2fa204a4 100644--- a/backend/plugin/advisor/oracle/advisor_column_add_not_null_column_require_default.go+++ b/backend/plugin/advisor/oracle/advisor_column_add_not_null_column_require_default.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -24,10 +25,10 @@ type ColumnAddNotNullColumnRequireDefaultAdvisor struct {}// Check checks for adding not null column requires default.-func (*ColumnAddNotNullColumnRequireDefaultAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnAddNotNullColumnRequireDefaultAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_column_maximum_character_length.go b/backend/plugin/advisor/oracle/advisor_column_maximum_character_length.goindex be9766a9ed..f067e8d299 100644--- a/backend/plugin/advisor/oracle/advisor_column_maximum_character_length.go+++ b/backend/plugin/advisor/oracle/advisor_column_maximum_character_length.go@@ -7,6 +7,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type ColumnMaximumCharacterLengthAdvisor struct {}// Check checks for maximum character length.-func (*ColumnMaximumCharacterLengthAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnMaximumCharacterLengthAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_column_maximum_varchar_length.go b/backend/plugin/advisor/oracle/advisor_column_maximum_varchar_length.goindex 8d94f08247..8c2737408a 100644--- a/backend/plugin/advisor/oracle/advisor_column_maximum_varchar_length.go+++ b/backend/plugin/advisor/oracle/advisor_column_maximum_varchar_length.go@@ -7,6 +7,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type ColumnMaximumVarcharLengthAdvisor struct {}// Check checks for maximum varchar length.-func (*ColumnMaximumVarcharLengthAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnMaximumVarcharLengthAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_column_no_null.go b/backend/plugin/advisor/oracle/advisor_column_no_null.goindex 988b342013..fc57fca7b4 100644--- a/backend/plugin/advisor/oracle/advisor_column_no_null.go+++ b/backend/plugin/advisor/oracle/advisor_column_no_null.go@@ -7,6 +7,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -27,10 +28,10 @@ type ColumnNoNullAdvisor struct {}// Check checks for column no NULL value.-func (*ColumnNoNullAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnNoNullAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_column_require.go b/backend/plugin/advisor/oracle/advisor_column_require.goindex 348c34beb3..44f0a12085 100644--- a/backend/plugin/advisor/oracle/advisor_column_require.go+++ b/backend/plugin/advisor/oracle/advisor_column_require.go@@ -8,6 +8,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -26,10 +27,10 @@ type ColumnRequireAdvisor struct {}// Check checks for column requirement.-func (*ColumnRequireAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnRequireAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_column_require_default.go b/backend/plugin/advisor/oracle/advisor_column_require_default.goindex e6fd180ba9..36ea28f32c 100644--- a/backend/plugin/advisor/oracle/advisor_column_require_default.go+++ b/backend/plugin/advisor/oracle/advisor_column_require_default.go@@ -7,6 +7,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type ColumnRequireDefaultAdvisor struct {}// Check checks for column default requirement.-func (*ColumnRequireDefaultAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnRequireDefaultAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_column_type_disallow_list.go b/backend/plugin/advisor/oracle/advisor_column_type_disallow_list.goindex 1d7305bc71..f53489bdb5 100644--- a/backend/plugin/advisor/oracle/advisor_column_type_disallow_list.go+++ b/backend/plugin/advisor/oracle/advisor_column_type_disallow_list.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type ColumnTypeDisallowListAdvisor struct {}// Check checks for column type disallow list.-func (*ColumnTypeDisallowListAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnTypeDisallowListAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_index_key_number_limit.go b/backend/plugin/advisor/oracle/advisor_index_key_number_limit.goindex 14a5f44b8b..6cbc2e812f 100644--- a/backend/plugin/advisor/oracle/advisor_index_key_number_limit.go+++ b/backend/plugin/advisor/oracle/advisor_index_key_number_limit.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -24,10 +25,10 @@ type IndexKeyNumberLimitAdvisor struct {}// Check checks for index key number limit.-func (*IndexKeyNumberLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*IndexKeyNumberLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_insert_must_specify_column.go b/backend/plugin/advisor/oracle/advisor_insert_must_specify_column.goindex 00cf76c77b..ec515ee9b7 100644--- a/backend/plugin/advisor/oracle/advisor_insert_must_specify_column.go+++ b/backend/plugin/advisor/oracle/advisor_insert_must_specify_column.go@@ -4,6 +4,7 @@ package oracleimport ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -22,10 +23,10 @@ type InsertMustSpecifyColumnAdvisor struct {}// Check checks for to enforce column specified.-func (*InsertMustSpecifyColumnAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*InsertMustSpecifyColumnAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go b/backend/plugin/advisor/oracle/advisor_naming_identifier_case.goindex 12a7f65235..cb51128424 100644--- a/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go+++ b/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go@@ -7,6 +7,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type NamingIdentifierCaseAdvisor struct {}// Check checks for identifier case.-func (*NamingIdentifierCaseAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingIdentifierCaseAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_naming_identifier_no_keyword.go b/backend/plugin/advisor/oracle/advisor_naming_identifier_no_keyword.goindex 49f43a3f71..df26728e2b 100644--- a/backend/plugin/advisor/oracle/advisor_naming_identifier_no_keyword.go+++ b/backend/plugin/advisor/oracle/advisor_naming_identifier_no_keyword.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type NamingIdentifierNoKeywordAdvisor struct {}// Check checks for identifier naming convention without keyword.-func (*NamingIdentifierNoKeywordAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingIdentifierNoKeywordAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_naming_table.go b/backend/plugin/advisor/oracle/advisor_naming_table.goindex 0200ce51e6..575bf11075 100644--- a/backend/plugin/advisor/oracle/advisor_naming_table.go+++ b/backend/plugin/advisor/oracle/advisor_naming_table.go@@ -7,6 +7,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type NamingTableAdvisor struct {}// Check checks for table naming convention.-func (*NamingTableAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingTableAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_naming_table_no_keyword.go b/backend/plugin/advisor/oracle/advisor_naming_table_no_keyword.goindex c481f36697..e258d2d94d 100644--- a/backend/plugin/advisor/oracle/advisor_naming_table_no_keyword.go+++ b/backend/plugin/advisor/oracle/advisor_naming_table_no_keyword.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type NamingTableNoKeywordAdvisor struct {}// Check checks for table naming convention without keyword.-func (*NamingTableNoKeywordAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingTableNoKeywordAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_select_no_select_all.go b/backend/plugin/advisor/oracle/advisor_select_no_select_all.goindex 86d3b5b8df..112023e32c 100644--- a/backend/plugin/advisor/oracle/advisor_select_no_select_all.go+++ b/backend/plugin/advisor/oracle/advisor_select_no_select_all.go@@ -4,6 +4,7 @@ package oracleimport ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -22,10 +23,10 @@ type SelectNoSelectAllAdvisor struct {}// Check checks for no select all.-func (*SelectNoSelectAllAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*SelectNoSelectAllAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_syntax.go b/backend/plugin/advisor/oracle/advisor_syntax.godeleted file mode 100644index d32f4d76d1..0000000000--- a/backend/plugin/advisor/oracle/advisor_syntax.go+++ /dev/null@@ -1,33 +0,0 @@-// Package oracle is the advisor for oracle database.-package oracle--import (- "github.com/bytebase/bytebase/backend/plugin/advisor"- "github.com/bytebase/bytebase/backend/plugin/advisor/db"-)--var (- _ advisor.Advisor = (*SyntaxAdvisor)(nil)-)--func init() {- advisor.Register(db.Oracle, advisor.OracleSyntax, &SyntaxAdvisor{})-}--// SyntaxAdvisor is the advisor checking for syntax.-type SyntaxAdvisor struct {-}--// Check checks for syntax.-func (*SyntaxAdvisor) Check(_ advisor.Context, statement string) ([]advisor.Advice, error) {- if _, errAdvice := parseStatement(statement); errAdvice != nil {- return errAdvice, nil- }-- return []advisor.Advice{{- Status: advisor.Success,- Code: advisor.Ok,- Title: "Syntax OK",- Content: "OK",- }}, nil-}diff --git a/backend/plugin/advisor/oracle/advisor_syntax_test.go b/backend/plugin/advisor/oracle/advisor_syntax_test.godeleted file mode 100644index 7a885ea81c..0000000000--- a/backend/plugin/advisor/oracle/advisor_syntax_test.go+++ /dev/null@@ -1,58 +0,0 @@-// Package oracle is the advisor for oracle database.-package oracle--import (- "testing"-- "github.com/stretchr/testify/assert"- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/backend/plugin/advisor"-)--func TestOracleSyntax(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "CREATE TABLE book(id int);",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "Syntax OK",- Content: "OK",- },- },- },- {- Statement: "DROP TABLE book CASCADE CONSTRAINTS;",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "Syntax OK",- Content: "OK",- },- },- },- {- Statement: "CREATE TABLE book(id int) ENGINE=INNODB;",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementSyntaxError,- Title: "Syntax error",- Content: "line 1:26 no viable alternative at input 'ENGINE' \nline 1:32 extraneous input '=' expecting {<EOF>, 'ABORT', 'ABS', 'ABSENT', 'ACCESS', 'ACCESSED', 'ACCOUNT', 'ACL', 'ACOS', 'ACROSS', 'ACTION', 'ACTIONS', 'ACTIVATE', 'ACTIVE', 'ACTIVE_COMPONENT', 'ACTIVE_DATA', 'ACTIVE_FUNCTION', 'ACTIVE_TAG', 'ACTIVITY', 'ADAPTIVE_PLAN', 'ADD', 'ADD_COLUMN', 'ADD_GROUP', 'ADD_MONTHS', 'ADJ_DATE', 'ADMIN', 'ADMINISTER', 'ADMINISTRATOR', 'ADVANCED', 'ADVISE', 'ADVISOR', 'AFD_DISKSTRING', 'AFTER', 'AGENT', 'AGGREGATE', 'A', 'ALIAS', 'ALLOCATE', 'ALLOW', 'ALL_ROWS', 'ALTER', 'ALTERNATE', 'ALWAYS', 'ANALYTIC', 'ANALYZE', 'ANCESTOR', 'ANCILLARY', 'AND_EQUAL', 'ANOMALY', 'ANSI_REARCH', 'ANTIJOIN', 'ANYSCHEMA', 'APPEND', 'APPENDCHILDXML', 'APPEND_VALUES', 'APPLICATION', 'APPLY', 'APPROX_COUNT_DISTINCT', 'ARCHIVAL', 'ARCHIVE', 'ARCHIVED', 'ARCHIVELOG', 'ARRAY', 'ASCII', 'ASCIISTR', 'ASIN', 'ASIS', 'ASSEMBLY', 'ASSIGN', 'ASSOCIATE', 'ASYNC', 'ASYNCHRONOUS', 'ATAN2', 'ATAN', 'AT', 'ATTRIBUTE', 'ATTRIBUTES', 'AUDIT', 'AUTHENTICATED', 'AUTHENTICATION', 'AUTHID', 'AUTHORIZATION', 'AUTOALLOCATE', 'A",- Line: 1,- },- },- },- }-- adv := &SyntaxAdvisor{}-- for _, tc := range tests {- adviceList, err := adv.Check(advisor.Context{}, tc.Statement)- require.NoError(t, err)- assert.Equal(t, tc.Want, adviceList)- }-}diff --git a/backend/plugin/advisor/oracle/advisor_table_no_foreign_key.go b/backend/plugin/advisor/oracle/advisor_table_no_foreign_key.goindex 0d61789047..cb3826c4ef 100644--- a/backend/plugin/advisor/oracle/advisor_table_no_foreign_key.go+++ b/backend/plugin/advisor/oracle/advisor_table_no_foreign_key.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -24,10 +25,10 @@ type TableNoForeignKeyAdvisor struct {}// Check checks for table disallow foreign key.-func (*TableNoForeignKeyAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*TableNoForeignKeyAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_table_require_pk.go b/backend/plugin/advisor/oracle/advisor_table_require_pk.goindex 9a816737e1..d26fc68280 100644--- a/backend/plugin/advisor/oracle/advisor_table_require_pk.go+++ b/backend/plugin/advisor/oracle/advisor_table_require_pk.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -24,10 +25,10 @@ type TableRequirePKAdvisor struct {}// Check checks table requires PK.-func (*TableRequirePKAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*TableRequirePKAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_where_no_leading_wildcard_like.go b/backend/plugin/advisor/oracle/advisor_where_no_leading_wildcard_like.goindex bd5d882e93..ec2773b130 100644--- a/backend/plugin/advisor/oracle/advisor_where_no_leading_wildcard_like.go+++ b/backend/plugin/advisor/oracle/advisor_where_no_leading_wildcard_like.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -24,10 +25,10 @@ type WhereNoLeadingWildcardLikeAdvisor struct {}// Check checks for no leading wildcard LIKE.-func (*WhereNoLeadingWildcardLikeAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*WhereNoLeadingWildcardLikeAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/advisor_where_require.go b/backend/plugin/advisor/oracle/advisor_where_require.goindex 10fd7a5cd4..f482496247 100644--- a/backend/plugin/advisor/oracle/advisor_where_require.go+++ b/backend/plugin/advisor/oracle/advisor_where_require.go@@ -4,6 +4,7 @@ package oracleimport ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -22,10 +23,10 @@ type WhereRequireAdvisor struct {}// Check checks for WHERE clause requirement.-func (*WhereRequireAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*WhereRequireAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/oracle/parser.go b/backend/plugin/advisor/oracle/parser.goindex aafcdb263e..4230caa24d 100644--- a/backend/plugin/advisor/oracle/parser.go+++ b/backend/plugin/advisor/oracle/parser.go@@ -8,39 +8,8 @@ import ("github.com/antlr4-go/antlr/v4"plsql "github.com/bytebase/plsql-parser"-- "github.com/bytebase/bytebase/backend/plugin/advisor"- parser "github.com/bytebase/bytebase/backend/plugin/parser/sql")-func parseStatement(statement string) (antlr.Tree, []advisor.Advice) {- tree, err := parser.ParsePLSQL(statement + ";")- if err != nil {- if syntaxErr, ok := err.(*parser.SyntaxError); ok {- return nil, []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementSyntaxError,- Title: advisor.SyntaxErrorTitle,- Content: syntaxErr.Message,- Line: syntaxErr.Line,- },- }- }- return nil, []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.Internal,- Title: "Parse error",- Content: err.Error(),- Line: 1,- },- }- }-- return tree, nil-}-func normalizeIdentifier(ctx antlr.ParserRuleContext, currentSchema string) string {switch ctx := ctx.(type) {case *plsql.IdentifierContext:diff --git a/backend/plugin/advisor/pg/advisor_collation_allowlist.go b/backend/plugin/advisor/pg/advisor_collation_allowlist.goindex 342dc2b586..4d5e4bb7ec 100644--- a/backend/plugin/advisor/pg/advisor_collation_allowlist.go+++ b/backend/plugin/advisor/pg/advisor_collation_allowlist.go@@ -5,6 +5,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -24,10 +26,10 @@ type CollationAllowlistAdvisor struct {}// Check checks for collation allowlist.-func (*CollationAllowlistAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*CollationAllowlistAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.go b/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.goindex 8d69a2bfde..d2c5b0ba97 100644--- a/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.go+++ b/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.go@@ -5,6 +5,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -24,10 +26,10 @@ type ColumnDisallowChangingTypeAdvisor struct {}// Check checks for disallow changing column type.-func (*ColumnDisallowChangingTypeAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnDisallowChangingTypeAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_column_maximum_character_length.go b/backend/plugin/advisor/pg/advisor_column_maximum_character_length.goindex acdd9b4631..c7929367e8 100644--- a/backend/plugin/advisor/pg/advisor_column_maximum_character_length.go+++ b/backend/plugin/advisor/pg/advisor_column_maximum_character_length.go@@ -5,6 +5,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -24,10 +26,10 @@ type ColumnMaximumCharacterLengthAdvisor struct {}// Check checks for maximum character length.-func (*ColumnMaximumCharacterLengthAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnMaximumCharacterLengthAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_column_no_null.go b/backend/plugin/advisor/pg/advisor_column_no_null.goindex 75f147b514..efec2157fe 100644--- a/backend/plugin/advisor/pg/advisor_column_no_null.go+++ b/backend/plugin/advisor/pg/advisor_column_no_null.go@@ -4,6 +4,8 @@ import ("fmt""sort"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -24,10 +26,10 @@ type ColumnNoNullAdvisor struct {}// Check checks for column no NULL value.-func (*ColumnNoNullAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnNoNullAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_column_require_default.go b/backend/plugin/advisor/pg/advisor_column_require_default.goindex 333c12d800..c0e44b11a6 100644--- a/backend/plugin/advisor/pg/advisor_column_require_default.go+++ b/backend/plugin/advisor/pg/advisor_column_require_default.go@@ -6,6 +6,8 @@ import ("fmt""sort"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -26,10 +28,10 @@ type ColumnRequireDefaultAdvisor struct {}// Check checks for column default requirement.-func (*ColumnRequireDefaultAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnRequireDefaultAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_column_required.go b/backend/plugin/advisor/pg/advisor_column_required.goindex 450e9855d2..c32d190bae 100644--- a/backend/plugin/advisor/pg/advisor_column_required.go+++ b/backend/plugin/advisor/pg/advisor_column_required.go@@ -5,6 +5,8 @@ import ("sort""strings"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -26,10 +28,10 @@ type ColumnRequirementAdvisor struct {}// Check checks for the column requirement.-func (*ColumnRequirementAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnRequirementAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_column_type_disallow_list.go b/backend/plugin/advisor/pg/advisor_column_type_disallow_list.goindex b44c7cba75..e5b56e7f50 100644--- a/backend/plugin/advisor/pg/advisor_column_type_disallow_list.go+++ b/backend/plugin/advisor/pg/advisor_column_type_disallow_list.go@@ -4,6 +4,8 @@ import ("fmt""strings"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -18,10 +20,10 @@ type ColumnTypeDisallowListAdvisor struct {}// Check checks for column type restriction.-func (*ColumnTypeDisallowListAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnTypeDisallowListAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_comment_convention.go b/backend/plugin/advisor/pg/advisor_comment_convention.goindex afa263751f..b1586a56b2 100644--- a/backend/plugin/advisor/pg/advisor_comment_convention.go+++ b/backend/plugin/advisor/pg/advisor_comment_convention.go@@ -5,6 +5,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -24,10 +26,10 @@ type CommentConventionAdvisor struct {}// Check checks for comment convention.-func (*CommentConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*CommentConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_encoding_allowlist.go b/backend/plugin/advisor/pg/advisor_encoding_allowlist.goindex e84504e6ad..43dd4fd8aa 100644--- a/backend/plugin/advisor/pg/advisor_encoding_allowlist.go+++ b/backend/plugin/advisor/pg/advisor_encoding_allowlist.go@@ -4,6 +4,8 @@ import ("fmt""strings"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -23,10 +25,10 @@ type EncodingAllowlistAdvisor struct {}// Check checks for encoding allowlist.-func (*EncodingAllowlistAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*EncodingAllowlistAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_index_create_concurrently.go b/backend/plugin/advisor/pg/advisor_index_create_concurrently.goindex 2298011d26..7ba39d7ca6 100644--- a/backend/plugin/advisor/pg/advisor_index_create_concurrently.go+++ b/backend/plugin/advisor/pg/advisor_index_create_concurrently.go@@ -3,6 +3,8 @@ package pg// Framework code is generated by the generator.import (+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -22,10 +24,10 @@ type IndexCreateConcurrentlyAdvisor struct {}// Check checks for to create index concurrently.-func (*IndexCreateConcurrentlyAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*IndexCreateConcurrentlyAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_index_key_number_limit.go b/backend/plugin/advisor/pg/advisor_index_key_number_limit.goindex f956343405..99ce920046 100644--- a/backend/plugin/advisor/pg/advisor_index_key_number_limit.go+++ b/backend/plugin/advisor/pg/advisor_index_key_number_limit.go@@ -3,6 +3,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -22,10 +24,10 @@ type IndexKeyNumberLimitAdvisor struct {}// Check checks for index key number limit.-func (*IndexKeyNumberLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*IndexKeyNumberLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.go b/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.goindex e13f29edbd..5f05c71ff0 100644--- a/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.go+++ b/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.go@@ -3,6 +3,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -17,10 +19,10 @@ type IndexNoDuplicateColumnAdvisor struct {}// Check checks for no duplicate columns in index.-func (*IndexNoDuplicateColumnAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*IndexNoDuplicateColumnAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_index_primary_key_type_allowlist.go b/backend/plugin/advisor/pg/advisor_index_primary_key_type_allowlist.goindex cfc7961c6d..b5e1a1244f 100644--- a/backend/plugin/advisor/pg/advisor_index_primary_key_type_allowlist.go+++ b/backend/plugin/advisor/pg/advisor_index_primary_key_type_allowlist.go@@ -7,6 +7,8 @@ import ("go.uber.org/zap"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/common/log""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -28,10 +30,10 @@ type IndexPrimaryKeyTypeAllowlistAdvisor struct {}// Check checks for primary key type allowlist.-func (*IndexPrimaryKeyTypeAllowlistAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*IndexPrimaryKeyTypeAllowlistAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_index_total_number_limit.go b/backend/plugin/advisor/pg/advisor_index_total_number_limit.goindex f17eb72bf1..702bc2cb00 100644--- a/backend/plugin/advisor/pg/advisor_index_total_number_limit.go+++ b/backend/plugin/advisor/pg/advisor_index_total_number_limit.go@@ -6,6 +6,8 @@ import ("fmt""sort"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -26,10 +28,10 @@ type IndexTotalNumberLimitAdvisor struct {}// Check checks for index total number limit.-func (*IndexTotalNumberLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*IndexTotalNumberLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_insert_disallow_order_by_rand.go b/backend/plugin/advisor/pg/advisor_insert_disallow_order_by_rand.goindex 24de9e78c2..4e5cf2c456 100644--- a/backend/plugin/advisor/pg/advisor_insert_disallow_order_by_rand.go+++ b/backend/plugin/advisor/pg/advisor_insert_disallow_order_by_rand.go@@ -6,6 +6,8 @@ import ("fmt""strings"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -25,10 +27,10 @@ type InsertDisallowOrderByRandAdvisor struct {}// Check checks for to disallow order by rand in INSERT statements.-func (*InsertDisallowOrderByRandAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*InsertDisallowOrderByRandAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_insert_must_specify_column.go b/backend/plugin/advisor/pg/advisor_insert_must_specify_column.goindex 0f3e21ac47..dc7eb3a232 100644--- a/backend/plugin/advisor/pg/advisor_insert_must_specify_column.go+++ b/backend/plugin/advisor/pg/advisor_insert_must_specify_column.go@@ -5,6 +5,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -24,10 +26,10 @@ type InsertMustSpecifyColumnAdvisor struct {}// Check checks for to enforce column specified.-func (*InsertMustSpecifyColumnAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*InsertMustSpecifyColumnAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_insert_row_limit.go b/backend/plugin/advisor/pg/advisor_insert_row_limit.goindex 9385e58663..44c97de76c 100644--- a/backend/plugin/advisor/pg/advisor_insert_row_limit.go+++ b/backend/plugin/advisor/pg/advisor_insert_row_limit.go@@ -28,10 +28,10 @@ type InsertRowLimitAdvisor struct {}// Check checks for the WHERE clause requirement.-func (*InsertRowLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*InsertRowLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_migration_compatibility.go b/backend/plugin/advisor/pg/advisor_migration_compatibility.goindex 1373f2e0e1..0265a70afc 100644--- a/backend/plugin/advisor/pg/advisor_migration_compatibility.go+++ b/backend/plugin/advisor/pg/advisor_migration_compatibility.go@@ -3,6 +3,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -22,10 +24,10 @@ type CompatibilityAdvisor struct {}// Check checks schema backward compatibility.-func (*CompatibilityAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*CompatibilityAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_naming_column.go b/backend/plugin/advisor/pg/advisor_naming_column.goindex 226911c7c3..9a8d464d73 100644--- a/backend/plugin/advisor/pg/advisor_naming_column.go+++ b/backend/plugin/advisor/pg/advisor_naming_column.go@@ -4,6 +4,8 @@ import ("fmt""regexp"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -23,10 +25,10 @@ type NamingColumnConventionAdvisor struct {}// Check checks for column naming convention.-func (*NamingColumnConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingColumnConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.goindex b48510db26..141779ac49 100644--- a/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.go+++ b/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.go@@ -5,6 +5,8 @@ import ("regexp""strings"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -24,10 +26,10 @@ type NamingFKConventionAdvisor struct {}// Check checks for foreign key naming convention.-func (*NamingFKConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingFKConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_naming_index_convention.go b/backend/plugin/advisor/pg/advisor_naming_index_convention.goindex 57c4ea0214..89dad65d85 100644--- a/backend/plugin/advisor/pg/advisor_naming_index_convention.go+++ b/backend/plugin/advisor/pg/advisor_naming_index_convention.go@@ -4,6 +4,8 @@ import ("fmt""strings"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -24,10 +26,10 @@ type NamingIndexConventionAdvisor struct {}// Check checks for index naming convention.-func (*NamingIndexConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingIndexConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.goindex ecf71842b0..e41b36e8dd 100644--- a/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go+++ b/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go@@ -4,6 +4,8 @@ import ("fmt""strings"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -24,10 +26,10 @@ type NamingPKConventionAdvisor struct {}// Check checks for index naming convention.-func (*NamingPKConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingPKConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_naming_table.go b/backend/plugin/advisor/pg/advisor_naming_table.goindex 7ff93949e5..a629ea7950 100644--- a/backend/plugin/advisor/pg/advisor_naming_table.go+++ b/backend/plugin/advisor/pg/advisor_naming_table.go@@ -4,6 +4,8 @@ import ("fmt""regexp"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -23,10 +25,10 @@ type NamingTableConventionAdvisor struct {}// Check checks for table naming convention.-func (*NamingTableConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingTableConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.goindex 83474b9c34..95b6e13e23 100644--- a/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go+++ b/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go@@ -4,6 +4,8 @@ import ("fmt""strings"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -24,10 +26,10 @@ type NamingUKConventionAdvisor struct {}// Check checks for unique key naming convention.-func (*NamingUKConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- root, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingUKConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ root, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_statement_add_check_not_valid.go b/backend/plugin/advisor/pg/advisor_statement_add_check_not_valid.goindex 6a87da72a3..0f31d7c260 100644--- a/backend/plugin/advisor/pg/advisor_statement_add_check_not_valid.go+++ b/backend/plugin/advisor/pg/advisor_statement_add_check_not_valid.go@@ -3,6 +3,8 @@ package pg// Framework code is generated by the generator.import (+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -22,10 +24,10 @@ type StatementAddCheckNotValidAdvisor struct {}// Check checks for to add check not valid.-func (*StatementAddCheckNotValidAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*StatementAddCheckNotValidAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.go b/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.goindex f37acb8466..b33b80aac1 100644--- a/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.go+++ b/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.go@@ -7,6 +7,8 @@ import ("database/sql""fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -26,10 +28,10 @@ type StatementAffectedRowLimitAdvisor struct {}// Check checks for UPDATE/DELETE affected row limit.-func (*StatementAffectedRowLimitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*StatementAffectedRowLimitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_add_column_with_default.go b/backend/plugin/advisor/pg/advisor_statement_disallow_add_column_with_default.goindex e5cbfe5771..6e4fe5c65a 100644--- a/backend/plugin/advisor/pg/advisor_statement_disallow_add_column_with_default.go+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_add_column_with_default.go@@ -3,6 +3,8 @@ package pg// Framework code is generated by the generator.import (+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -22,10 +24,10 @@ type StatementDisallowAddColumnWithDefaultAdvisor struct {}// Check checks for to disallow add column with default.-func (*StatementDisallowAddColumnWithDefaultAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*StatementDisallowAddColumnWithDefaultAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_add_not_null.go b/backend/plugin/advisor/pg/advisor_statement_disallow_add_not_null.goindex ad6d1da536..8dce33fc42 100644--- a/backend/plugin/advisor/pg/advisor_statement_disallow_add_not_null.go+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_add_not_null.go@@ -5,6 +5,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -24,10 +26,10 @@ type StatementDisallowAddNotNullAdvisor struct {}// Check checks for to disallow add not null.-func (*StatementDisallowAddNotNullAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*StatementDisallowAddNotNullAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_commit.go b/backend/plugin/advisor/pg/advisor_statement_disallow_commit.goindex 1e939fbbf5..724b686a9d 100644--- a/backend/plugin/advisor/pg/advisor_statement_disallow_commit.go+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_commit.go@@ -5,6 +5,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -24,10 +26,10 @@ type StatementDisallowCommitAdvisor struct {}// Check checks for to disallow commit.-func (*StatementDisallowCommitAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*StatementDisallowCommitAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.go b/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.goindex fee616d712..2a07111fa7 100644--- a/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.go+++ b/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.go@@ -7,6 +7,8 @@ import ("database/sql""fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -26,10 +28,10 @@ type StatementDmlDryRunAdvisor struct {}// Check checks for DML dry run.-func (*StatementDmlDryRunAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*StatementDmlDryRunAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.go b/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.goindex 919c15bb2d..e9f3ea96e6 100644--- a/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.go+++ b/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.go@@ -6,6 +6,8 @@ import ("fmt""sort"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -25,10 +27,10 @@ type StatementMergeAlterTableAdvisor struct {}// Check checks for no redundant ALTER TABLE statements.-func (*StatementMergeAlterTableAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*StatementMergeAlterTableAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go b/backend/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.goindex 6d56d7c8fb..f793764c54 100644--- a/backend/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go+++ b/backend/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go@@ -3,6 +3,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -26,10 +28,10 @@ type NoLeadingWildcardLikeAdvisor struct {}// Check checks for no leading wildcard LIKE.-func (*NoLeadingWildcardLikeAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NoLeadingWildcardLikeAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_stmt_no_select_all.go b/backend/plugin/advisor/pg/advisor_stmt_no_select_all.goindex 5343030461..ac4658e946 100644--- a/backend/plugin/advisor/pg/advisor_stmt_no_select_all.go+++ b/backend/plugin/advisor/pg/advisor_stmt_no_select_all.go@@ -3,6 +3,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -22,10 +24,10 @@ type NoSelectAllAdvisor struct {}// Check checks for no "select *".-func (*NoSelectAllAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NoSelectAllAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_stmt_where_required.go b/backend/plugin/advisor/pg/advisor_stmt_where_required.goindex f8cfc62d50..b13fa7b1bd 100644--- a/backend/plugin/advisor/pg/advisor_stmt_where_required.go+++ b/backend/plugin/advisor/pg/advisor_stmt_where_required.go@@ -3,6 +3,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -22,10 +24,10 @@ type WhereRequirementAdvisor struct {}// Check checks for the WHERE clause requirement.-func (*WhereRequirementAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*WhereRequirementAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_syntax.go b/backend/plugin/advisor/pg/advisor_syntax.godeleted file mode 100644index 3d3525245d..0000000000--- a/backend/plugin/advisor/pg/advisor_syntax.go+++ /dev/null@@ -1,45 +0,0 @@-package pg--import (- "github.com/bytebase/bytebase/backend/plugin/advisor"- "github.com/bytebase/bytebase/backend/plugin/advisor/db"-)--var (- _ advisor.Advisor = (*SyntaxAdvisor)(nil)-)--func init() {- advisor.Register(db.Postgres, advisor.PostgreSQLSyntax, &SyntaxAdvisor{})-}--// SyntaxAdvisor is the advisor for checking syntax.-type SyntaxAdvisor struct {-}--// Check parses the given statement and checks for errors.-func (*SyntaxAdvisor) Check(_ advisor.Context, statement string) ([]advisor.Advice, error) {- var res []advisor.Advice- if _, errAdvice := parseStatement(statement); errAdvice != nil {- for _, advice := range errAdvice {- // Here is to filter parser.ConvertError.- // The reason for this is to remove potential conversion errors from the syntax check.- // Syntax check doesn't actually require the transformed AST either.- // TODO(rebelice): remove it when conversion function is complete.- if advice.Code == advisor.StatementSyntaxError {- res = append(res, advice)- }- }- }-- if len(res) == 0 {- res = append(res, advisor.Advice{- Status: advisor.Success,- Code: advisor.Ok,- Title: "Syntax OK",- Content: "OK",- })- }-- return res, nil-}diff --git a/backend/plugin/advisor/pg/advisor_syntax_test.go b/backend/plugin/advisor/pg/advisor_syntax_test.godeleted file mode 100644index 3de0c6023a..0000000000--- a/backend/plugin/advisor/pg/advisor_syntax_test.go+++ /dev/null@@ -1,48 +0,0 @@-package pg--import (- "testing"-- "github.com/stretchr/testify/assert"- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/backend/plugin/advisor"-- _ "github.com/bytebase/bytebase/backend/plugin/parser/sql/engine/pg"-)--func TestPostgreSQLSyntax(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "CREATE TABLE book(id int);",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "Syntax OK",- Content: "OK",- },- },- },- {- Statement: "CREATE TABLE book(id int) ENGINE=INNODB;",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.StatementSyntaxError,- Title: "Syntax error",- Content: "syntax error at or near \"ENGINE\"",- Line: 1,- },- },- },- }-- adv := &SyntaxAdvisor{}-- for _, tc := range tests {- adviceList, err := adv.Check(advisor.Context{}, tc.Statement)- require.NoError(t, err)- assert.Equal(t, tc.Want, adviceList)- }-}diff --git a/backend/plugin/advisor/pg/advisor_table_disallow_partition.go b/backend/plugin/advisor/pg/advisor_table_disallow_partition.goindex 47daf88994..1e8d7b274c 100644--- a/backend/plugin/advisor/pg/advisor_table_disallow_partition.go+++ b/backend/plugin/advisor/pg/advisor_table_disallow_partition.go@@ -5,6 +5,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -24,10 +26,10 @@ type TableDisallowPartitionAdvisor struct {}// Check checks for disallow table partition.-func (*TableDisallowPartitionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*TableDisallowPartitionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.goindex 9075b6c01b..5589fa35ec 100644--- a/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.go+++ b/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.go@@ -6,6 +6,8 @@ import ("fmt""regexp"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -25,10 +27,10 @@ type TableDropNamingConventionAdvisor struct {}// Check checks for table drop with naming convention.-func (*TableDropNamingConventionAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmtList, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*TableDropNamingConventionAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmtList, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_table_no_fk.go b/backend/plugin/advisor/pg/advisor_table_no_fk.goindex 9acc6cda74..b3ba8b9a6b 100644--- a/backend/plugin/advisor/pg/advisor_table_no_fk.go+++ b/backend/plugin/advisor/pg/advisor_table_no_fk.go@@ -3,6 +3,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -22,10 +24,10 @@ type TableNoFKAdvisor struct {}// Check checks table disallow foreign key.-func (*TableNoFKAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*TableNoFKAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/advisor_table_require_pk.go b/backend/plugin/advisor/pg/advisor_table_require_pk.goindex cd2bf42ea8..86d34f8008 100644--- a/backend/plugin/advisor/pg/advisor_table_require_pk.go+++ b/backend/plugin/advisor/pg/advisor_table_require_pk.go@@ -3,6 +3,8 @@ package pgimport ("fmt"+ "github.com/pkg/errors"+"github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -23,10 +25,10 @@ type TableRequirePKAdvisor struct {}// Check parses the given statement and checks for errors.-func (*TableRequirePKAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- stmts, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*TableRequirePKAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ stmts, ok := ctx.AST.([]ast.Node)+ if !ok {+ return nil, errors.Errorf("failed to convert to Node")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/pg/parser.go b/backend/plugin/advisor/pg/parser.godeleted file mode 100644index f02996071b..0000000000--- a/backend/plugin/advisor/pg/parser.go+++ /dev/null@@ -1,56 +0,0 @@-package pg--import (- "github.com/bytebase/bytebase/backend/plugin/advisor"- parser "github.com/bytebase/bytebase/backend/plugin/parser/sql"- "github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"-)--func parseStatement(statement string) ([]ast.Node, []advisor.Advice) {- nodes, err := parser.Parse(parser.Postgres, parser.ParseContext{}, statement)- if err != nil {- if _, ok := err.(*parser.ConvertError); ok {- return nil, []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.Internal,- Title: "Parser conversion error",- Content: err.Error(),- Line: calculateErrorLine(statement),- },- }- }- return nil, []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.StatementSyntaxError,- Title: advisor.SyntaxErrorTitle,- Content: err.Error(),- Line: calculateErrorLine(statement),- },- }- }- var res []ast.Node- for _, node := range nodes {- if node != nil {- res = append(res, node)- }- }- return res, nil-}--func calculateErrorLine(statement string) int {- statementList, err := parser.SplitMultiSQL(parser.Postgres, statement)- if err != nil {- // nolint:nilerr- return 1- }-- for _, stmt := range statementList {- if _, err := parser.Parse(parser.Postgres, parser.ParseContext{}, stmt.Text); err != nil {- return stmt.LastLine- }- }-- return 0-}diff --git a/backend/plugin/advisor/snowflake/advisor_column_maximum_varchar_length.go b/backend/plugin/advisor/snowflake/advisor_column_maximum_varchar_length.goindex 04957a79e5..2ea1386d68 100644--- a/backend/plugin/advisor/snowflake/advisor_column_maximum_varchar_length.go+++ b/backend/plugin/advisor/snowflake/advisor_column_maximum_varchar_length.go@@ -7,6 +7,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -31,10 +32,10 @@ type ColumnMaximumVarcharLengthAdvisor struct {}// Check checks for maximum varchar length.-func (*ColumnMaximumVarcharLengthAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnMaximumVarcharLengthAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/snowflake/advisor_column_no_null.go b/backend/plugin/advisor/snowflake/advisor_column_no_null.goindex b6a4d4be52..5f473dd850 100644--- a/backend/plugin/advisor/snowflake/advisor_column_no_null.go+++ b/backend/plugin/advisor/snowflake/advisor_column_no_null.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"+ "github.com/pkg/errors"snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/sql"@@ -26,10 +27,10 @@ type ColumnNoNullAdvisor struct {}// Check checks for column no NULL value.-func (*ColumnNoNullAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnNoNullAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/snowflake/advisor_column_require.go b/backend/plugin/advisor/snowflake/advisor_column_require.goindex d56e50519a..05c41137f2 100644--- a/backend/plugin/advisor/snowflake/advisor_column_require.go+++ b/backend/plugin/advisor/snowflake/advisor_column_require.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"+ "github.com/pkg/errors""golang.org/x/exp/slices""github.com/bytebase/bytebase/backend/plugin/advisor"@@ -26,10 +27,10 @@ type ColumnRequireAdvisor struct {}// Check checks for column requirement.-func (*ColumnRequireAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*ColumnRequireAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/snowflake/advisor_naming_identifier_case.go b/backend/plugin/advisor/snowflake/advisor_naming_identifier_case.goindex 578924cc7b..4dc4849064 100644--- a/backend/plugin/advisor/snowflake/advisor_naming_identifier_case.go+++ b/backend/plugin/advisor/snowflake/advisor_naming_identifier_case.go@@ -7,6 +7,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -26,10 +27,10 @@ type NamingIdentifierCaseAdvisor struct {}// Check checks for identifier case.-func (*NamingIdentifierCaseAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingIdentifierCaseAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/snowflake/advisor_naming_identifier_no_keyword.go b/backend/plugin/advisor/snowflake/advisor_naming_identifier_no_keyword.goindex 3c05404671..e43b5b1213 100644--- a/backend/plugin/advisor/snowflake/advisor_naming_identifier_no_keyword.go+++ b/backend/plugin/advisor/snowflake/advisor_naming_identifier_no_keyword.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type NamingIdentifierNoKeywordAdvisor struct {}// Check checks for identifier naming convention without keyword.-func (*NamingIdentifierNoKeywordAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingIdentifierNoKeywordAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/snowflake/advisor_naming_table.go b/backend/plugin/advisor/snowflake/advisor_naming_table.goindex 77721a2ae9..b9c5fabebb 100644--- a/backend/plugin/advisor/snowflake/advisor_naming_table.go+++ b/backend/plugin/advisor/snowflake/advisor_naming_table.go@@ -8,6 +8,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"+ "github.com/pkg/errors""go.uber.org/zap""github.com/bytebase/bytebase/backend/common/log"@@ -28,10 +29,10 @@ type NamingTableAdvisor struct {}// Check checks for table naming convention.-func (*NamingTableAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingTableAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/snowflake/advisor_naming_table_no_keyword.go b/backend/plugin/advisor/snowflake/advisor_naming_table_no_keyword.goindex 75a886deaa..750f8254e8 100644--- a/backend/plugin/advisor/snowflake/advisor_naming_table_no_keyword.go+++ b/backend/plugin/advisor/snowflake/advisor_naming_table_no_keyword.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type NamingTableNoKeywordAdvisor struct {}// Check checks for table naming convention without keyword.-func (*NamingTableNoKeywordAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*NamingTableNoKeywordAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/snowflake/advisor_syntax.go b/backend/plugin/advisor/snowflake/advisor_syntax.godeleted file mode 100644index d834c75da3..0000000000--- a/backend/plugin/advisor/snowflake/advisor_syntax.go+++ /dev/null@@ -1,33 +0,0 @@-// Package snowflake is the advisor for Snowflake database.-package snowflake--import (- "github.com/bytebase/bytebase/backend/plugin/advisor"- "github.com/bytebase/bytebase/backend/plugin/advisor/db"-)--var (- _ advisor.Advisor = (*SyntaxAdvisor)(nil)-)--func init() {- advisor.Register(db.Snowflake, advisor.SnowflakeSyntax, &SyntaxAdvisor{})-}--// SyntaxAdvisor is the advisor checking for syntax.-type SyntaxAdvisor struct {-}--// Check checks for syntax.-func (*SyntaxAdvisor) Check(_ advisor.Context, statement string) ([]advisor.Advice, error) {- if _, errAdvice := parseStatement(statement); errAdvice != nil {- return errAdvice, nil- }-- return []advisor.Advice{{- Status: advisor.Success,- Code: advisor.Ok,- Title: "Syntax OK",- Content: "OK",- }}, nil-}diff --git a/backend/plugin/advisor/snowflake/advisor_table_no_foreign_key.go b/backend/plugin/advisor/snowflake/advisor_table_no_foreign_key.goindex 42800c3ed3..aff63ad4f5 100644--- a/backend/plugin/advisor/snowflake/advisor_table_no_foreign_key.go+++ b/backend/plugin/advisor/snowflake/advisor_table_no_foreign_key.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type TableNoForeignKeyAdvisor struct {}// Check checks for table disallow foreign key.-func (*TableNoForeignKeyAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*TableNoForeignKeyAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/snowflake/advisor_table_require_pk.go b/backend/plugin/advisor/snowflake/advisor_table_require_pk.goindex 9cc30225dd..3c265a405e 100644--- a/backend/plugin/advisor/snowflake/advisor_table_require_pk.go+++ b/backend/plugin/advisor/snowflake/advisor_table_require_pk.go@@ -6,6 +6,7 @@ import ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -25,10 +26,10 @@ type TableRequirePkAdvisor struct {}// Check checks for table require primary key.-func (*TableRequirePkAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*TableRequirePkAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/snowflake/advisor_where_require.go b/backend/plugin/advisor/snowflake/advisor_where_require.goindex 0fdc9f714c..2c8c7325ae 100644--- a/backend/plugin/advisor/snowflake/advisor_where_require.go+++ b/backend/plugin/advisor/snowflake/advisor_where_require.go@@ -4,6 +4,7 @@ package snowflakeimport ("github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"@@ -22,10 +23,10 @@ type WhereRequireAdvisor struct {}// Check checks for WHERE clause requirement.-func (*WhereRequireAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {- tree, errAdvice := parseStatement(statement)- if errAdvice != nil {- return errAdvice, nil+func (*WhereRequireAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {+ tree, ok := ctx.AST.(antlr.Tree)+ if !ok {+ return nil, errors.Errorf("failed to convert to Tree")}level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)diff --git a/backend/plugin/advisor/snowflake/parser.go b/backend/plugin/advisor/snowflake/parser.godeleted file mode 100644index 84eb6602e8..0000000000--- a/backend/plugin/advisor/snowflake/parser.go+++ /dev/null@@ -1,37 +0,0 @@-// Package snowflake is the advisor for snowflake database.-package snowflake--import (- "github.com/antlr4-go/antlr/v4"-- "github.com/bytebase/bytebase/backend/plugin/advisor"- parser "github.com/bytebase/bytebase/backend/plugin/parser/sql"-)--func parseStatement(statement string) (antlr.Tree, []advisor.Advice) {- tree, err := parser.ParseSnowSQL(statement + ";")- if err != nil {- if syntaxErr, ok := err.(*parser.SyntaxError); ok {- return nil, []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementSyntaxError,- Title: advisor.SyntaxErrorTitle,- Content: syntaxErr.Message,- Line: syntaxErr.Line,- },- }- }- return nil, []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.Internal,- Title: "Parse error",- Content: err.Error(),- Line: 1,- },- }- }-- return tree, nil-}diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.goindex 2cf18f7f29..c0897c2a05 100644--- a/backend/plugin/advisor/sql_review.go+++ b/backend/plugin/advisor/sql_review.go@@ -13,9 +13,17 @@ import ("github.com/pkg/errors""go.uber.org/zap"+ tidbparser "github.com/pingcap/tidb/parser"+ tidbast "github.com/pingcap/tidb/parser/ast"+"github.com/bytebase/bytebase/backend/common/log""github.com/bytebase/bytebase/backend/plugin/advisor/catalog""github.com/bytebase/bytebase/backend/plugin/advisor/db"+ parser "github.com/bytebase/bytebase/backend/plugin/parser/sql"+ "github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"++ // register pg parser.+ _ "github.com/bytebase/bytebase/backend/plugin/parser/sql/engine/pg")// How to add a SQL review rule:@@ -472,9 +480,221 @@ type SQLReviewCheckContext struct {CurrentSchema string}+func syntaxCheck(statement string, checkContext SQLReviewCheckContext) (any, []Advice) {+ switch checkContext.DbType {+ case db.MySQL, db.MariaDB, db.OceanBase, db.TiDB:+ return mysqlSyntaxCheck(statement)+ case db.Postgres:+ return postgresSyntaxCheck(statement)+ case db.Oracle:+ return oracleSyntaxCheck(statement)+ case db.Snowflake:+ return snowflakeSyntaxCheck(statement)+ }+ return nil, []Advice{+ {+ Status: Error,+ Code: Unsupported,+ Title: "Unsupported database type",+ Content: fmt.Sprintf("Unsupported database type %s", checkContext.DbType),+ Line: 1,+ },+ }+}++func snowflakeSyntaxCheck(statement string) (any, []Advice) {+ tree, err := parser.ParseSnowSQL(statement + ";")+ if err != nil {+ if syntaxErr, ok := err.(*parser.SyntaxError); ok {+ return nil, []Advice{+ {+ Status: Warn,+ Code: StatementSyntaxError,+ Title: SyntaxErrorTitle,+ Content: syntaxErr.Message,+ Line: syntaxErr.Line,+ },+ }+ }+ return nil, []Advice{+ {+ Status: Warn,+ Code: Internal,+ Title: "Parse error",+ Content: err.Error(),+ Line: 1,+ },+ }+ }++ return tree, nil+}++func oracleSyntaxCheck(statement string) (any, []Advice) {+ tree, err := parser.ParsePLSQL(statement + ";")+ if err != nil {+ if syntaxErr, ok := err.(*parser.SyntaxError); ok {+ return nil, []Advice{+ {+ Status: Warn,+ Code: StatementSyntaxError,+ Title: SyntaxErrorTitle,+ Content: syntaxErr.Message,+ Line: syntaxErr.Line,+ },+ }+ }+ return nil, []Advice{+ {+ Status: Warn,+ Code: Internal,+ Title: "Parse error",+ Content: err.Error(),+ Line: 1,+ },+ }+ }++ return tree, nil+}++func postgresSyntaxCheck(statement string) (any, []Advice) {+ nodes, err := parser.Parse(parser.Postgres, parser.ParseContext{}, statement)+ if err != nil {+ if _, ok := err.(*parser.ConvertError); ok {+ return nil, []Advice{+ {+ Status: Error,+ Code: Internal,+ Title: "Parser conversion error",+ Content: err.Error(),+ Line: calculatePostgresErrorLine(statement),+ },+ }+ }+ return nil, []Advice{+ {+ Status: Error,+ Code: StatementSyntaxError,+ Title: SyntaxErrorTitle,+ Content: err.Error(),+ Line: calculatePostgresErrorLine(statement),+ },+ }+ }+ var res []ast.Node+ for _, node := range nodes {+ if node != nil {+ res = append(res, node)+ }+ }+ return res, nil+}++func calculatePostgresErrorLine(statement string) int {+ statementList, err := parser.SplitMultiSQL(parser.Postgres, statement)+ if err != nil {+ // nolint:nilerr+ return 1+ }++ for _, stmt := range statementList {+ if _, err := parser.Parse(parser.Postgres, parser.ParseContext{}, stmt.Text); err != nil {+ return stmt.LastLine+ }+ }++ return 0+}++func newTiDBParser() *tidbparser.Parser {+ p := tidbparser.New()++ // To support MySQL8 window function syntax.+ // See https://github.com/bytebase/bytebase/issues/175.+ p.EnableWindowFunc(true)++ return p+}++func mysqlSyntaxCheck(statement string) (any, []Advice) {+ list, err := parser.SplitMySQL(statement)+ if err != nil {+ return nil, []Advice{+ {+ Status: Warn,+ Code: Internal,+ Title: "Syntax error",+ Content: err.Error(),+ Line: 1,+ },+ }+ }++ p := newTiDBParser()+ var returnNodes []tidbast.StmtNode+ var adviceList []Advice+ for _, item := range list {+ nodes, _, err := p.Parse(item.Text, "", "")+ if err != nil {+ // TiDB parser doesn't fully support MySQL syntax, so we need to use MySQL parser to parse the statement.+ // But MySQL parser has some performance issue, so we only use it to parse the statement after TiDB parser failed.+ if _, err := parser.ParseMySQL(item.Text); err != nil {+ if syntaxErr, ok := err.(*parser.SyntaxError); ok {+ return nil, []Advice{+ {+ Status: Error,+ Code: StatementSyntaxError,+ Title: SyntaxErrorTitle,+ Content: syntaxErr.Message,+ Line: syntaxErr.Line,+ },+ }+ }+ return nil, []Advice{+ {+ Status: Warn,+ Code: Internal,+ Title: "Parse error",+ Content: err.Error(),+ Line: 1,+ },+ }+ }+ // If MySQL parser can parse the statement, but TiDB parser can't, we just ignore the statement.+ continue+ }++ if len(nodes) != 1 {+ continue+ }++ node := nodes[0]+ node.SetText(nil, item.Text)+ node.SetOriginTextPosition(item.LastLine)+ if n, ok := node.(*tidbast.CreateTableStmt); ok {+ if err := parser.SetLineForMySQLCreateTableStmt(n); err != nil {+ return nil, append(adviceList, Advice{+ Status: Error,+ Code: Internal,+ Title: "Set line error",+ Content: err.Error(),+ Line: item.LastLine,+ })+ }+ }+ returnNodes = append(returnNodes, node)+ }++ return returnNodes, adviceList+}+// SQLReviewCheck checks the statements with sql review rules.func SQLReviewCheck(statements string, ruleList []*SQLReviewRule, checkContext SQLReviewCheckContext) ([]Advice, error) {- var result []Advice+ ast, result := syntaxCheck(statements, checkContext)+ if ast == nil || len(ruleList) == 0 {+ return result, nil+ }finder := checkContext.Catalog.GetFinder()switch checkContext.DbType {@@ -506,6 +726,7 @@ func SQLReviewCheck(statements string, ruleList []*SQLReviewRule, checkContext SContext{Charset: checkContext.Charset,Collation: checkContext.Collation,+ AST: ast,Rule: rule,Catalog: finder,Driver: checkContext.Driver,diff --git a/backend/runner/taskcheck/scheduler.go b/backend/runner/taskcheck/scheduler.goindex f3d6236894..1e3feb4748 100644--- a/backend/runner/taskcheck/scheduler.go+++ b/backend/runner/taskcheck/scheduler.go@@ -269,14 +269,6 @@ func (s *Scheduler) getTaskCheck(ctx context.Context, task *store.TaskMessage, creturn nil, errors.Errorf("instance %q not found", database.InstanceID)}- create, err = getSyntaxCheckTaskCheck(task, instance)- if err != nil {- return nil, errors.Wrap(err, "failed to schedule syntax check task check")- }- if create != nil {- createList = append(createList, create...)- }-create, err = s.getSQLReviewTaskCheck(task, instance)if err != nil {return nil, errors.Wrap(err, "failed to schedule SQL review task check")@@ -347,19 +339,6 @@ func (*Scheduler) getSQLReviewTaskCheck(task *store.TaskMessage, instance *store}, nil}-func getSyntaxCheckTaskCheck(task *store.TaskMessage, instance *store.InstanceMessage) ([]*store.TaskCheckRunMessage, error) {- if !api.IsSyntaxCheckSupported(instance.Engine) {- return nil, nil- }- return []*store.TaskCheckRunMessage{- {- CreatorID: api.SystemBotID,- TaskID: task.ID,- Type: api.TaskCheckDatabaseStatementSyntax,- },- }, nil-}-func (*Scheduler) getGeneralTaskCheck(task *store.TaskMessage, creatorID int) ([]*store.TaskCheckRunMessage, error) {return []*store.TaskCheckRunMessage{{diff --git a/backend/runner/taskcheck/statement_advisor_composite_executor.go b/backend/runner/taskcheck/statement_advisor_composite_executor.goindex af96b4cc9e..f91f68ebcc 100644--- a/backend/runner/taskcheck/statement_advisor_composite_executor.go+++ b/backend/runner/taskcheck/statement_advisor_composite_executor.go@@ -118,17 +118,13 @@ func (e *StatementAdvisorCompositeExecutor) Run(ctx context.Context, taskCheckRupolicy, err := e.store.GetSQLReviewPolicy(ctx, environment.UID)if err != nil {if e, ok := err.(*common.Error); ok && e.Code == common.NotFound {- return []api.TaskCheckResult{- {- Status: api.TaskCheckStatusSuccess,- Namespace: api.AdvisorNamespace,- Code: common.Ok.Int(),- Title: "Empty SQL review policy or disabled",- Content: "",- },- }, nil+ policy = &advisor.SQLReviewPolicy{+ Name: "Default",+ RuleList: []*advisor.SQLReviewRule{},+ }+ } else {+ return nil, common.Wrapf(err, common.Internal, "failed to get SQL review policy")}- return nil, common.Wrapf(err, common.Internal, "failed to get SQL review policy")}catalog, err := e.store.NewCatalog(ctx, *task.DatabaseID, instance.Engine, task.GetSyntaxMode())diff --git a/backend/runner/taskcheck/statement_advisor_simple_executor.go b/backend/runner/taskcheck/statement_advisor_simple_executor.godeleted file mode 100644index 052a4b4dc7..0000000000--- a/backend/runner/taskcheck/statement_advisor_simple_executor.go+++ /dev/null@@ -1,162 +0,0 @@-package taskcheck--import (- "context"- "encoding/json"- "fmt"-- "github.com/pkg/errors"-- "github.com/bytebase/bytebase/backend/common"- enterpriseAPI "github.com/bytebase/bytebase/backend/enterprise/api"- api "github.com/bytebase/bytebase/backend/legacyapi"- "github.com/bytebase/bytebase/backend/plugin/advisor"- advisorDB "github.com/bytebase/bytebase/backend/plugin/advisor/db"- "github.com/bytebase/bytebase/backend/plugin/db"- "github.com/bytebase/bytebase/backend/store"- "github.com/bytebase/bytebase/backend/utils"-)--// NewStatementAdvisorSimpleExecutor creates a task check statement simple advisor executor.-func NewStatementAdvisorSimpleExecutor(store *store.Store, licenseService enterpriseAPI.LicenseService) Executor {- return &StatementAdvisorSimpleExecutor{- store: store,- licenseService: licenseService,- }-}--// StatementAdvisorSimpleExecutor is the task check statement advisor simple executor.-type StatementAdvisorSimpleExecutor struct {- store *store.Store- licenseService enterpriseAPI.LicenseService-}--// Run will run the task check statement advisor executor once.-func (e *StatementAdvisorSimpleExecutor) Run(ctx context.Context, taskCheckRun *store.TaskCheckRunMessage, task *store.TaskMessage) (result []api.TaskCheckResult, err error) {- instance, err := e.store.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: &task.InstanceID})- if err != nil {- return nil, err- }- if instance == nil {- return nil, errors.Errorf("instance %q not found", task.InstanceID)- }- if err := e.licenseService.IsFeatureEnabledForInstance(api.FeatureSQLReview, instance); err != nil {- // nolint:nilerr- return []api.TaskCheckResult{- {- Status: api.TaskCheckStatusWarn,- Namespace: api.AdvisorNamespace,- Code: advisor.Unsupported.Int(),- Title: fmt.Sprintf("SQL review disabled for instance %s", instance.ResourceID),- Content: err.Error(),- },- }, nil- }-- database, err := e.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{UID: task.DatabaseID})- if err != nil {- return nil, err- }- if database == nil {- return nil, errors.Errorf("database %v not found", task.DatabaseID)- }-- dbSchema, err := e.store.GetDBSchema(ctx, database.UID)- if err != nil {- return nil, err- }- payload := &TaskPayload{}- if err := json.Unmarshal([]byte(task.Payload), payload); err != nil {- return nil, err- }-- sheet, err := e.store.GetSheetV2(ctx, &store.FindSheetMessage{UID: &payload.SheetID}, api.SystemBotID)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet %d", payload.SheetID)- }- if sheet == nil {- return nil, errors.Errorf("sheet %d not found", payload.SheetID)- }- if sheet.Size > common.MaxSheetSizeForTaskCheck {- return []api.TaskCheckResult{- {- Status: api.TaskCheckStatusSuccess,- Namespace: api.AdvisorNamespace,- Code: common.Ok.Int(),- Title: "Large SQL review policy is disabled",- Content: "",- },- }, nil- }- statement, err := e.store.GetSheetStatementByID(ctx, payload.SheetID)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet statement %d", payload.SheetID)- }-- var advisorType advisor.Type- switch taskCheckRun.Type {- case api.TaskCheckDatabaseStatementFakeAdvise:- advisorType = advisor.Fake- case api.TaskCheckDatabaseStatementSyntax:- switch instance.Engine {- case db.MySQL, db.TiDB, db.MariaDB, db.OceanBase:- advisorType = advisor.MySQLSyntax- case db.Postgres:- advisorType = advisor.PostgreSQLSyntax- case db.Oracle:- advisorType = advisor.OracleSyntax- case db.Snowflake:- advisorType = advisor.SnowflakeSyntax- default:- return nil, common.Errorf(common.Invalid, "invalid database type: %s for syntax statement advisor", instance.Engine)- }- }-- dbType, err := advisorDB.ConvertToAdvisorDBType(string(instance.Engine))- if err != nil {- return nil, err- }-- materials := utils.GetSecretMapFromDatabaseMessage(database)- // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.- renderedStatement := utils.RenderStatement(statement, materials)-- adviceList, err := advisor.Check(- dbType,- advisorType,- advisor.Context{- Charset: dbSchema.Metadata.CharacterSet,- Collation: dbSchema.Metadata.Collation,- SyntaxMode: task.GetSyntaxMode(),- },- renderedStatement,- )- if err != nil {- return nil, common.Wrapf(err, common.Internal, "failed to check statement")- }-- result = []api.TaskCheckResult{}- for _, advice := range adviceList {- status := api.TaskCheckStatusSuccess- switch advice.Status {- case advisor.Success:- status = api.TaskCheckStatusSuccess- case advisor.Warn:- status = api.TaskCheckStatusWarn- case advisor.Error:- status = api.TaskCheckStatusError- }-- result = append(result, api.TaskCheckResult{- Status: status,- Namespace: api.AdvisorNamespace,- Code: advice.Code.Int(),- Title: advice.Title,- Content: advice.Content,- Line: advice.Line,- Details: advice.Details,- })- }-- return result, nil-}diff --git a/backend/runner/taskrun/scheduler.go b/backend/runner/taskrun/scheduler.goindex 11c8ee1bec..8bccbe79a7 100644--- a/backend/runner/taskrun/scheduler.go+++ b/backend/runner/taskrun/scheduler.go@@ -443,20 +443,6 @@ func (s *Scheduler) PatchTask(ctx context.Context, task *store.TaskMessage, taskif err != nil {return err}- if api.IsSyntaxCheckSupported(instance.Engine) {- if err := s.store.CreateTaskCheckRun(ctx, &store.TaskCheckRunMessage{- CreatorID: taskPatched.CreatorID,- TaskID: task.ID,- Type: api.TaskCheckDatabaseStatementSyntax,- }); err != nil {- // It's OK if we failed to trigger a check, just emit an error log- log.Error("Failed to trigger syntax check after changing the task statement",- zap.Int("task_id", task.ID),- zap.String("task_name", task.Name),- zap.Error(err),- )- }- }if api.IsSQLReviewSupported(instance.Engine) {if err := s.triggerDatabaseStatementAdviseTask(ctx, taskPatched); err != nil {diff --git a/backend/server/server.go b/backend/server/server.goindex 0bb7e0a057..ded7514787 100644--- a/backend/server/server.go+++ b/backend/server/server.go@@ -455,9 +455,6 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {s.TaskScheduler.Register(api.TaskDatabaseRestorePITRCutover, taskrun.NewPITRCutoverExecutor(storeInstance, s.dbFactory, s.SchemaSyncer, s.BackupRunner, s.ActivityManager, profile))s.TaskCheckScheduler = taskcheck.NewScheduler(storeInstance, s.licenseService, s.stateCfg)- statementSimpleExecutor := taskcheck.NewStatementAdvisorSimpleExecutor(storeInstance, s.licenseService)- s.TaskCheckScheduler.Register(api.TaskCheckDatabaseStatementFakeAdvise, statementSimpleExecutor)- s.TaskCheckScheduler.Register(api.TaskCheckDatabaseStatementSyntax, statementSimpleExecutor)statementCompositeExecutor := taskcheck.NewStatementAdvisorCompositeExecutor(storeInstance, s.dbFactory, s.licenseService)s.TaskCheckScheduler.Register(api.TaskCheckDatabaseStatementAdvise, statementCompositeExecutor)statementTypeExecutor := taskcheck.NewStatementTypeExecutor(storeInstance, s.dbFactory)diff --git a/backend/tests/sql_review_test.go b/backend/tests/sql_review_test.goindex ca5014f7f9..1947087189 100644--- a/backend/tests/sql_review_test.go+++ b/backend/tests/sql_review_test.go@@ -38,9 +38,9 @@ var (noSQLReviewPolicy = []api.TaskCheckResult{{Status: api.TaskCheckStatusSuccess,- Namespace: api.AdvisorNamespace,+ Namespace: api.BBNamespace,Code: common.Ok.Int(),- Title: "Empty SQL review policy or disabled",+ Title: "OK",Content: "",},}diff --git a/backend/tests/test-data/sql_review_mysql.yaml b/backend/tests/test-data/sql_review_mysql.yamlindex 67b6538d5d..e1be421062 100644--- a/backend/tests/test-data/sql_review_mysql.yaml+++ b/backend/tests/test-data/sql_review_mysql.yaml@@ -15,7 +15,7 @@status: ERRORtitle: Syntax errorcontent: line 1:20 mismatched input ')' expecting {BIGINT_SYMBOL, BINARY_SYMBOL, BIT_SYMBOL, BLOB_SYMBOL, BOOLEAN_SYMBOL, BOOL_SYMBOL, CHAR_SYMBOL, DATETIME_SYMBOL, DATE_SYMBOL, DECIMAL_SYMBOL, DOUBLE_SYMBOL, ENUM_SYMBOL, FIXED_SYMBOL, FLOAT_SYMBOL, GEOMETRYCOLLECTION_SYMBOL, GEOMETRY_SYMBOL, INT_SYMBOL, JSON_SYMBOL, LINESTRING_SYMBOL, LONGBLOB_SYMBOL, LONGTEXT_SYMBOL, LONG_SYMBOL, MEDIUMBLOB_SYMBOL, MEDIUMINT_SYMBOL, MEDIUMTEXT_SYMBOL, MULTILINESTRING_SYMBOL, MULTIPOINT_SYMBOL, MULTIPOLYGON_SYMBOL, NATIONAL_SYMBOL, NCHAR_SYMBOL, NUMERIC_SYMBOL, NVARCHAR_SYMBOL, POINT_SYMBOL, POLYGON_SYMBOL, REAL_SYMBOL, SERIAL_SYMBOL, SET_SYMBOL, SMALLINT_SYMBOL, TEXT_SYMBOL, TIMESTAMP_SYMBOL, TIME_SYMBOL, TINYBLOB_SYMBOL, TINYINT_SYMBOL, TINYTEXT_SYMBOL, VARBINARY_SYMBOL, VARCHAR_SYMBOL, YEAR_SYMBOL}- line: 0+ line: 1details: ""run: false- statement: CREATE TABLE userTable(id INT NOT NULL,name VARCHAR(255) CHARSET ascii,roomId INT,time_created TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',time_updated TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',content BLOB NOT NULL COMMENT 'comment',json_content JSON NOT NULL COMMENT 'comment',INDEX idx1(name),UNIQUE KEY uk1(id, name),FOREIGN KEY fk1(roomId) REFERENCES room(id),INDEX idx_userTable_content(content)) ENGINE = CSV COLLATE latin1_bin@@ -96,21 +96,21 @@code: 401status: WARNtitle: column.required- content: 'Table `userTable` requires columns: created_ts, creator_id, updated_ts, updater_id'+ content: "Table `userTable` requires columns: created_ts, creator_id, updated_ts, updater_id"line: 2details: ""- namespace: bb.advisorcode: 402status: WARNtitle: column.no-null- content: '`userTable`.`name` cannot have NULL value'+ content: "`userTable`.`name` cannot have NULL value"line: 1details: ""- namespace: bb.advisorcode: 402status: WARNtitle: column.no-null- content: '`userTable`.`roomId` cannot have NULL value'+ content: "`userTable`.`roomId` cannot have NULL value"line: 1details: ""- namespace: bb.advisor@@ -224,7 +224,7 @@code: 401status: WARNtitle: column.required- content: 'Table `t_auto` requires columns: created_ts, creator_id, id, updated_ts, updater_id'+ content: "Table `t_auto` requires columns: created_ts, creator_id, id, updated_ts, updater_id"line: 2details: ""- namespace: bb.advisor@@ -249,7 +249,7 @@line: 1details: ""run: false-- statement: ' DELETE FROM tech_book'+- statement: " DELETE FROM tech_book"result:- namespace: bb.advisorcode: 202@@ -309,7 +309,7 @@line: 2details: ""run: false-- statement: ' INSERT INTO t_copy SELECT * FROM t'+- statement: " INSERT INTO t_copy SELECT * FROM t"result:- namespace: bb.advisorcode: 203@@ -357,7 +357,7 @@line: 2details: ""run: false-- statement: ' INSERT INTO t VALUES (1, 1, now(), 1, now())'+- statement: " INSERT INTO t VALUES (1, 1, now(), 1, now())"result:- namespace: bb.advisorcode: 208@@ -506,7 +506,7 @@line: 2details: ""run: false-- statement: ' ALTER TABLE user PARTITION BY HASH(id) PARTITIONS 8;'+- statement: " ALTER TABLE user PARTITION BY HASH(id) PARTITIONS 8;"result:- namespace: bb.advisorcode: 608@@ -558,7 +558,7 @@line: 1details: ""run: false-- statement: ' DROP TABLE user;'+- statement: " DROP TABLE user;"result:- namespace: bb.advisorcode: 603diff --git a/backend/tests/test-data/sql_review_pg.yaml b/backend/tests/test-data/sql_review_pg.yamlindex 76370a40e1..555cdc9dfa 100644--- a/backend/tests/test-data/sql_review_pg.yaml+++ b/backend/tests/test-data/sql_review_pg.yaml@@ -25,7 +25,7 @@status: ERRORtitle: Syntax errorcontent: syntax error at or near "user"- line: 0+ line: 1run: false- statement: |-CREATE TABLE "userTable"(diff --git a/backend/utils/utils.go b/backend/utils/utils.goindex 39e377dbda..4930f0175f 100644--- a/backend/utils/utils.go+++ b/backend/utils/utils.go@@ -410,16 +410,6 @@ func PassAllCheck(task *store.TaskMessage, allowedStatus api.TaskCheckStatus, tareturn false, nil}- if api.IsSyntaxCheckSupported(engine) {- ok, err := passCheck(runs, api.TaskCheckDatabaseStatementSyntax, allowedStatus)- if err != nil {- return false, err- }- if !ok {- return false, nil- }- }-if api.IsSQLReviewSupported(engine) {ok, err := passCheck(runs, api.TaskCheckDatabaseStatementAdvise, allowedStatus)if err != nil {