Skip to content

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

chore: warning for walkthrough refernece other database (#16717)

rebelice063b57caeccd
diff --git a/backend/plugin/advisor/catalog/walk_through.go b/backend/plugin/advisor/catalog/walk_through.go
index 031c3705c1..9ad34d4cb0 100644
--- a/backend/plugin/advisor/catalog/walk_through.go
+++ b/backend/plugin/advisor/catalog/walk_through.go
@@ -47,6 +47,8 @@ const (
ErrorTypeAccessOtherDatabase = 201
// ErrorTypeDatabaseIsDeleted is the error that try to access the deleted database.
ErrorTypeDatabaseIsDeleted = 202
+ // ErrorTypeReferenceOtherDatabase is the error that try to reference other database.
+ ErrorTypeReferenceOtherDatabase = 203
// 301 ~ 399 table error type.
@@ -963,7 +965,12 @@ func (d *DatabaseState) dropTable(node *tidbast.DropTableStmt) *WalkThroughError
func (d *DatabaseState) copyTable(node *tidbast.CreateTableStmt) *WalkThroughError {
targetTable, err := d.findTableState(node.ReferTable)
if err != nil {
- return err
+ if err.Type == ErrorTypeAccessOtherDatabase {
+ return &WalkThroughError{
+ Type: ErrorTypeReferenceOtherDatabase,
+ Content: fmt.Sprintf("Reference table `%s` in other database `%s`, skip walkthrough", node.ReferTable.Name.O, node.ReferTable.Schema.O),
+ }
+ }
}
schema := d.schemaSet[""]
diff --git a/backend/plugin/advisor/code.go b/backend/plugin/advisor/code.go
index bf6d918f62..e5a9a37692 100644
--- a/backend/plugin/advisor/code.go
+++ b/backend/plugin/advisor/code.go
@@ -132,10 +132,11 @@ const (
NoCollation Code = 617
// 701 ~ 799 database advisor error code.
- DatabaseNotEmpty Code = 701
- NotCurrentDatabase Code = 702
- DatabaseIsDeleted Code = 703
- DatabaseNotExists Code = 704
+ DatabaseNotEmpty Code = 701
+ NotCurrentDatabase Code = 702
+ DatabaseIsDeleted Code = 703
+ DatabaseNotExists Code = 704
+ ReferenceOtherDatabase Code = 705
// 801 ~ 899 index error code.
NotUseIndex Code = 801
diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.go
index 23ece5e34e..830efc1c4d 100644
--- a/backend/plugin/advisor/sql_review.go
+++ b/backend/plugin/advisor/sql_review.go
@@ -667,6 +667,14 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Content: walkThroughError.Content,
StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
+ case catalog.ErrorTypeReferenceOtherDatabase:
+ res = append(res, &storepb.Advice{
+ Status: storepb.Advice_WARNING,
+ Code: ReferenceOtherDatabase.Int32(),
+ Title: "Reference other database",
+ Content: walkThroughError.Content,
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
+ })
case catalog.ErrorTypeTableExists:
res = append(res, &storepb.Advice{
Status: storepb.Advice_ERROR,