Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: bump omni to 431fd0df and adapt to its changes (#21613)
rebelice2c7f6f848b27
diff --git a/backend/generated-go/v1/review_rule.pb.go b/backend/generated-go/v1/review_rule.pb.goindex cd5b1c6b03..87945a6eec 100644--- a/backend/generated-go/v1/review_rule.pb.go+++ b/backend/generated-go/v1/review_rule.pb.go@@ -48,13 +48,15 @@ const (ReviewRuleType_REQUIRE_IS_NULL ReviewRuleType = 5// P1: UPDATE or DELETE without WHERE.ReviewRuleType_REQUIRE_WHERE ReviewRuleType = 6- // P1: DROP TABLE, COLUMN, SCHEMA, or DATABASE.+ // P1: dropping any object, such as a table, column, view, index, sequence,+ // schema, database, or function. Dropping a constraint is+ // DISALLOW_DROP_CONSTRAINT.ReviewRuleType_DISALLOW_DROP_OBJECT ReviewRuleType = 7// P1: TRUNCATE.ReviewRuleType_DISALLOW_TRUNCATE ReviewRuleType = 8// P1: dropping a PRIMARY KEY, FOREIGN KEY, UNIQUE, or CHECK constraint.ReviewRuleType_DISALLOW_DROP_CONSTRAINT ReviewRuleType = 9- // P1: renaming a table or column.+ // P1: renaming a table, foreign table, view, materialized view, or column.ReviewRuleType_DISALLOW_RENAME ReviewRuleType = 10// P1: the change creates a table without a primary key, or drops a// primary key without adding one back. A table that already lacked adiff --git a/backend/plugin/parser/cassandra/cassandra.go b/backend/plugin/parser/cassandra/cassandra.goindex 044cbf2616..72720ab612 100644--- a/backend/plugin/parser/cassandra/cassandra.go+++ b/backend/plugin/parser/cassandra/cassandra.go@@ -51,7 +51,7 @@ func convertOmniError(err error, stmt base.Statement) error {return err}- pos := byteOffsetToPosition(stmt.Text, parseErr.Loc.Start)+ pos := byteOffsetToPosition(stmt.Text, parseErr.Position)if stmt.Start != nil {if pos.Line == 1 {pos.Column += stmt.Start.Column - 1diff --git a/backend/plugin/parser/doris/doris.go b/backend/plugin/parser/doris/doris.goindex ac38f03259..7bd674f1f6 100644--- a/backend/plugin/parser/doris/doris.go+++ b/backend/plugin/parser/doris/doris.go@@ -1,6 +1,7 @@package dorisimport (+ "errors""strings""unicode/utf8"@@ -56,10 +57,9 @@ func parseDorisStatements(statement string) ([]base.ParsedStatement, error) {// Parse the segment text on its own so byte offsets in any ParseError// align with stmt.Text; convertParseError then shifts them into the// coordinates of the original multi-statement script.- file, errs := parser.Parse(stmt.Text)- if len(errs) > 0 {- pe := errs[0]- return nil, convertParseError(stmt.Text, &pe, stmt.Start)+ file, err := parser.Parse(stmt.Text)+ if err != nil {+ return nil, convertParseError(stmt.Text, err, stmt.Start)}var node ast.Nodeif file != nil && len(file.Stmts) > 0 {@@ -93,10 +93,9 @@ func parseDorisSQL(statement string) ([]*omniAST, error) {if stmt.Empty || strings.TrimSpace(stmt.Text) == "" {continue}- file, errs := parser.Parse(stmt.Text)- if len(errs) > 0 {- pe := errs[0]- return nil, convertParseError(stmt.Text, &pe, stmt.Start)+ file, err := parser.Parse(stmt.Text)+ if err != nil {+ return nil, convertParseError(stmt.Text, err, stmt.Start)}var node ast.Nodeif file != nil && len(file.Stmts) > 0 {@@ -110,17 +109,21 @@ func parseDorisSQL(statement string) ([]*omniAST, error) {return result, nil}-// convertParseError converts an omni *parser.ParseError to a-// *base.SyntaxError that sql_service.go recognises for structured-// error diagnostics. It converts the byte offset in ParseError.Loc+// convertParseError converts the first omni *parser.ParseError carried by err+// to a *base.SyntaxError that sql_service.go recognises for structured+// error diagnostics. It converts the byte offset in ParseError.Position// to 1-based line and 1-based column (rune-based) matching the// storepb.Position convention used across other omni parser adapters.//// If basePos is non-nil, the computed position is offset by it so that// errors from parsing an isolated statement segment are reported in the// coordinates of the original multi-statement script.-func convertParseError(statement string, pe *parser.ParseError, basePos *storepb.Position) *base.SyntaxError {- line, col := byteOffsetToPosition(statement, pe.Loc.Start)+func convertParseError(statement string, err error, basePos *storepb.Position) error {+ var pe *parser.ParseError+ if !errors.As(err, &pe) {+ return err+ }+ line, col := byteOffsetToPosition(statement, pe.Position)if basePos != nil {// The first line of the segment shares a line with basePos, so// column offsets only apply when the error is on that line.@@ -135,7 +138,7 @@ func convertParseError(statement string, pe *parser.ParseError, basePos *storepbColumn: int32(col),},Message: pe.Error(),- RawMessage: pe.Msg,+ RawMessage: pe.Message,}}diff --git a/backend/plugin/parser/doris/limit.go b/backend/plugin/parser/doris/limit.goindex 22490a5249..07935e365a 100644--- a/backend/plugin/parser/doris/limit.go+++ b/backend/plugin/parser/doris/limit.go@@ -74,9 +74,9 @@ func statementWithResultLimitInline(statement string, limitCount int) (string, ereturn "", errors.New("empty statement")}- file, errs := parser.Parse(statement)- if len(errs) > 0 {- return "", errors.New(errs[0].Error())+ file, err := parser.Parse(statement)+ if err != nil {+ return "", parser.FirstError(err)}if file == nil || len(file.Stmts) != 1 {stmtCount := 0diff --git a/backend/plugin/parser/doris/query_span_extractor.go b/backend/plugin/parser/doris/query_span_extractor.goindex 036617cb5b..dc8ade1ee4 100644--- a/backend/plugin/parser/doris/query_span_extractor.go+++ b/backend/plugin/parser/doris/query_span_extractor.go@@ -112,8 +112,8 @@ func (q *querySpanExtractor) getQuerySpan(ctx context.Context, statement string)// without this unwrap an `EXPLAIN SELECT ... FROM t` would yield zero// AccessTables — table-level ACL checks need to see `t`.func unwrapExplainForSpan(statement string) string {- file, errs := parser.Parse(statement)- if len(errs) > 0 || file == nil || len(file.Stmts) == 0 {+ file, err := parser.Parse(statement)+ if err != nil || file == nil || len(file.Stmts) == 0 {return statement}explain, ok := file.Stmts[0].(*ast.ExplainStmt)diff --git a/backend/plugin/parser/doris/query_type.go b/backend/plugin/parser/doris/query_type.goindex 4495086671..b945c94ebb 100644--- a/backend/plugin/parser/doris/query_type.go+++ b/backend/plugin/parser/doris/query_type.go@@ -49,8 +49,8 @@ func getQueryType(statement string, allSystems bool) base.QueryType {// node. On parse failure or empty input it falls back to the keyword-based// Classify.func classifyByAST(statement string) analysis.QueryType {- file, errs := parser.Parse(statement)- if len(errs) > 0 || file == nil || len(file.Stmts) == 0 {+ file, err := parser.Parse(statement)+ if err != nil || file == nil || len(file.Stmts) == 0 {return analysis.Classify(statement)}if qt, ok := astQueryType(file.Stmts[0]); ok {diff --git a/backend/plugin/parser/googlesql/query_type.go b/backend/plugin/parser/googlesql/query_type.goindex 138f05a219..42059ef4dc 100644--- a/backend/plugin/parser/googlesql/query_type.go+++ b/backend/plugin/parser/googlesql/query_type.go@@ -22,8 +22,8 @@ func ClassifyStatement(statement string, cfg Config) base.QueryType {// IsSetStatement reports whether the statement parses to a single SET statement.func IsSetStatement(statement string) bool {- file, errs := parser.Parse(statement)- if len(errs) > 0 || file == nil || len(file.Stmts) != 1 {+ file, err := parser.Parse(statement)+ if err != nil || file == nil || len(file.Stmts) != 1 {return false}_, ok := file.Stmts[0].(*ast.SetStmt)diff --git a/backend/plugin/parser/googlesql/statement_type.go b/backend/plugin/parser/googlesql/statement_type.goindex 49cbe939cc..c1a99a5b06 100644--- a/backend/plugin/parser/googlesql/statement_type.go+++ b/backend/plugin/parser/googlesql/statement_type.go@@ -34,8 +34,8 @@ func ParseStatements(statement string, cfg Config) ([]base.ParsedStatement, errovar result []base.ParsedStatementfor _, stmt := range stmts {- file, errs := parser.Parse(stmt.Text)- if len(errs) > 0 || file == nil || len(file.Stmts) == 0 {+ file, err := parser.Parse(stmt.Text)+ if err != nil || file == nil || len(file.Stmts) == 0 {result = append(result, base.ParsedStatement{Statement: stmt,AST: &AST{StartPosition: stmt.Start},diff --git a/backend/plugin/parser/mysql/backup.go b/backend/plugin/parser/mysql/backup.goindex 431d80eb1a..eb694350e5 100644--- a/backend/plugin/parser/mysql/backup.go+++ b/backend/plugin/parser/mysql/backup.go@@ -10,6 +10,7 @@ import ("github.com/pkg/errors""github.com/bytebase/omni/mysql/ast"+ mysqlparser "github.com/bytebase/omni/mysql/parser""github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store"@@ -275,40 +276,71 @@ func collectSingleTablesFromExpr(databaseName string, expr ast.TableExpr, out ma}}-// collectCTENames extracts CTE names from the SQL text before the statement Loc.-// MySQL's UPDATE/DELETE CTEs are not in the omni AST, so we parse the prefix.+// collectCTENames returns the names of the CTEs the statement at stmtLoc opens with.func collectCTENames(fullSQL string, stmtLoc ast.Loc) map[string]bool {result := make(map[string]bool)- for _, cte := range parseCTEPrefix(fullSQL, stmtLoc) {+ for _, cte := range parseCTEs(withClause(fullSQL, stmtLoc)) {result[cte.Name] = true}return result}-// extractCTE extracts the CTE (WITH clause) text from the SQL before the statement.+// extractCTE returns the WITH clause the statement at stmtLoc opens with, or ""+// when it has none or the clause does not parse.func extractCTE(fullSQL string, stmtLoc ast.Loc) string {- if stmtLoc.Start <= 0 {+ clause := withClause(fullSQL, stmtLoc)+ if len(parseCTEs(clause)) == 0 {return ""}- ctes := parseCTEPrefix(fullSQL, stmtLoc)- if len(ctes) == 0 {+ return clause+}++// withClause returns the WITH clause that opens the UPDATE or DELETE at loc, or "".+func withClause(sql string, loc ast.Loc) string {+ start := dmlKeywordStart(sql, loc)+ if start <= loc.Start {return ""}- return strings.TrimSpace(fullSQL[:stmtLoc.Start])+ return strings.TrimSpace(sql[loc.Start:start])}-// parseCTEPrefix parses the SQL text before stmtLoc as a WITH clause.-// Returns the CTE list if the prefix contains a valid WITH clause, nil otherwise.-func parseCTEPrefix(fullSQL string, stmtLoc ast.Loc) []*ast.CommonTableExpr {- if stmtLoc.Start <= 0 {- return nil+// dmlKeywordStart returns the offset of the UPDATE or DELETE keyword of the+// statement at loc. omni starts the node at its WITH clause, if any, and keeps+// no CTE on it, so the clause is the text between the two.+func dmlKeywordStart(sql string, loc ast.Loc) int {+ if loc.Start < 0 || loc.End > len(sql) || loc.Start >= loc.End {+ return loc.Start+ }+ tokens := mysqlparser.Tokenize(sql[loc.Start:loc.End])+ if len(tokens) == 0 || mysqlparser.TokenName(tokens[0].Type) != "WITH" {+ return loc.Start+ }+ depth := 0+ for _, token := range tokens[1:] {+ switch token.Type {+ case '(':+ depth+++ case ')':+ depth--+ default:+ if depth != 0 {+ continue+ }+ if name := mysqlparser.TokenName(token.Type); name == "UPDATE" || name == "DELETE" {+ return loc.Start + token.Loc+ }+ }}- prefix := strings.TrimSpace(fullSQL[:stmtLoc.Start])- if prefix == "" {+ return loc.Start+}++// parseCTEs returns the CTEs of a WITH clause, or nil when it does not parse.+func parseCTEs(clause string) []*ast.CommonTableExpr {+ if clause == "" {return nil}- // Wrap the prefix with a dummy SELECT to make it parseable.- parsed, err := ParseMySQL(prefix + " SELECT 1")+ // Wrap the clause with a dummy SELECT to make it parseable.+ parsed, err := ParseMySQL(clause + " SELECT 1")if err != nil || parsed == nil {return nil}diff --git a/backend/plugin/parser/mysql/explain.go b/backend/plugin/parser/mysql/explain.goindex d8ff52ee9c..de98c1c09a 100644--- a/backend/plugin/parser/mysql/explain.go+++ b/backend/plugin/parser/mysql/explain.go@@ -62,8 +62,8 @@ func singleStatement(text string) (ast.Node, error) {// explainedText returns the text within text of the statement explain plans, and// whether it could be located.func explainedText(explain *ast.ExplainStmt, text string) (string, bool) {- // An executable comment moves every location after it, because the lexer- // parses the comment's body with its markers spliced out of the text.+ // The parser reads the body of an executable comment, so a location can fall+ // inside one and the slice would leave the comment unclosed.if strings.Contains(text, "/*!") || strings.Contains(text, "/*M!") {return "", false}diff --git a/backend/plugin/parser/mysql/explain_plan.go b/backend/plugin/parser/mysql/explain_plan.goindex 9a3e94f5f5..943703e439 100644--- a/backend/plugin/parser/mysql/explain_plan.go+++ b/backend/plugin/parser/mysql/explain_plan.go@@ -40,18 +40,19 @@ func AffectedRowsQuery(stmt ast.Node, statement string) string {if loc.Start < 0 || loc.Start > table.Loc.Start || table.Loc.End > clausesStart || clausesStart > loc.End || loc.End > len(statement) {return statement}- // omni positions the text after an executable comment as if the comment's markers were removed, so- // no SELECT is cut from a statement with one. The SELECT would also leave out an optimizer hint- // before the table, which can change the plan.- if strings.Contains(statement, "/*!") || strings.Contains(statement, "/*M!") || strings.Contains(statement[loc.Start:table.Loc.Start], "/*+") {+ keywordStart := dmlKeywordStart(statement, loc)+ // The parser reads the body of an executable comment, so a cut could leave one unclosed; no SELECT+ // is cut from a statement with one. The SELECT would also leave out an optimizer hint before the+ // table, which can change the plan.+ if strings.Contains(statement, "/*!") || strings.Contains(statement, "/*M!") || strings.Contains(statement[keywordStart:table.Loc.Start], "/*+") {return statement}clauses := strings.TrimSpace(statement[clausesStart:loc.End])if rest := trimLeadingComments(clauses); rest != "" && !startsWithKeyword(rest, "WHERE", "ORDER", "LIMIT") {return statement}- // The text before the statement holds its WITH clause.- query := statement[:loc.Start] + "SELECT 1 FROM " + statement[table.Loc.Start:table.Loc.End]+ // The text before the UPDATE or DELETE keyword holds the statement's WITH clause.+ query := statement[:keywordStart] + "SELECT 1 FROM " + statement[table.Loc.Start:table.Loc.End]if clauses != "" {query += " " + clauses}diff --git a/backend/plugin/parser/mysql/explain_plan_test.go b/backend/plugin/parser/mysql/explain_plan_test.goindex 191193b880..be4d289cd5 100644--- a/backend/plugin/parser/mysql/explain_plan_test.go+++ b/backend/plugin/parser/mysql/explain_plan_test.go@@ -38,7 +38,7 @@ func TestAffectedRowsQuery(t *testing.T) {{name: "update with a comment before WHERE",statement: "UPDATE t SET v = (SELECT MAX(v) FROM s) /* latest */ WHERE id = 1",- want: "SELECT 1 FROM t WHERE id = 1",+ want: "SELECT 1 FROM t /* latest */ WHERE id = 1",},{name: "delete with a comment before WHERE",@@ -48,7 +48,7 @@ func TestAffectedRowsQuery(t *testing.T) {{name: "update with a block comment before WHERE",statement: "UPDATE t SET c = 1 /* ticket 42 */ WHERE id = 1;",- want: "SELECT 1 FROM t WHERE id = 1",+ want: "SELECT 1 FROM t /* ticket 42 */ WHERE id = 1",},{name: "delete with an executable comment",diff --git a/backend/plugin/parser/partiql/query.go b/backend/plugin/parser/partiql/query.goindex f44094ca49..26d6285f7f 100644--- a/backend/plugin/parser/partiql/query.go+++ b/backend/plugin/parser/partiql/query.go@@ -36,7 +36,7 @@ func validateQuery(statement string) (bool, bool, error) {// convertParseError converts an omni *parser.ParseError to a// *base.SyntaxError that sql_service.go recognizes for structured-// error diagnostics. It converts the byte offset in ParseError.Loc+// error diagnostics. It converts the byte offset in ParseError.Position// to 1-based line and 1-based column (rune-based) matching the// storepb.Position convention used across all omni parser adapters.//@@ -44,7 +44,7 @@ func validateQuery(statement string) (bool, bool, error) {// errors from parsing an isolated statement segment are reported in the// coordinates of the original multi-statement script.func convertParseError(statement string, pe *parser.ParseError, basePos *storepb.Position) *base.SyntaxError {- line, col := byteOffsetToPosition(statement, pe.Loc.Start)+ line, col := byteOffsetToPosition(statement, pe.Position)if basePos != nil {// The first line of the segment shares a line with basePos, so// column offsets only apply when the error is on that line.diff --git a/backend/plugin/parser/snowflake/diagnose.go b/backend/plugin/parser/snowflake/diagnose.goindex 682c083c48..3184c0f55b 100644--- a/backend/plugin/parser/snowflake/diagnose.go+++ b/backend/plugin/parser/snowflake/diagnose.go@@ -30,10 +30,8 @@ func init() {func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]base.Diagnostic, error) {diags := diagnostics.Analyze(statement)out := make([]base.Diagnostic, 0, len(diags))- // Re-derive line:column from the byte offset so the column is rune-based- // (the position that base.ConvertSyntaxErrorToDiagnostic expects). omni's- // own Range.Column is byte-based, so we deliberately use Offset instead to- // keep multibyte input positions correct — mirroring the Trino diagnose.go.+ // Re-derive line:column from the byte offset so the position matches what+ // base.ConvertSyntaxErrorToDiagnostic expects, mirroring the Trino diagnose.go.mapper := base.NewByteOffsetPositionMapper(statement)for _, d := range diags {syntaxErr := &base.SyntaxError{diff --git a/backend/plugin/parser/snowflake/omni_ast.go b/backend/plugin/parser/snowflake/omni_ast.goindex 4bdd3d042e..2b319e92a0 100644--- a/backend/plugin/parser/snowflake/omni_ast.go+++ b/backend/plugin/parser/snowflake/omni_ast.go@@ -72,7 +72,7 @@ func convertOmniParseError(err error, stmt base.Statement) error {}mapper := base.NewByteOffsetPositionMapper(stmt.Text)- position := mapper.Position(parseErr.Loc.Start)+ position := mapper.Position(parseErr.Position)if stmt.Start != nil {localLine := position.Lineposition.Line += stmt.Start.Line - 1@@ -82,7 +82,7 @@ func convertOmniParseError(err error, stmt base.Statement) error {}return &base.SyntaxError{Position: position,- Message: fmt.Sprintf("Syntax error at line %d:%d \n%s", position.Line, position.Column, parseErr.Msg),- RawMessage: parseErr.Msg,+ Message: fmt.Sprintf("Syntax error at line %d:%d \n%s", position.Line, position.Column, parseErr.Message),+ RawMessage: parseErr.Message,}}diff --git a/backend/plugin/parser/spanner/limit.go b/backend/plugin/parser/spanner/limit.goindex 7d15ba8172..bd99828d28 100644--- a/backend/plugin/parser/spanner/limit.go+++ b/backend/plugin/parser/spanner/limit.go@@ -20,8 +20,8 @@ func init() {// clause, so a query it cannot rewrite runs unchanged and queryStatement caps its// rows.func statementWithResultLimit(stmt string, limit int, _ string) string {- file, errs := parser.Parse(stmt)- if len(errs) > 0 || len(file.Stmts) != 1 {+ file, err := parser.Parse(stmt)+ if err != nil || len(file.Stmts) != 1 {return stmt}query, ok := file.Stmts[0].(*ast.QueryStmt)diff --git a/backend/plugin/parser/starrocks/limit.go b/backend/plugin/parser/starrocks/limit.goindex 80f3ac49f8..24f8b4d23f 100644--- a/backend/plugin/parser/starrocks/limit.go+++ b/backend/plugin/parser/starrocks/limit.go@@ -40,9 +40,9 @@ func statementWithResultLimitInline(statement string, limitCount int) (string, ereturn "", errors.New("empty statement")}- file, errs := parser.Parse(statement)- if len(errs) > 0 {- return "", errors.New(errs[0].Error())+ file, err := parser.Parse(statement)+ if err != nil {+ return "", parser.FirstError(err)}if file == nil || len(file.Stmts) != 1 {stmtCount := 0diff --git a/backend/plugin/parser/starrocks/query_span_extractor.go b/backend/plugin/parser/starrocks/query_span_extractor.goindex fc22c083df..ec23e64ee7 100644--- a/backend/plugin/parser/starrocks/query_span_extractor.go+++ b/backend/plugin/parser/starrocks/query_span_extractor.go@@ -112,8 +112,8 @@ func (q *querySpanExtractor) getQuerySpan(ctx context.Context, statement string)// without this unwrap an `EXPLAIN SELECT ... FROM t` would yield zero// AccessTables — table-level ACL checks need to see `t`.func unwrapExplainForSpan(statement string) string {- file, errs := parser.Parse(statement)- if len(errs) > 0 || file == nil || len(file.Stmts) == 0 {+ file, err := parser.Parse(statement)+ if err != nil || file == nil || len(file.Stmts) == 0 {return statement}explain, ok := file.Stmts[0].(*ast.ExplainStmt)diff --git a/backend/plugin/parser/starrocks/query_type.go b/backend/plugin/parser/starrocks/query_type.goindex 1e968513e8..22aa505a2b 100644--- a/backend/plugin/parser/starrocks/query_type.go+++ b/backend/plugin/parser/starrocks/query_type.go@@ -49,8 +49,8 @@ func getQueryType(statement string, allSystems bool) base.QueryType {// node. On parse failure or empty input it falls back to the keyword-based// Classify.func classifyByAST(statement string) analysis.QueryType {- file, errs := parser.Parse(statement)- if len(errs) > 0 || file == nil || len(file.Stmts) == 0 {+ file, err := parser.Parse(statement)+ if err != nil || file == nil || len(file.Stmts) == 0 {return analysis.Classify(statement)}if qt, ok := astQueryType(file.Stmts[0]); ok {diff --git a/backend/plugin/parser/starrocks/starrocks.go b/backend/plugin/parser/starrocks/starrocks.goindex 07685dc621..c14dc889eb 100644--- a/backend/plugin/parser/starrocks/starrocks.go+++ b/backend/plugin/parser/starrocks/starrocks.go@@ -1,6 +1,7 @@package starrocksimport (+ "errors""strings""unicode/utf8"@@ -56,10 +57,9 @@ func parseStarRocksStatements(statement string) ([]base.ParsedStatement, error)// Parse the segment text on its own so byte offsets in any ParseError// align with stmt.Text; convertParseError then shifts them into the// coordinates of the original multi-statement script.- file, errs := parser.Parse(stmt.Text)- if len(errs) > 0 {- pe := errs[0]- return nil, convertParseError(stmt.Text, &pe, stmt.Start)+ file, err := parser.Parse(stmt.Text)+ if err != nil {+ return nil, convertParseError(stmt.Text, err, stmt.Start)}var node ast.Nodeif file != nil && len(file.Stmts) > 0 {@@ -93,10 +93,9 @@ func parseStarRocksSQL(statement string) ([]*omniAST, error) {if stmt.Empty || strings.TrimSpace(stmt.Text) == "" {continue}- file, errs := parser.Parse(stmt.Text)- if len(errs) > 0 {- pe := errs[0]- return nil, convertParseError(stmt.Text, &pe, stmt.Start)+ file, err := parser.Parse(stmt.Text)+ if err != nil {+ return nil, convertParseError(stmt.Text, err, stmt.Start)}var node ast.Nodeif file != nil && len(file.Stmts) > 0 {@@ -110,17 +109,21 @@ func parseStarRocksSQL(statement string) ([]*omniAST, error) {return result, nil}-// convertParseError converts an omni *parser.ParseError to a-// *base.SyntaxError that sql_service.go recognises for structured-// error diagnostics. It converts the byte offset in ParseError.Loc+// convertParseError converts the first omni *parser.ParseError carried by err+// to a *base.SyntaxError that sql_service.go recognises for structured+// error diagnostics. It converts the byte offset in ParseError.Position// to 1-based line and 1-based column (rune-based) matching the// storepb.Position convention used across other omni parser adapters.//// If basePos is non-nil, the computed position is offset by it so that// errors from parsing an isolated statement segment are reported in the// coordinates of the original multi-statement script.-func convertParseError(statement string, pe *parser.ParseError, basePos *storepb.Position) *base.SyntaxError {- line, col := byteOffsetToPosition(statement, pe.Loc.Start)+func convertParseError(statement string, err error, basePos *storepb.Position) error {+ var pe *parser.ParseError+ if !errors.As(err, &pe) {+ return err+ }+ line, col := byteOffsetToPosition(statement, pe.Position)if basePos != nil {// The first line of the segment shares a line with basePos, so// column offsets only apply when the error is on that line.@@ -135,7 +138,7 @@ func convertParseError(statement string, pe *parser.ParseError, basePos *storepbColumn: int32(col),},Message: pe.Error(),- RawMessage: pe.Msg,+ RawMessage: pe.Message,}}diff --git a/backend/plugin/parser/tidb/backup.go b/backend/plugin/parser/tidb/backup.goindex 6b2c15d2ce..f9ae22285c 100644--- a/backend/plugin/parser/tidb/backup.go+++ b/backend/plugin/parser/tidb/backup.go@@ -9,6 +9,7 @@ import ("github.com/pkg/errors""github.com/bytebase/omni/tidb/ast"+ omniparser "github.com/bytebase/omni/tidb/parser""github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store"@@ -403,13 +404,11 @@ func firstKey(m map[string]*TableReference) string {return ""}-// collectCTENames returns the set of CTE (WITH clause) names that precede the-// statement, lower-cased for case-insensitive matching. omni does not attach-// UPDATE/DELETE CTEs to the statement node, so we parse the text before the-// statement Loc as a WITH clause.+// collectCTENames returns the names of the CTEs the statement opens with,+// lower-cased for case-insensitive matching.func collectCTENames(fullSQL string, stmtLoc ast.Loc) map[string]bool {result := make(map[string]bool)- for _, cte := range parseCTEPrefix(fullSQL, stmtLoc) {+ for _, cte := range parseCTEs(withClause(fullSQL, stmtLoc)) {result[strings.ToLower(cte.Name)] = true}return result@@ -425,9 +424,7 @@ func isCTERef(cteNames map[string]bool, ref *TableReference) bool {}// writeCTEPrefix writes the statement's WITH (CTE) clause before the backup-// SELECT, so a SELECT whose FROM references a CTE stays valid. omni does not-// attach UPDATE/DELETE CTEs to the statement node, so the prefix is recovered-// from the text before the statement Loc.+// SELECT, so a SELECT whose FROM references a CTE stays valid.func writeCTEPrefix(buf *strings.Builder, node ast.Node, fullSQL string) error {cte := extractCTE(fullSQL, nodeStmtLoc(node))if cte == "" {@@ -437,12 +434,45 @@ func writeCTEPrefix(buf *strings.Builder, node ast.Node, fullSQL string) error {return err}-// extractCTE returns the WITH-clause text preceding the statement, or "".+// extractCTE returns the WITH clause the statement opens with, or "" when it+// has none or the clause does not parse.func extractCTE(fullSQL string, stmtLoc ast.Loc) string {- if stmtLoc.Start <= 0 || len(parseCTEPrefix(fullSQL, stmtLoc)) == 0 {+ clause := withClause(fullSQL, stmtLoc)+ if len(parseCTEs(clause)) == 0 {return ""}- return strings.TrimSpace(fullSQL[:stmtLoc.Start])+ return clause+}++// withClause returns the WITH clause that opens the UPDATE or DELETE at loc, or+// "". omni starts the node at its WITH clause and keeps no CTE on it, so the+// clause is the text before the UPDATE or DELETE keyword outside parentheses.+func withClause(sql string, loc ast.Loc) string {+ if loc.Start < 0 || loc.End > len(sql) || loc.Start >= loc.End {+ return ""+ }+ text := sql[loc.Start:loc.End]+ tokens := omniparser.Tokenize(text)+ if len(tokens) == 0 || omniparser.TokenName(tokens[0].Type) != "WITH" {+ return ""+ }+ depth := 0+ for _, token := range tokens[1:] {+ switch token.Type {+ case '(':+ depth+++ case ')':+ depth--+ default:+ if depth != 0 {+ continue+ }+ if name := omniparser.TokenName(token.Type); name == "UPDATE" || name == "DELETE" {+ return strings.TrimSpace(text[:token.Loc])+ }+ }+ }+ return ""}// nodeStmtLoc returns the source Loc of a DML statement node.@@ -456,16 +486,13 @@ func nodeStmtLoc(node ast.Node) ast.Loc {return ast.Loc{}}-func parseCTEPrefix(fullSQL string, stmtLoc ast.Loc) []*ast.CommonTableExpr {- if stmtLoc.Start <= 0 || stmtLoc.Start > len(fullSQL) {- return nil- }- prefix := strings.TrimSpace(fullSQL[:stmtLoc.Start])- if prefix == "" {+// parseCTEs returns the CTEs of a WITH clause, or nil when it does not parse.+func parseCTEs(clause string) []*ast.CommonTableExpr {+ if clause == "" {return nil}- // Wrap the prefix with a dummy SELECT so it parses as a complete statement.- parsed, err := ParseTiDBOmni(prefix + " SELECT 1")+ // Wrap the clause with a dummy SELECT so it parses as a complete statement.+ parsed, err := ParseTiDBOmni(clause + " SELECT 1")if err != nil || parsed == nil {return nil}diff --git a/backend/plugin/parser/tidb/dispatcher_test.go b/backend/plugin/parser/tidb/dispatcher_test.goindex 9060b52969..fd4d37860f 100644--- a/backend/plugin/parser/tidb/dispatcher_test.go+++ b/backend/plugin/parser/tidb/dispatcher_test.go@@ -20,29 +20,23 @@ import (//// Also asserts the per-fallback observability sub-contract: the// tidb_dispatcher_omni_fallback_total{reason} counter increments by-// exactly 1 for the rejected statement, with the empirically-verified-// "sequence" label.+// exactly 1 for the rejected statement, with the "flashback" label.//-// Empirical note (invariant #9): the Option B fixture must be a statement-// omni REJECTS but pingcap ACCEPTS. BATCH non-transactional DML was the-// original choice, but omni now SUPPORTS BATCH (grammar merged in omni-// #157, consumed via the go.mod bump), so it no longer falls back.-// `FLASHBACK TABLE foo TO BEFORE DROP;` can't be used either — pingcap-// rejects that exact syntax (both-engines-reject path). `CREATE SEQUENCE`-// is the correct Option B input: omni rejects it (Tier-4 grammar gap),-// pingcap accepts it (TiDB sequences). If pingcap also rejected it, the+// The Option B fixture must be a statement omni REJECTS but pingcap+// ACCEPTS (invariant #9); omni now parses BATCH and CREATE SEQUENCE, so+// neither falls back. If pingcap also rejected the fixture, the// require.NoError below would fail.func TestParseTiDBStatementsOmni_OptionBFallback(t *testing.T) {const (omniAccepted1 = "CREATE TABLE t (id INT);"- omniRejected = "CREATE SEQUENCE seq;"+ omniRejected = "FLASHBACK TABLE t;"omniAccepted2 = "INSERT INTO t (id) VALUES (1);")input := omniAccepted1 + "\n" + omniRejected + "\n" + omniAccepted2// Snapshot the counter before so the assertion is delta-based — other// tests in the package may have incremented it already.- before := testutil.ToFloat64(tidbDispatcherOmniFallbackTotal.WithLabelValues("sequence"))+ before := testutil.ToFloat64(tidbDispatcherOmniFallbackTotal.WithLabelValues("flashback"))result, err := parseTiDBStatementsOmni(input)require.NoError(t, err,@@ -56,7 +50,7 @@ func TestParseTiDBStatementsOmni_OptionBFallback(t *testing.T) {// trailing whitespace etc.).for _, ps := range result {switch {- case strings.Contains(ps.Text, "SEQUENCE"):+ case strings.Contains(ps.Text, "FLASHBACK"):require.IsType(t, &AST{}, ps.AST,"omni-rejected statement must carry pingcap *AST after Option B fallback (un-migrated advisors continue to function)")case strings.Contains(ps.Text, "CREATE TABLE") || strings.Contains(ps.Text, "INSERT"):@@ -68,9 +62,9 @@ func TestParseTiDBStatementsOmni_OptionBFallback(t *testing.T) {}// Counter sub-contract.- after := testutil.ToFloat64(tidbDispatcherOmniFallbackTotal.WithLabelValues("sequence"))+ after := testutil.ToFloat64(tidbDispatcherOmniFallbackTotal.WithLabelValues("flashback"))require.InDelta(t, 1.0, after-before, 0.0001,- "counter must increment by exactly 1 for the single SEQUENCE fallback")+ "counter must increment by exactly 1 for the single FLASHBACK fallback")}// TestParseTiDBStatementsOmni_BothEnginesReject pins the Q2 designdiff --git a/backend/plugin/parser/tidb/explain.go b/backend/plugin/parser/tidb/explain.goindex 998bbbe547..9c8af8442e 100644--- a/backend/plugin/parser/tidb/explain.go+++ b/backend/plugin/parser/tidb/explain.go@@ -60,8 +60,8 @@ func singleStatement(text string) (omniast.Node, error) {// explainedText returns the text within text of the statement explain plans, and// whether it could be located.func explainedText(explain *omniast.ExplainStmt, text string) (string, bool) {- // An executable comment moves every location after it, because the lexer- // parses the comment's body with its markers spliced out of the text.+ // The parser reads the body of an executable comment, so a location can fall+ // inside one and the slice would leave the comment unclosed.if strings.Contains(text, "/*!") || strings.Contains(text, "/*T!") {return "", false}diff --git a/backend/plugin/parser/tidb/metrics_test.go b/backend/plugin/parser/tidb/metrics_test.goindex 9f4b368ff5..b274b12da3 100644--- a/backend/plugin/parser/tidb/metrics_test.go+++ b/backend/plugin/parser/tidb/metrics_test.go@@ -8,18 +8,10 @@ import ()// TestClassifyOmniParseError pins the dispatcher fallback classifier-// against the actual omni error strings — empirically derived against-// omni v0.0.0-20260513072939-39c04c4cca0f. The classifier must label each+// against the actual omni error strings. The classifier must label each// known Tier-4 grammar gap correctly so the// tidb_dispatcher_omni_fallback_total{reason} counter drives the// invariant #8 retirement gate (otherwise we ship Option B blind).-//-// Critical empirical finding (motivating the err+sql two-arg signature):-// CREATE SEQUENCE seq; produces an omni error string of "unexpected token-// after CREATE (line 1, column 8)" — the keyword SEQUENCE never appears-// in the error. A classifier that matched only against err.Error() would-// silently mis-label SEQUENCE rejections as "unknown" and lose the entire-// SEQUENCE telemetry signal. The sql parameter is required, not optional.func TestClassifyOmniParseError(t *testing.T) {cases := []struct {name string@@ -33,12 +25,6 @@ func TestClassifyOmniParseError(t *testing.T) {wantOK: false,expected: "flashback",},- {- name: "SEQUENCE keyword ONLY in input (omni err says 'after CREATE')",- sql: "CREATE SEQUENCE seq;",- wantOK: false,- expected: "sequence",- },// NOTE: BATCH non-transactional DML is now SUPPORTED by omni (grammar// merged in omni #157, consumed via the go.mod bump). It therefore// parses successfully and no longer reaches the fallback classifier, sodiff --git a/backend/plugin/parser/tidb/resource_change.go b/backend/plugin/parser/tidb/resource_change.goindex a5c07a6e09..225251a2aa 100644--- a/backend/plugin/parser/tidb/resource_change.go+++ b/backend/plugin/parser/tidb/resource_change.go@@ -135,7 +135,8 @@ func addBatchSampleDML(summary *base.ChangeSummary, ast base.AST) {summary.DMLCount++return}- // omni positions the text after an executable comment as if the comment's markers were removed.+ // The parser reads the body of an executable comment, so the DML's location can fall inside one+ // and the slice would leave the comment unclosed.if strings.Contains(omniAST.Text, "/*!") || strings.Contains(omniAST.Text, "/*T!") || strings.Contains(omniAST.Text, "/*M!") {summary.DMLCount++returndiff --git a/backend/plugin/parser/trino/query_span_extractor.go b/backend/plugin/parser/trino/query_span_extractor.goindex 5a9fa69d32..ee89680dad 100644--- a/backend/plugin/parser/trino/query_span_extractor.go+++ b/backend/plugin/parser/trino/query_span_extractor.go@@ -87,8 +87,8 @@ func (q *querySpanExtractor) getQuerySpan(ctx context.Context, statement string)// Resolve the statement type up front so non-SELECT statements short-circuit// the way the legacy plugin did. EXPLAIN ANALYZE classifies as base.Select.- file, errs := parser.Parse(single)- if len(errs) > 0 || file == nil || len(file.Stmts) == 0 {+ file, err := parser.Parse(single)+ if err != nil || file == nil || len(file.Stmts) == 0 {return nil, errors.Errorf("failed to parse Trino statement: %s", single)}node := file.Stmts[0]diff --git a/backend/plugin/parser/trino/query_type.go b/backend/plugin/parser/trino/query_type.goindex 780a81cf81..3f8bcd8c6f 100644--- a/backend/plugin/parser/trino/query_type.go+++ b/backend/plugin/parser/trino/query_type.go@@ -71,8 +71,8 @@ func getQueryType(node ast.Node) (base.QueryType, bool) {//// On parse failure or empty/multi input it returns base.QueryTypeUnknown.func queryTypeFromText(statement string) base.QueryType {- file, errs := parser.Parse(statement)- if len(errs) > 0 || file == nil || len(file.Stmts) == 0 {+ file, err := parser.Parse(statement)+ if err != nil || file == nil || len(file.Stmts) == 0 {return base.QueryTypeUnknown}qt, _ := getQueryType(file.Stmts[0])diff --git a/backend/plugin/parser/trino/trino.go b/backend/plugin/parser/trino/trino.goindex 2985cb7e0c..031946cee1 100644--- a/backend/plugin/parser/trino/trino.go+++ b/backend/plugin/parser/trino/trino.go@@ -3,6 +3,7 @@package trinoimport (+ "errors""strings""github.com/bytebase/omni/trino/ast"@@ -103,9 +104,9 @@ func parseSegment(stmt base.Statement) (*omniAST, error) {if stmt.Empty || strings.TrimSpace(stmt.Text) == "" {return nil, nil}- file, errs := parser.Parse(stmt.Text)- if len(errs) > 0 {- return nil, convertParseError(stmt.Text, &errs[0], stmt.Start)+ file, err := parser.Parse(stmt.Text)+ if err != nil {+ return nil, convertParseError(stmt.Text, err, stmt.Start)}var node ast.Nodeif file != nil && len(file.Stmts) > 0 {@@ -114,17 +115,21 @@ func parseSegment(stmt base.Statement) (*omniAST, error) {return &omniAST{node: node, startPos: stmt.Start}, nil}-// convertParseError converts an omni *parser.ParseError to a *base.SyntaxError-// that sql_service.go recognises for structured error diagnostics. It converts-// the byte offset in ParseError.Loc to 1-based line and 1-based column-// (rune-based), matching the storepb.Position convention used across other omni-// parser adapters.+// convertParseError converts the first omni *parser.ParseError carried by err to+// a *base.SyntaxError that sql_service.go recognises for structured error+// diagnostics. It converts the byte offset in ParseError.Position to 1-based+// line and 1-based column (rune-based), matching the storepb.Position+// convention used across other omni parser adapters.//// If basePos is non-nil, the computed position is offset by it so that errors// from parsing an isolated statement segment are reported in the coordinates of// the original multi-statement script.-func convertParseError(statement string, pe *parser.ParseError, basePos *storepb.Position) *base.SyntaxError {- pos := base.NewByteOffsetPositionMapper(statement).Position(pe.Loc.Start)+func convertParseError(statement string, err error, basePos *storepb.Position) error {+ var pe *parser.ParseError+ if !errors.As(err, &pe) {+ return err+ }+ pos := base.NewByteOffsetPositionMapper(statement).Position(pe.Position)line, col := int(pos.Line), int(pos.Column)if basePos != nil {if line == 1 {@@ -138,7 +143,7 @@ func convertParseError(statement string, pe *parser.ParseError, basePos *storepbColumn: int32(col),},Message: pe.Error(),- RawMessage: pe.Msg,+ RawMessage: pe.Message,}}diff --git a/backend/runner/reviewrun/review_funcs.go b/backend/runner/reviewrun/review_funcs.goindex 324c957d26..b138b98781 100644--- a/backend/runner/reviewrun/review_funcs.go+++ b/backend/runner/reviewrun/review_funcs.go@@ -1,13 +1,29 @@package reviewrunimport (+ mariadbreview "github.com/bytebase/omni/mariadb/review"+ mssqlreview "github.com/bytebase/omni/mssql/review"+ mysqlreview "github.com/bytebase/omni/mysql/review"+ oraclereview "github.com/bytebase/omni/oracle/review"+ pgreview "github.com/bytebase/omni/pg/review""github.com/bytebase/omni/review"+ snowflakereview "github.com/bytebase/omni/snowflake/review"+ tidbreview "github.com/bytebase/omni/tidb/review"storepb "github.com/bytebase/bytebase/backend/generated-go/store")// reviewFuncs maps an engine to its omni Review entry point. An engine absent// here has no standard rule review, and a run touching it fails. The map-// fills in as omni ships engine review packages (pg/review, mysql/review,-// ...): each one is a line here and nothing else.-var reviewFuncs = map[storepb.Engine]review.ReviewFunc{}+// fills in as omni ships engine review packages: each one is a line here and+// nothing else.+var reviewFuncs = map[storepb.Engine]review.ReviewFunc{+ storepb.Engine_POSTGRES: pgreview.Review,+ storepb.Engine_MYSQL: mysqlreview.Review,+ storepb.Engine_OCEANBASE: mysqlreview.ReviewOceanBase,+ storepb.Engine_MARIADB: mariadbreview.Review,+ storepb.Engine_TIDB: tidbreview.Review,+ storepb.Engine_MSSQL: mssqlreview.Review,+ storepb.Engine_ORACLE: oraclereview.Review,+ storepb.Engine_SNOWFLAKE: snowflakereview.Review,+}diff --git a/backend/runner/reviewrun/review_funcs_test.go b/backend/runner/reviewrun/review_funcs_test.gonew file mode 100644index 0000000000..02dcf91648--- /dev/null+++ b/backend/runner/reviewrun/review_funcs_test.go@@ -0,0 +1,20 @@+package reviewrun++import (+ "context"+ "testing"++ "github.com/bytebase/omni/review"+ "github.com/stretchr/testify/require"+)++func TestReviewFuncsEvaluateRules(t *testing.T) {+ t.Parallel()+ for engine, reviewFunc := range reviewFuncs {+ result, err := reviewFunc(context.Background(), "DELETE FROM t;", review.Options{Rules: []review.Rule{review.RequireWhere}}, []review.Target{{}})+ require.NoError(t, err, engine)+ require.Len(t, result.Findings, 1, engine)+ require.Equal(t, review.RequireWhere, result.Findings[0].Rule, engine)+ require.Equal(t, []int{0}, result.Findings[0].Targets, engine)+ }+}diff --git a/backend/runner/reviewrun/rule_review_test.go b/backend/runner/reviewrun/rule_review_test.goindex ae7e56339f..b914fc8d85 100644--- a/backend/runner/reviewrun/rule_review_test.go+++ b/backend/runner/reviewrun/rule_review_test.go@@ -191,9 +191,9 @@ func TestAggregateUnitErrors(t *testing.T) {require.EqualError(t, err, "4 of 5 review units failed: a; b; c (+1 more)")unit := groupReviewUnits(nil, []*reviewTarget{- target("spec-1", "instances/pg/databases/a", storepb.Engine_POSTGRES, false),- target("spec-1", "instances/pg/databases/b", storepb.Engine_POSTGRES, false),+ target("spec-1", "instances/ch/databases/a", storepb.Engine_CLICKHOUSE, false),+ target("spec-1", "instances/ch/databases/b", storepb.Engine_CLICKHOUSE, false),})[0]- err = aggregateUnitErrors(2, unit.failures(errors.New("engine POSTGRES has no standard rule reviewer")))- require.EqualError(t, err, "2 of 2 review units failed: instances/pg/databases/a: engine POSTGRES has no standard rule reviewer; instances/pg/databases/b: engine POSTGRES has no standard rule reviewer")+ err = aggregateUnitErrors(2, unit.failures(errors.New("engine CLICKHOUSE has no standard rule reviewer")))+ require.EqualError(t, err, "2 of 2 review units failed: instances/ch/databases/a: engine CLICKHOUSE has no standard rule reviewer; instances/ch/databases/b: engine CLICKHOUSE has no standard rule reviewer")}diff --git a/backend/tests/review_run_lifecycle_test.go b/backend/tests/review_run_lifecycle_test.goindex 722ef09aa2..549e0d8035 100644--- a/backend/tests/review_run_lifecycle_test.go+++ b/backend/tests/review_run_lifecycle_test.go@@ -99,15 +99,12 @@ func TestCollision_RunReviewLifecycle(t *testing.T) {a.Equal(v1pb.ReviewRun_AVAILABLE, runB.Status)// The scheduler claims and executes both. The rule executor evaluates- // the real test databases through omni's SQL Review V2 contract; until- // omni ships this engine's review package, the run fails honestly rather- // than reporting a vacuous DONE. Flip these to DONE when it registers.+ // the real test databases through omni's SQL Review V2 contract.rowA := waitReviewRunTerminal(ctx, t, ctl, projectAID, issueAUID, "RULE")- a.Equal("FAILED", rowA.Status, "rule review on project A, got payload %s", rowA.Payload)- a.Contains(rowA.Payload, "has no standard rule reviewer")+ a.Equal("DONE", rowA.Status, "rule review on project A, got payload %s", rowA.Payload)a.Equal(int64(0), rowA.Attempt)rowB := waitReviewRunTerminal(ctx, t, ctl, projectBID, issueBUID, "RULE")- a.Equal("FAILED", rowB.Status, "rule review on project B, got payload %s", rowB.Payload)+ a.Equal("DONE", rowB.Status, "rule review on project B, got payload %s", rowB.Payload)a.Equal(int64(0), rowB.Attempt)// Re-running A bumps only A's attempt; B's colliding slot is untouched.@@ -118,7 +115,7 @@ func TestCollision_RunReviewLifecycle(t *testing.T) {a.Equal(v1pb.ReviewRun_AVAILABLE, runA2.Status)rowA2 := waitReviewRunTerminal(ctx, t, ctl, projectAID, issueAUID, "RULE")a.Equal(int64(1), rowA2.Attempt)- a.Equal("FAILED", rowA2.Status)+ a.Equal("DONE", rowA2.Status)afterB := listReviewRuns(ctx, t, ctl, projectBID)a.Equal(beforeB, afterB, "project B review_run rows must be untouched by A's re-run")@@ -154,7 +151,7 @@ func TestCollision_RunReviewLifecycle(t *testing.T) {// The failed AI run left A's rule slot alone.rowA3 := waitReviewRunTerminal(ctx, t, ctl, projectAID, issueAUID, "RULE")a.Equal(int64(1), rowA3.Attempt)- a.Equal("FAILED", rowA3.Status)+ a.Equal("DONE", rowA3.Status)// A table in A's database for the model to read through the tools.pgContainer, err := pgContainerOf(fixture.Instance)diff --git a/frontend/src/locales/sql-review/en-US.json b/frontend/src/locales/sql-review/en-US.jsonindex a88feb900d..a3264ee15f 100644--- a/frontend/src/locales/sql-review/en-US.json+++ b/frontend/src/locales/sql-review/en-US.json@@ -760,11 +760,11 @@"title": "Dropping constraints"},"disallow-drop-object": {- "description": "Flags DROP TABLE, COLUMN, SCHEMA, or DATABASE.",+ "description": "Flags dropping any object, such as a table, column, view, index, schema, or database. Dropping a constraint is covered separately.","title": "Dropping objects"},"disallow-rename": {- "description": "Flags renaming a table or column.",+ "description": "Flags renaming a table, view, or column.","title": "Renaming"},"disallow-truncate": {diff --git a/frontend/src/locales/sql-review/es-ES.json b/frontend/src/locales/sql-review/es-ES.jsonindex 23387cb563..03910a1595 100644--- a/frontend/src/locales/sql-review/es-ES.json+++ b/frontend/src/locales/sql-review/es-ES.json@@ -760,11 +760,11 @@"title": "Eliminación de restricciones"},"disallow-drop-object": {- "description": "Señala DROP TABLE, COLUMN, SCHEMA o DATABASE.",+ "description": "Señala la eliminación de cualquier objeto, como una tabla, columna, vista, índice, esquema o base de datos. La eliminación de restricciones se revisa por separado.","title": "Eliminación de objetos"},"disallow-rename": {- "description": "Señala el cambio de nombre de una tabla o columna.",+ "description": "Señala el cambio de nombre de una tabla, vista o columna.","title": "Cambio de nombre"},"disallow-truncate": {diff --git a/frontend/src/locales/sql-review/ja-JP.json b/frontend/src/locales/sql-review/ja-JP.jsonindex 307d63b89f..8d18cad47f 100644--- a/frontend/src/locales/sql-review/ja-JP.json+++ b/frontend/src/locales/sql-review/ja-JP.json@@ -760,11 +760,11 @@"title": "制約の削除"},"disallow-drop-object": {- "description": "DROP TABLE、COLUMN、SCHEMA、DATABASE を検出します。",+ "description": "テーブル、列、ビュー、インデックス、スキーマ、データベースなど、あらゆるオブジェクトの削除を検出します。制約の削除は別のルールで検出します。","title": "オブジェクトの削除"},"disallow-rename": {- "description": "テーブルまたは列の名前変更を検出します。",+ "description": "テーブル、ビュー、または列の名前変更を検出します。","title": "名前の変更"},"disallow-truncate": {diff --git a/frontend/src/locales/sql-review/vi-VN.json b/frontend/src/locales/sql-review/vi-VN.jsonindex aa895c4f0a..0bd881c1f0 100644--- a/frontend/src/locales/sql-review/vi-VN.json+++ b/frontend/src/locales/sql-review/vi-VN.json@@ -760,11 +760,11 @@"title": "Xóa ràng buộc"},"disallow-drop-object": {- "description": "Đánh dấu DROP TABLE, COLUMN, SCHEMA hoặc DATABASE.",+ "description": "Đánh dấu việc xóa bất kỳ đối tượng nào, như bảng, cột, view, chỉ mục, schema hoặc cơ sở dữ liệu. Việc xóa ràng buộc được kiểm tra riêng.","title": "Xóa đối tượng"},"disallow-rename": {- "description": "Đánh dấu việc đổi tên bảng hoặc cột.",+ "description": "Đánh dấu việc đổi tên bảng, view hoặc cột.","title": "Đổi tên"},"disallow-truncate": {diff --git a/frontend/src/locales/sql-review/zh-CN.json b/frontend/src/locales/sql-review/zh-CN.jsonindex dda8cde57e..5b664df5b1 100644--- a/frontend/src/locales/sql-review/zh-CN.json+++ b/frontend/src/locales/sql-review/zh-CN.json@@ -760,11 +760,11 @@"title": "删除约束"},"disallow-drop-object": {- "description": "标记 DROP TABLE、COLUMN、SCHEMA 或 DATABASE。",+ "description": "标记删除任意对象的操作,例如表、列、视图、索引、模式或数据库。删除约束由单独的规则检查。","title": "删除对象"},"disallow-rename": {- "description": "标记重命名表或列的操作。",+ "description": "标记重命名表、视图或列的操作。","title": "重命名"},"disallow-truncate": {diff --git a/frontend/src/types/proto-es/v1/review_rule_pb.d.ts b/frontend/src/types/proto-es/v1/review_rule_pb.d.tsindex 6abbd0ddaf..bb9f14e647 100644--- a/frontend/src/types/proto-es/v1/review_rule_pb.d.ts+++ b/frontend/src/types/proto-es/v1/review_rule_pb.d.ts@@ -73,7 +73,9 @@ export enum ReviewRuleType {REQUIRE_WHERE = 6,/**- * P1: DROP TABLE, COLUMN, SCHEMA, or DATABASE.+ * P1: dropping any object, such as a table, column, view, index, sequence,+ * schema, database, or function. Dropping a constraint is+ * DISALLOW_DROP_CONSTRAINT.** @generated from enum value: DISALLOW_DROP_OBJECT = 7;*/@@ -94,7 +96,7 @@ export enum ReviewRuleType {DISALLOW_DROP_CONSTRAINT = 9,/**- * P1: renaming a table or column.+ * P1: renaming a table, foreign table, view, materialized view, or column.** @generated from enum value: DISALLOW_RENAME = 10;*/diff --git a/go.mod b/go.modindex 0178100c3f..25c006c88a 100644--- a/go.mod+++ b/go.mod@@ -36,7 +36,7 @@ require (github.com/bmatcuk/doublestar/v4 v4.10.0github.com/bytebase/gomongo v0.0.0-20260730033313-67ba6e249735github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0- github.com/bytebase/omni v0.0.0-20260920103048-3165d7e5a683+ github.com/bytebase/omni v0.0.0-20261016090414-431fd0dff942github.com/caarlos0/env/v11 v11.4.1github.com/cenkalti/backoff/v7 v7.0.0github.com/cockroachdb/cockroach-go/v2 v2.4.3diff --git a/go.sum b/go.sumindex e49af43d3e..d888aeaf57 100644--- a/go.sum+++ b/go.sum@@ -252,8 +252,8 @@ github.com/bytebase/gomongo v0.0.0-20260730033313-67ba6e249735 h1:v8y6mXeHmYVsdMgithub.com/bytebase/gomongo v0.0.0-20260730033313-67ba6e249735/go.mod h1:vTHjcvfn8Pmf65WjnV1ytTCYyC7xNhFjrniv4YWvtA8=github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0 h1:bJ8NSf2K+pccl5m/wuu97fiYjDwpJH6IzURAq/3XA2U=github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0/go.mod h1:BEWMfiZtqshdmulKJcIsWb45MUaEvDO4CROcgi8dfFg=-github.com/bytebase/omni v0.0.0-20260920103048-3165d7e5a683 h1:qPDr0tbTRnhhWbmwlDf0yfVLAtWGyh9KT5YzT5ZLCJ4=-github.com/bytebase/omni v0.0.0-20260920103048-3165d7e5a683/go.mod h1:9XZE1hqtvr09Oc+DdLu1/yCb8MDcoy/EPdA4AONDHlE=+github.com/bytebase/omni v0.0.0-20261016090414-431fd0dff942 h1:9AYkMDev4UcDaYyrJk2cqymYxJYrQLEyHXX85I2XRMc=+github.com/bytebase/omni v0.0.0-20261016090414-431fd0dff942/go.mod h1:9XZE1hqtvr09Oc+DdLu1/yCb8MDcoy/EPdA4AONDHlE=github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767 h1:YuR5G3LcxpO5ScSTA+Kdirxg9RW4TRc/v1t7N2Hfmbw=github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=github.com/bytebase/pkcs8 v0.0.0-20240612095628-fcd0a7484c94 h1:6PNsuNmSqCuR8Z616uQLzDIvujWCFsKzeVc3ECmVubk=diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex e6d7218a5e..9fc14ad68f 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -3385,10 +3385,10 @@ needs a person's acceptance, not that it is forbidden.| PRIOR_BACKUP | 4 | P0: the change enables prior backup but the backup cannot be taken. || REQUIRE_IS_NULL | 5 | P0: = NULL or <> NULL in a predicate, which is always false. Test for NULL with IS NULL or IS NOT NULL. || REQUIRE_WHERE | 6 | P1: UPDATE or DELETE without WHERE. |-| DISALLOW_DROP_OBJECT | 7 | P1: DROP TABLE, COLUMN, SCHEMA, or DATABASE. |+| DISALLOW_DROP_OBJECT | 7 | P1: dropping any object, such as a table, column, view, index, sequence, schema, database, or function. Dropping a constraint is DISALLOW_DROP_CONSTRAINT. || DISALLOW_TRUNCATE | 8 | P1: TRUNCATE. || DISALLOW_DROP_CONSTRAINT | 9 | P1: dropping a PRIMARY KEY, FOREIGN KEY, UNIQUE, or CHECK constraint. |-| DISALLOW_RENAME | 10 | P1: renaming a table or column. |+| DISALLOW_RENAME | 10 | P1: renaming a table, foreign table, view, materialized view, or column. || REQUIRE_PRIMARY_KEY | 11 | P1: the change creates a table without a primary key, or drops a primary key without adding one back. A table that already lacked a primary key before the change is not reported. |diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.htmlindex 542f1e2dea..e3729a4e78 100644--- a/proto/gen/grpc-doc/v1/index.html+++ b/proto/gen/grpc-doc/v1/index.html@@ -10418,7 +10418,9 @@ NULL with IS NULL or IS NOT NULL.</p></td><tr><td>DISALLOW_DROP_OBJECT</td><td>7</td>- <td><p>P1: DROP TABLE, COLUMN, SCHEMA, or DATABASE.</p></td>+ <td><p>P1: dropping any object, such as a table, column, view, index, sequence,+schema, database, or function. Dropping a constraint is+DISALLOW_DROP_CONSTRAINT.</p></td></tr><tr>@@ -10436,7 +10438,7 @@ NULL with IS NULL or IS NOT NULL.</p></td><tr><td>DISALLOW_RENAME</td><td>10</td>- <td><p>P1: renaming a table or column.</p></td>+ <td><p>P1: renaming a table, foreign table, view, materialized view, or column.</p></td></tr><tr>diff --git a/proto/v1/v1/review_rule.proto b/proto/v1/v1/review_rule.protoindex 651648cffe..7f45e80587 100644--- a/proto/v1/v1/review_rule.proto+++ b/proto/v1/v1/review_rule.proto@@ -31,13 +31,15 @@ enum ReviewRuleType {// P1: UPDATE or DELETE without WHERE.REQUIRE_WHERE = 6;- // P1: DROP TABLE, COLUMN, SCHEMA, or DATABASE.+ // P1: dropping any object, such as a table, column, view, index, sequence,+ // schema, database, or function. Dropping a constraint is+ // DISALLOW_DROP_CONSTRAINT.DISALLOW_DROP_OBJECT = 7;// P1: TRUNCATE.DISALLOW_TRUNCATE = 8;// P1: dropping a PRIMARY KEY, FOREIGN KEY, UNIQUE, or CHECK constraint.DISALLOW_DROP_CONSTRAINT = 9;- // P1: renaming a table or column.+ // P1: renaming a table, foreign table, view, materialized view, or column.DISALLOW_RENAME = 10;// P1: the change creates a table without a primary key, or drops a// primary key without adding one back. A table that already lacked a