Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(review): run WALK_THROUGH on MariaDB, TiDB, MSSQL, and Oracle (#21693)
rebelice0d89f8d15ff8
diff --git a/backend/plugin/advisor/mssql/rule_statement_where_disallow_functions_and_calculations.go b/backend/plugin/advisor/mssql/rule_statement_where_disallow_functions_and_calculations.goindex 3e5ddcd788..41f34f3923 100644--- a/backend/plugin/advisor/mssql/rule_statement_where_disallow_functions_and_calculations.go+++ b/backend/plugin/advisor/mssql/rule_statement_where_disallow_functions_and_calculations.go@@ -150,41 +150,13 @@ func (r *disallowFuncAndCalcOmniRule) checkMerge(n *ast.MergeStmt) {if ref, ok := n.Target.(*ast.TableRef); ok {addTableRef(r, tables, ref)}- // Extract source tables (can be TableRef, SubqueryExpr, JoinClause, etc.).+ // The source is one FROM item carrying its own alias: a table, a derived+ // table, or a join. Its nested SELECTs are checked in their own scope.if n.Source != nil {- if ref, ok := n.Source.(*ast.TableRef); ok {- // Bare table source: honor SourceAlias if set, otherwise use the ref's own alias/object.- if n.SourceAlias != "" {- tables[r.normalizeIdent(n.SourceAlias)] = tableRef{database: ref.Database, schema: ref.Schema, object: ref.Object}- } else {- addTableRef(r, tables, ref)- }- } else {- // Non-TableRef source (subquery, join, etc.). Recurse into the inner SELECT- // in its own scope. When SourceAlias is set, register it as an opaque entry- // so qualified refs like `src.col` resolve to no indexed columns (safely- // returning false) rather than falling through to cross-table matches.- if n.SourceAlias != "" {- tables[r.normalizeIdent(n.SourceAlias)] = tableRef{}- }- ast.Inspect(n.Source, func(m ast.Node) bool {- if sub, ok := m.(*ast.SelectStmt); ok {- r.checkSelect(sub)- return false- }- if _, ok := m.(*ast.SubqueryExpr); ok {- return true- }- // When there's a SourceAlias, don't leak inner TableRefs into outer scope.- if _, ok := m.(*ast.TableRef); ok {- if n.SourceAlias == "" {- addTableRef(r, tables, m.(*ast.TableRef))- }- return false- }- return true- })+ for alias, ref := range r.collectTableNamesFromList(&ast.List{Items: []ast.Node{n.Source}}) {+ tables[alias] = ref}+ r.recurseIntoNestedSelectsInNode(n.Source, nil)}r.checkWhere(n.OnCondition, tables)if n.WhenClauses != nil {diff --git a/backend/plugin/advisor/mssql/test/statement_where_disallow_functions_and_calculations.yaml b/backend/plugin/advisor/mssql/test/statement_where_disallow_functions_and_calculations.yamlindex 9d10b29508..fa981a914a 100644--- a/backend/plugin/advisor/mssql/test/statement_where_disallow_functions_and_calculations.yaml+++ b/backend/plugin/advisor/mssql/test/statement_where_disallow_functions_and_calculations.yaml@@ -326,7 +326,7 @@column: 0endposition: null-# Test (adversarial): MERGE with SourceAlias — alias in WHEN condition should resolve.+# Test (adversarial): MERGE with a source alias — alias in WHEN condition should resolve.- statement: |-MERGE INTO pokes2 AS tgtUSING pokes AS src@@ -343,6 +343,23 @@column: 0endposition: null+# Test: MERGE target without an alias — USING is not its alias, so the table name resolves.+- statement: |-+ MERGE INTO pokes+ USING pokes2 AS src+ ON pokes.c1 = src.foo+ WHEN MATCHED AND ABS(pokes.c1) > 0 THEN UPDATE SET bar = 0;+ changeType: 1+ want:+ - status: 2+ code: 234+ title: STATEMENT_WHERE_DISALLOW_FUNCTIONS_AND_CALCULATIONS+ content: "Function \"ABS\" is applied to indexed column \"c1\" in the WHERE clause, which prevents index usage"+ startposition:+ line: 4+ column: 0+ endposition: null+# Test (adversarial high): Case-insensitive match — ABS(C1) on indexed `c1`.- statement: SELECT c1 FROM pokes WHERE ABS(C1) > 5;changeType: 1diff --git a/backend/runner/reviewrun/rule_executor.go b/backend/runner/reviewrun/rule_executor.goindex 642d26cdb5..3dac21d6e0 100644--- a/backend/runner/reviewrun/rule_executor.go+++ b/backend/runner/reviewrun/rule_executor.go@@ -80,6 +80,7 @@ func (e *RuleExecutor) RunOnce(ctx context.Context, projectID string, issueUID i}targets = append(targets, target)}+ markOtherSpecs(targets)var comments []*store.IssueCommentMessagesheets := make(map[string]string)diff --git a/backend/runner/reviewrun/rule_review.go b/backend/runner/reviewrun/rule_review.goindex 901b61dee6..779e283388 100644--- a/backend/runner/reviewrun/rule_review.go+++ b/backend/runner/reviewrun/rule_review.go@@ -39,6 +39,24 @@ func reviewRules(policy *storepb.ReviewRulePolicy) []review.Rule {return rules}+// markOtherSpecs sets OtherSpecs on each target whose database another spec+// of the plan also changes. Such specs run in no fixed order (only release+// tasks are sequential), so neither may assume it meets the synced schema.+// Check.Target names a database in one form only: ResolveDatabaseTarget+// rejects the other.+func markOtherSpecs(targets []*reviewTarget) {+ specs := make(map[string]map[string]bool)+ for _, target := range targets {+ if specs[target.Check.Target] == nil {+ specs[target.Check.Target] = make(map[string]bool)+ }+ specs[target.Check.Target][target.Check.SpecID] = true+ }+ for _, target := range targets {+ target.Input.OtherSpecs = len(specs[target.Check.Target]) > 1+ }+}+// groupReviewUnits folds the targets into one unit per (spec, engine), in// first-seen order. The change's requested behaviors are read from the first// target: they come from the spec and its sheet, so every target of a specdiff --git a/backend/runner/reviewrun/rule_review_test.go b/backend/runner/reviewrun/rule_review_test.goindex b914fc8d85..6757df6835 100644--- a/backend/runner/reviewrun/rule_review_test.go+++ b/backend/runner/reviewrun/rule_review_test.go@@ -86,6 +86,22 @@ func TestGroupReviewUnits(t *testing.T) {require.Equal(t, []string{"instances/pg/databases/c"}, targetNames(units[2]))}+func TestMarkOtherSpecs(t *testing.T) {+ t.Parallel()+ shared1 := target("spec-1", "instances/pg/databases/a", storepb.Engine_POSTGRES, false)+ own := target("spec-1", "instances/pg/databases/b", storepb.Engine_POSTGRES, false)+ shared2 := target("spec-2", "instances/pg/databases/a", storepb.Engine_POSTGRES, false)+ repeated1 := target("spec-3", "instances/pg/databases/c", storepb.Engine_POSTGRES, false)+ repeated2 := target("spec-3", "instances/pg/databases/c", storepb.Engine_POSTGRES, false)+ markOtherSpecs([]*reviewTarget{shared1, own, shared2, repeated1, repeated2})++ require.True(t, shared1.Input.OtherSpecs)+ require.True(t, shared2.Input.OtherSpecs)+ require.False(t, own.Input.OtherSpecs)+ require.False(t, repeated1.Input.OtherSpecs, "one spec naming a database twice is still one spec")+ require.False(t, repeated2.Input.OtherSpecs)+}+func targetNames(unit *reviewUnit) []string {var names []stringfor _, target := range unit.Targets {diff --git a/go.mod b/go.modindex f60dc23188..4f5488bf19 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-20261026083107-25cc3c3b45bd+ github.com/bytebase/omni v0.0.0-20261028062602-59f0194f8502github.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 063df968f8..dc847b0911 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-20261026083107-25cc3c3b45bd h1:Mp5RLIccvrgW/jkK2MgYx3+Kh+wr/03yYFntb/F3Um0=-github.com/bytebase/omni v0.0.0-20261026083107-25cc3c3b45bd/go.mod h1:9XZE1hqtvr09Oc+DdLu1/yCb8MDcoy/EPdA4AONDHlE=+github.com/bytebase/omni v0.0.0-20261028062602-59f0194f8502 h1:sVl3/7PRraXNpT3i0vfDHkwfCcosLEwvakDIg2OZZyM=+github.com/bytebase/omni v0.0.0-20261028062602-59f0194f8502/go.mod h1:9XZE1hqtvr09Oc+DdLu1/yCb8MDcoy/EPdA4AONDHlE=github.com/bytebase/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=