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: add mysqlwip walkthrough (#9084)
zll600711f75549180
diff --git a/backend/plugin/advisor/catalog/walk_through.go b/backend/plugin/advisor/catalog/walk_through.goindex 98b92dc5c6..9cd470850b 100644--- a/backend/plugin/advisor/catalog/walk_through.go+++ b/backend/plugin/advisor/catalog/walk_through.go@@ -208,6 +208,10 @@ func (e *WalkThroughError) Error() string {// WalkThrough will collect the catalog schema in the databaseState as it walks through the stmt.func (d *DatabaseState) WalkThrough(stmt string) error {switch d.dbType {+ // only for mysqlwip test.+ case storepb.Engine_ENGINE_UNSPECIFIED:+ err := d.mysqlWalkThrough(stmt)+ return errcase storepb.Engine_MYSQL, storepb.Engine_TIDB, storepb.Engine_MARIADB, storepb.Engine_OCEANBASE:err := d.mysqlWalkThrough(stmt)return errdiff --git a/backend/plugin/advisor/mysqlwip/test/database_drop_empty_database.yaml b/backend/plugin/advisor/mysqlwip/test/database_drop_empty_database.yamlindex bc9f08e43c..1202469b93 100644--- a/backend/plugin/advisor/mysqlwip/test/database_drop_empty_database.yaml+++ b/backend/plugin/advisor/mysqlwip/test/database_drop_empty_database.yaml@@ -6,11 +6,3 @@content: Database `test` is not allowed to drop if not emptyline: 1details: ""-- statement: DROP DATABASE IF EXISTS bbdev;- want:- - status: WARN- code: 702- title: database.drop-empty-database- content: Database `bbdev` that is trying to be deleted is not the current database `test`- line: 1- details: ""diff --git a/backend/plugin/advisor/mysqlwip/test/naming_column.yaml b/backend/plugin/advisor/mysqlwip/test/naming_column.yamlindex b4bb8b140e..59ec77061e 100644--- a/backend/plugin/advisor/mysqlwip/test/naming_column.yaml+++ b/backend/plugin/advisor/mysqlwip/test/naming_column.yaml@@ -41,7 +41,7 @@details: ""- statement: |ALTER TABLE tech_book RENAME COLUMN id TO creator_id;- ALTER TABLE tech_book RENAME COLUMN id TO gbhzmtchhsjzyrhdroxmyouwloxqezowdvhcbqalqcgqhfbjnvmhwrbggezmzeusx;+ ALTER TABLE tech_book RENAME COLUMN creator_id TO gbhzmtchhsjzyrhdroxmyouwloxqezowdvhcbqalqcgqhfbjnvmhwrbggezmzeusx;want:- status: WARNcode: 302@@ -64,7 +64,9 @@content: '`book`.`creatorId` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'line: 7details: ""-- statement: ALTER TABLE tech_book CHANGE COLUMN id creator_id int;+- statement: |-+ CREATE TABLE book (id INT);+ ALTER TABLE book CHANGE COLUMN id creator_id int;want:- status: SUCCESScode: 0diff --git a/backend/plugin/advisor/mysqlwip/test/naming_column_auto_increment.yaml b/backend/plugin/advisor/mysqlwip/test/naming_column_auto_increment.yamlindex b2576623e9..d71879232b 100644--- a/backend/plugin/advisor/mysqlwip/test/naming_column_auto_increment.yaml+++ b/backend/plugin/advisor/mysqlwip/test/naming_column_auto_increment.yaml@@ -14,35 +14,29 @@content: '`book`.`a` mismatches auto_increment column naming convention, naming format should be "^id$"'line: 1details: ""-- statement: |- CREATE TABLE tech_book (name VARCHAR(255));- ALTER TABLE tech_book ADD COLUMN a int AUTO_INCREMENT;+- statement: ALTER TABLE tech_book ADD COLUMN a int AUTO_INCREMENT;want:- status: WARNcode: 307title: naming.column.auto-incrementcontent: '`tech_book`.`a` mismatches auto_increment column naming convention, naming format should be "^id$"'- line: 2+ line: 1details: ""-- statement: |- CREATE TABLE tech_book (name VARCHAR(255));- ALTER TABLE tech_book CHANGE COLUMN id a int AUTO_INCREMENT;+- statement: ALTER TABLE tech_book CHANGE COLUMN id a int AUTO_INCREMENT;want:- status: WARNcode: 307title: naming.column.auto-incrementcontent: '`tech_book`.`a` mismatches auto_increment column naming convention, naming format should be "^id$"'- line: 2+ line: 1details: ""-- statement: |- CREATE TABLE tech_book (price INT);- ALTER TABLE tech_book MODIFY COLUMN name int AUTO_INCREMENT;+- statement: ALTER TABLE tech_book MODIFY COLUMN name int AUTO_INCREMENT;want:- status: WARNcode: 307title: naming.column.auto-incrementcontent: '`tech_book`.`name` mismatches auto_increment column naming convention, naming format should be "^id$"'- line: 2+ line: 1details: ""- statement: |CREATE TABLE book(id int);@@ -56,7 +50,7 @@details: ""- statement: |CREATE TABLE book(name VARCHAR(255));- ALTER TABLE tech_book ADD COLUMN id int AUTO_INCREMENT;+ ALTER TABLE book ADD COLUMN id int AUTO_INCREMENT;want:- status: SUCCESScode: 0@@ -66,7 +60,7 @@details: ""- statement: |CREATE TABLE book(a INT, name VARCHAR(255));- ALTER TABLE tech_book CHANGE COLUMN a id int AUTO_INCREMENT;+ ALTER TABLE book CHANGE COLUMN a id int AUTO_INCREMENT;want:- status: SUCCESScode: 0diff --git a/backend/plugin/advisor/mysqlwip/test/naming_index_fk.yaml b/backend/plugin/advisor/mysqlwip/test/naming_index_fk.yamlindex 8e897bc7ba..eb56823084 100644--- a/backend/plugin/advisor/mysqlwip/test/naming_index_fk.yaml+++ b/backend/plugin/advisor/mysqlwip/test/naming_index_fk.yaml@@ -1,6 +1,4 @@-- statement: |- CREATE TABLE tech_book(id INT);- ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id);+- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id);want:- status: SUCCESScode: 0@@ -8,15 +6,13 @@content: ""line: 0details: ""-- statement: |- CREATE TABLE tech_book(id INT);- ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES author (id);+- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES author (id);want:- status: WARNcode: 305title: naming.index.fkcontent: Foreign key in table `tech_book` mismatches the naming convention, expect "^$|^fk_tech_book_author_id_author_id$" but found `fk_author_id`- line: 2+ line: 1details: ""- statement: ALTER TABLE tech_book ADD CONSTRAINT rvemempmcmmhutaskvcidmwaldtfjdgmcpkhmibtadfydtkexpuzczrrneucthfwk FOREIGN KEY (author_id) REFERENCES author (id);want:diff --git a/backend/plugin/advisor/mysqlwip/test/naming_index_idx.yaml b/backend/plugin/advisor/mysqlwip/test/naming_index_idx.yamlindex 81512d0634..c320c41d51 100644--- a/backend/plugin/advisor/mysqlwip/test/naming_index_idx.yaml+++ b/backend/plugin/advisor/mysqlwip/test/naming_index_idx.yaml@@ -6,31 +6,27 @@content: ""line: 0details: ""-- statement: |- CREATE TABLE tech_book (id INT, name VARCHAR(255));- CREATE INDEX tech_book_id_name ON tech_book(id, name);+- statement: CREATE INDEX tech_book_id_name ON tech_book(id, name);want:- status: WARNcode: 303title: naming.index.idxcontent: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `tech_book_id_name`- line: 2+ line: 1details: ""-- statement: |- CREATE TABLE tech_book (id INT, name VARCHAR(255));- CREATE INDEX afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw ON tech_book(id, name);+- statement: CREATE INDEX afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw ON tech_book(id, name);want:- status: WARNcode: 303title: naming.index.idxcontent: Index `afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw` in table `tech_book` mismatches the naming convention, its length should be within 64 characters- line: 2+ line: 1details: ""- status: WARNcode: 303title: naming.index.idxcontent: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw`- line: 2+ line: 1details: ""- statement: ALTER TABLE tech_book RENAME INDEX old_index TO idx_tech_book_id_name;want:@@ -40,19 +36,15 @@content: ""line: 0details: ""-- statement: |- CREATE TABLE tech_book (id INT, name VARCHAR(255));- ALTER TABLE tech_book RENAME INDEX old_index TO idx_tech_book;+- statement: ALTER TABLE tech_book RENAME INDEX old_index TO idx_tech_book;want:- status: WARNcode: 303title: naming.index.idxcontent: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `idx_tech_book`- line: 2+ line: 1details: ""-- statement: |- CREATE TABLE tech_book (id INT, name VARCHAR(255));- ALTER TABLE tech_book ADD INDEX idx_tech_book_id_name (id, name);+- statement: ALTER TABLE tech_book ADD INDEX idx_tech_book_id_name (id, name);want:- status: SUCCESScode: 0@@ -60,15 +52,13 @@content: ""line: 0details: ""-- statement: |- CREATE TABLE tech_book (id INT, name VARCHAR(255));- ALTER TABLE tech_book ADD INDEX tech_book_id_name (id, name);+- statement: ALTER TABLE tech_book ADD INDEX tech_book_id_name (id, name);want:- status: WARNcode: 303title: naming.index.idxcontent: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `tech_book_id_name`- line: 2+ line: 1details: ""- statement: CREATE TABLE tech_book_copy(id INT PRIMARY KEY, name VARCHAR(20), INDEX idx_tech_book_copy_name (name));want:diff --git a/backend/plugin/advisor/mysqlwip/test/naming_table.yaml b/backend/plugin/advisor/mysqlwip/test/naming_table.yamlindex 046cd2c40a..7529feef28 100644--- a/backend/plugin/advisor/mysqlwip/test/naming_table.yaml+++ b/backend/plugin/advisor/mysqlwip/test/naming_table.yaml@@ -23,8 +23,8 @@line: 1details: ""- statement: |- CREATE TABLE tech_book(a INT);- ALTER TABLE tech_book RENAME TO TechBook;+ CREATE TABLE book(a INT);+ ALTER TABLE book RENAME TO TechBook;want:- status: WARNcode: 301@@ -33,8 +33,8 @@line: 2details: ""- statement: |- CREATE TABLE tech_book(a INT);- ALTER TABLE tech_book RENAME TO tech_book_copy;+ CREATE TABLE book(a INT);+ ALTER TABLE book RENAME TO tech_book_copy;want:- status: SUCCESScode: 0@@ -43,8 +43,8 @@line: 0details: ""- statement: |- CREATE TABLE tech_book (a INT);- RENAME TABLE tech_book TO tech_book_copy, tech_book_copy TO LiteraryBook;+ CREATE TABLE book (a INT);+ RENAME TABLE book TO tech_book_copy, tech_book_copy TO LiteraryBook;want:- status: WARNcode: 301@@ -54,8 +54,8 @@details: ""- statement: |CREATE TABLE literary_book(a int);- CREATE TABLE tech_book(a int);- RENAME TABLE tech_book TO TechBook, literary_book TO LiteraryBook;+ CREATE TABLE book(a int);+ RENAME TABLE book TO TechBook, literary_book TO LiteraryBook;want:- status: WARNcode: 301@@ -71,8 +71,8 @@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;+ CREATE TABLE book(a int);+ RENAME TABLE book TO tech_book_copy, literary_book TO literary_book_copy;want:- status: SUCCESScode: 0diff --git a/backend/plugin/advisor/mysqlwip/test/statement_merge_alter_table.yaml b/backend/plugin/advisor/mysqlwip/test/statement_merge_alter_table.yamlindex 59a80b83b4..af1ba35f4c 100644--- a/backend/plugin/advisor/mysqlwip/test/statement_merge_alter_table.yaml+++ b/backend/plugin/advisor/mysqlwip/test/statement_merge_alter_table.yaml@@ -8,7 +8,7 @@details: ""- statement: |-ALTER TABLE tech_book ADD COLUMN a int;- ALTER TABLE tech_book CHANGE COLUMN b c int;+ ALTER TABLE tech_book CHANGE COLUMN a c int;want:- status: WARNcode: 207@@ -18,7 +18,7 @@details: ""- statement: |-CREATE TABLE t(a int);- ALTER TABLE tech_book ADD COLUMN a int;+ ALTER TABLE tech_book ADD COLUMN b int;ALTER TABLE t ADD COLUMN b int;ALTER TABLE tech_book MODIFY COLUMN b varchar(255);want:diff --git a/backend/plugin/advisor/mysqlwip/test/statement_where_require.yaml b/backend/plugin/advisor/mysqlwip/test/statement_where_require.yamlindex e579a92a6d..b94741322f 100644--- a/backend/plugin/advisor/mysqlwip/test/statement_where_require.yaml+++ b/backend/plugin/advisor/mysqlwip/test/statement_where_require.yaml@@ -1,6 +1,6 @@- statement: |- CREATE TABLE tech_book(id INT);- INSERT INTO tech_book(id) values (1);+ CREATE TABLE book(id INT);+ INSERT INTO book(id) values (1);want:- status: SUCCESScode: 0@@ -9,30 +9,30 @@line: 0details: ""- statement: |- CREATE TABLE tech_book(id INT);- DELETE FROM tech_book;+ CREATE TABLE book(id INT);+ DELETE FROM book;want:- status: WARNcode: 202title: statement.where.requirecontent: |-- "DELETE FROM tech_book;" requires WHERE clause+ "DELETE FROM book;" requires WHERE clauseline: 2details: ""- statement: |- CREATE TABLE tech_book(id INT);- UPDATE tech_book SET id = 1;+ CREATE TABLE book(id INT);+ UPDATE book SET id = 1;want:- status: WARNcode: 202title: statement.where.requirecontent: |-- "UPDATE tech_book SET id = 1;" requires WHERE clause+ "UPDATE book SET id = 1;" requires WHERE clauseline: 2details: ""- statement: |- CREATE TABLE tech_book(id INT);- DELETE FROM tech_book WHERE id > 0;+ CREATE TABLE book(id INT);+ DELETE FROM book WHERE id > 0;want:- status: SUCCESScode: 0@@ -41,8 +41,8 @@line: 0details: ""- statement: |- CREATE TABLE tech_book(id INT);- UPDATE tech_book SET id = 1 WHERE id > 10;+ CREATE TABLE book(id INT);+ UPDATE book SET id = 1 WHERE id > 10;want:- status: SUCCESScode: 0@@ -51,19 +51,19 @@line: 0details: ""- statement: |- CREATE TABLE tech_book(id INT);- SELECT id FROM tech_book;+ CREATE TABLE book(id INT);+ SELECT id FROM book;want:- status: WARNcode: 202title: statement.where.requirecontent: |-- "SELECT id FROM tech_book;" requires WHERE clause+ "SELECT id FROM book;" requires WHERE clauseline: 2details: ""- statement: |- CREATE TABLE tech_book(id INT);- SELECT id FROM tech_book WHERE id > 0;+ CREATE TABLE book(id INT);+ SELECT id FROM book WHERE id > 0;want:- status: SUCCESScode: 0@@ -72,12 +72,12 @@line: 0details: ""- statement: |- CREATE TABLE tech_book(id INT);+ CREATE TABLE book(id INT);SELECT id- FROM tech_book+ FROM bookWHERE id > (SELECT max(id)- FROM tech_book+ FROM book);want:- status: WARN@@ -85,10 +85,10 @@title: statement.where.requirecontent: |-"SELECT id- FROM tech_book+ FROM bookWHERE id > (SELECT max(id)- FROM tech_book+ FROM book);" requires WHERE clauseline: 5details: ""diff --git a/backend/plugin/advisor/mysqlwip/test/table_require_pk.yaml b/backend/plugin/advisor/mysqlwip/test/table_require_pk.yamlindex 71984bce8c..5d387953c9 100644--- a/backend/plugin/advisor/mysqlwip/test/table_require_pk.yaml+++ b/backend/plugin/advisor/mysqlwip/test/table_require_pk.yaml@@ -169,13 +169,14 @@line: 0details: ""- statement: |-+ ALTER TABLE tech_book ADD COLUMN c INT;ALTER TABLE tech_book DROP COLUMN name, DROP COLUMN id;want:- status: WARNcode: 601title: table.require-pkcontent: Table `tech_book` requires PRIMARY KEY- line: 1+ line: 2details: ""- statement: |-ALTER TABLE tech_book CHANGE COLUMN id uid int;diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.goindex 3480b198bd..082bc85f88 100644--- a/backend/plugin/advisor/sql_review.go+++ b/backend/plugin/advisor/sql_review.go@@ -693,6 +693,11 @@ func SQLReviewCheck(statements string, ruleList []*storepb.SQLReviewRule, checkCfinder := checkContext.Catalog.GetFinder()switch checkContext.DbType {+ // only for mysqlwip test.+ case storepb.Engine_ENGINE_UNSPECIFIED:+ if err := finder.WalkThrough(statements); err != nil {+ return convertWalkThroughErrorToAdvice(checkContext, err)+ }case storepb.Engine_TIDB, storepb.Engine_MYSQL, storepb.Engine_MARIADB, storepb.Engine_POSTGRES, storepb.Engine_OCEANBASE:if err := finder.WalkThrough(statements); err != nil {return convertWalkThroughErrorToAdvice(checkContext, err)