Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: also check foreign key name for compatibility (#9347)
zll60079ef38028528
diff --git a/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go b/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.goindex 6a85d0f629..8e45a2273f 100644--- a/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go+++ b/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go@@ -179,6 +179,11 @@ func (checker *namingFKConventionChecker) handleConstraintDef(tableName string,}indexName := ""+ // for compatibility.+ if ctx.IndexName() != nil {+ indexName = mysqlparser.NormalizeIndexName(ctx.IndexName())+ }+ // use constraint_name if both exist at the same time.// for mysql, foreign key use constraint name as unique identifier.if ctx.ConstraintName() != nil {indexName = mysqlparser.NormalizeConstraintName(ctx.ConstraintName())diff --git a/backend/plugin/advisor/mysql/test/naming_index_fk.yaml b/backend/plugin/advisor/mysql/test/naming_index_fk.yamlindex eb56823084..f5bba48227 100644--- a/backend/plugin/advisor/mysql/test/naming_index_fk.yaml+++ b/backend/plugin/advisor/mysql/test/naming_index_fk.yaml@@ -1,3 +1,11 @@+- 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;+ want:+ - status: WARN+ code: 305+ title: naming.index.fk+ content: Foreign key in table `userTable` mismatches the naming convention, expect "^$|^fk_userTable_roomId_room_id$" but found `fk1`+ line: 1+ details: ""- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id);want:- status: SUCCESS@@ -32,7 +40,7 @@CREATE TABLE book(id INT,author_id INT,- FOREIGN KEY fk_book_author_id_author_id (author_id) REFERENCES author (id)+ FOREIGN KEY fk_book_author_id_author_id (author_id) REFERENCES author (id));want:- status: SUCCESS@@ -61,9 +69,9 @@FOREIGN KEY fk_book_author_id (author_id) REFERENCES author (id));want:- - status: SUCCESS- code: 0- title: OK- content: ""- line: 0+ - status: WARN+ code: 305+ title: naming.index.fk+ content: Foreign key in table `book` mismatches the naming convention, expect "^$|^fk_book_author_id_author_id$" but found `fk_book_author_id`+ line: 4details: ""