Skip to content

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

fix: add baseLine for each statement (#8919)

zll600b581f1e58241
diff --git a/backend/plugin/advisor/mysqlwip/advisor_naming_table.go b/backend/plugin/advisor/mysqlwip/advisor_naming_table.go
index 569d99a464..9a20eae2f6 100644
--- a/backend/plugin/advisor/mysqlwip/advisor_naming_table.go
+++ b/backend/plugin/advisor/mysqlwip/advisor_naming_table.go
@@ -51,6 +51,7 @@ func (*NamingTableConventionAdvisor) Check(ctx advisor.Context, _ string) ([]adv
}
for _, stmt := range list {
+ checker.baseLine = stmt.BaseLine
antlr.ParseTreeWalkerDefault.Walk(checker, stmt.Tree)
}
return checker.generateAdvice()
@@ -59,6 +60,7 @@ func (*NamingTableConventionAdvisor) Check(ctx advisor.Context, _ string) ([]adv
type namingTableConventionChecker struct {
*mysql.BaseMySQLParserListener
+ baseLine int
adviceList []advisor.Advice
level advisor.Status
title string
@@ -123,6 +125,7 @@ func (checker *namingTableConventionChecker) EnterRenameTableStatement(ctx *mysq
}
func (checker *namingTableConventionChecker) handleTableName(tableName string, lineNumber int) {
+ lineNumber += checker.baseLine
if !checker.format.MatchString(tableName) {
checker.adviceList = append(checker.adviceList, advisor.Advice{
Status: checker.level,
diff --git a/backend/plugin/advisor/mysqlwip/test/naming_table.yaml b/backend/plugin/advisor/mysqlwip/test/naming_table.yaml
index 2336e69666..046cd2c40a 100644
--- a/backend/plugin/advisor/mysqlwip/test/naming_table.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/naming_table.yaml
@@ -22,15 +22,19 @@
content: "`cjnubexocfhqoogdmihudyahmmghviqkzvpixnwvxtxumvuannpwdcbtsgwrvzpde` mismatches table naming convention, its length should be within 64 characters"
line: 1
details: ""
-- statement: ALTER TABLE tech_book RENAME TO TechBook;
+- statement: |
+ CREATE TABLE tech_book(a INT);
+ ALTER TABLE tech_book RENAME TO TechBook;
want:
- status: WARN
code: 301
title: naming.table
content: '`TechBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
- line: 1
+ line: 2
details: ""
-- statement: ALTER TABLE tech_book RENAME TO tech_book_copy;
+- statement: |
+ CREATE TABLE tech_book(a INT);
+ ALTER TABLE tech_book RENAME TO tech_book_copy;
want:
- status: SUCCESS
code: 0
@@ -38,32 +42,36 @@
content: ""
line: 0
details: ""
-- statement: RENAME TABLE tech_book TO tech_book_copy, tech_book_copy TO LiteraryBook;
+- statement: |
+ CREATE TABLE tech_book (a INT);
+ RENAME TABLE tech_book TO tech_book_copy, tech_book_copy TO LiteraryBook;
want:
- status: WARN
code: 301
title: naming.table
content: '`LiteraryBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
- line: 1
+ line: 2
details: ""
- statement: |
CREATE TABLE literary_book(a int);
+ CREATE TABLE tech_book(a int);
RENAME TABLE tech_book TO TechBook, literary_book TO LiteraryBook;
want:
- status: WARN
code: 301
title: naming.table
content: '`LiteraryBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
- line: 2
+ line: 3
details: ""
- status: WARN
code: 301
title: naming.table
content: '`TechBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
- line: 2
+ line: 3
details: ""
- statement: |
CREATE TABLE literary_book(a int);
+ CREATE TABLE teck_book(a int);
RENAME TABLE tech_book TO tech_book_copy, literary_book TO literary_book_copy;
want:
- status: SUCCESS