Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: add Line in taskCheckResult (#4350)
rebelice74f84753242e
diff --git a/api/task_check_run.go b/api/task_check_run.goindex cbf441839b..ec42c121a2 100644--- a/api/task_check_run.go+++ b/api/task_check_run.go@@ -124,6 +124,7 @@ type TaskCheckResult struct {Status TaskCheckStatus `json:"status,omitempty"`Title string `json:"title,omitempty"`Content string `json:"content,omitempty"`+ Line int `json:"line,omitempty"`}// TaskCheckRunResultPayload is the result payload of a task check run.diff --git a/server/runner/taskcheck/statement_advisor_composite_executor.go b/server/runner/taskcheck/statement_advisor_composite_executor.goindex 10e345316b..f147f210e6 100644--- a/server/runner/taskcheck/statement_advisor_composite_executor.go+++ b/server/runner/taskcheck/statement_advisor_composite_executor.go@@ -113,6 +113,7 @@ func (e *StatementAdvisorCompositeExecutor) Run(ctx context.Context, taskCheckRuCode: advice.Code.Int(),Title: advice.Title,Content: advice.Content,+ Line: advice.Line,})}@@ -123,6 +124,7 @@ func (e *StatementAdvisorCompositeExecutor) Run(ctx context.Context, taskCheckRuCode: common.Ok.Int(),Title: "OK",Content: "",+ Line: 0,})}diff --git a/tests/test-data/sql_review_mysql.yaml b/tests/test-data/sql_review_mysql.yamlindex c728d88020..96d31429ac 100644--- a/tests/test-data/sql_review_mysql.yaml+++ b/tests/test-data/sql_review_mysql.yaml@@ -5,6 +5,7 @@status: SUCCESStitle: OKcontent: ""+ line: 0run: false- statement: CREATE TABLE user(id);result:@@ -13,6 +14,7 @@status: ERRORtitle: Syntax errorcontent: 'line 1 column 21 near ");" '+ line: 0run: false- 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_binresult:@@ -21,126 +23,151 @@status: ERRORtitle: engine.mysql.use-innodbcontent: '"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" doesn''t use InnoDB engine'+ line: 1- namespace: bb.advisorcode: 301status: WARNtitle: naming.tablecontent: '`userTable` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 1- namespace: bb.advisorcode: 302status: WARNtitle: naming.columncontent: '`userTable`.`roomId` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 1- namespace: bb.advisorcode: 303status: WARNtitle: naming.index.idxcontent: Index in table `userTable` mismatches the naming convention, expect "^$|^idx_userTable_name$" but found `idx1`+ line: 1- namespace: bb.advisorcode: 304status: WARNtitle: naming.index.ukcontent: Unique key in table `userTable` mismatches the naming convention, expect "^$|^uk_userTable_id_name$" but found `uk1`+ line: 1- namespace: bb.advisorcode: 305status: WARNtitle: naming.index.fkcontent: Foreign key in table `userTable` mismatches the naming convention, expect "^$|^fk_userTable_roomId_room_id$" but found `fk1`+ line: 1- namespace: bb.advisorcode: 601status: ERRORtitle: table.require-pkcontent: Table `userTable` requires PRIMARY KEY+ line: 1- namespace: bb.advisorcode: 602status: ERRORtitle: table.no-foreign-keycontent: Foreign key is not allowed in the table `userTable`+ line: 1- namespace: bb.advisorcode: 605status: WARNtitle: table.commentcontent: Table `userTable` requires comments+ line: 1- namespace: bb.advisorcode: 401status: WARNtitle: column.requiredcontent: 'Table `userTable` requires columns: created_ts, creator_id, updated_ts, updater_id'+ line: 1- namespace: bb.advisorcode: 402status: WARNtitle: column.no-nullcontent: '`userTable`.`name` cannot have NULL value'+ line: 1- namespace: bb.advisorcode: 402status: WARNtitle: column.no-nullcontent: '`userTable`.`roomId` cannot have NULL value'+ line: 1- namespace: bb.advisorcode: 404status: WARNtitle: column.set-default-for-not-nullcontent: Column `userTable`.`id` is NOT NULL but doesn't have DEFAULT+ line: 1- namespace: bb.advisorcode: 408status: WARNtitle: column.commentcontent: Column `userTable`.`id` requires comments+ line: 1- namespace: bb.advisorcode: 408status: WARNtitle: column.commentcontent: Column `userTable`.`name` requires comments+ line: 1- namespace: bb.advisorcode: 408status: WARNtitle: column.commentcontent: Column `userTable`.`roomId` requires comments+ line: 1- namespace: bb.advisorcode: 411status: ERRORtitle: column.type-disallow-listcontent: Disallow column type JSON but column `userTable`.`json_content` is+ line: 1- namespace: bb.advisorcode: 414status: WARNtitle: column.disallow-set-charsetcontent: Disallow set column charset but "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" does+ line: 1- namespace: bb.advisorcode: 419status: WARNtitle: column.current-time-count-limitcontent: Table `userTable` has 2 ON UPDATE CURRENT_TIMESTAMP() columns. The count greater than 1.+ line: 1- namespace: bb.advisorcode: 420status: WARNtitle: column.require-defaultcontent: Column `userTable`.`id` doesn't have DEFAULT.+ line: 1- namespace: bb.advisorcode: 420status: WARNtitle: column.require-defaultcontent: Column `userTable`.`name` doesn't have DEFAULT.+ line: 1- namespace: bb.advisorcode: 420status: WARNtitle: column.require-defaultcontent: Column `userTable`.`roomId` doesn't have DEFAULT.+ line: 1- namespace: bb.advisorcode: 804status: WARNtitle: index.type-no-blobcontent: Columns in index must not be BLOB but `userTable`.`content` is blob+ line: 1- namespace: bb.advisorcode: 1001status: WARNtitle: system.charset.allowlistcontent: '"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" used disabled charset ''ascii'''+ line: 1- namespace: bb.advisorcode: 1201status: WARNtitle: system.collation.allowlistcontent: '"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" used disabled collation ''latin1_bin'''+ line: 1run: false- statement: CREATE TABLE t_auto(auto_id varchar(20) AUTO_INCREMENT PRIMARY KEY COMMENT 'COMMENT') auto_increment = 2 COMMENT 'comment'result:@@ -149,31 +176,37 @@status: WARNtitle: naming.column.auto-incrementcontent: '`t_auto`.`auto_id` mismatches auto_increment column naming convention, naming format should be "^id$"'+ line: 1- namespace: bb.advisorcode: 401status: WARNtitle: column.requiredcontent: 'Table `t_auto` requires columns: created_ts, creator_id, id, updated_ts, updater_id'+ line: 1- namespace: bb.advisorcode: 410status: ERRORtitle: column.auto-increment-must-integercontent: Auto-increment column `t_auto`.`auto_id` requires integer type+ line: 1- namespace: bb.advisorcode: 416status: WARNtitle: column.auto-increment-initial-valuecontent: The initial auto-increment value in table `t_auto` is 2, which doesn't equal 20+ line: 1- namespace: bb.advisorcode: 417status: WARNtitle: column.auto-increment-must-unsignedcontent: Auto-increment column `t_auto`.`auto_id` is not UNSIGNED type+ line: 1- namespace: bb.advisorcode: 803status: WARNtitle: index.pk-type-limitcontent: Columns in primary key must be INT/BIGINT but `t_auto`.`auto_id` is varchar(20)+ line: 1run: false- statement: ' DELETE FROM tech_book'result:@@ -182,16 +215,19 @@status: ERRORtitle: statement.where.requirecontent: '"DELETE FROM tech_book" requires WHERE clause'+ line: 1- namespace: bb.advisorcode: 209status: WARNtitle: statement.affected-row-limitcontent: '"DELETE FROM tech_book" dry runs failed: Error 1146: Table ''testsqlreview.tech_book'' doesn''t exist'+ line: 1- namespace: bb.advisorcode: 208status: ERRORtitle: statement.dml-dry-runcontent: '"DELETE FROM tech_book" dry runs failed: Error 1146: Table ''testsqlreview.tech_book'' doesn''t exist'+ line: 1run: false- statement: DELETE FROM tech_book WHERE name like `%abc`result:@@ -200,16 +236,19 @@status: ERRORtitle: statement.where.no-leading-wildcard-likecontent: '"DELETE FROM tech_book WHERE name like `%abc`" uses leading wildcard LIKE'+ line: 1- namespace: bb.advisorcode: 209status: WARNtitle: statement.affected-row-limitcontent: '"DELETE FROM tech_book WHERE name like `%abc`" dry runs failed: Error 1146: Table ''testsqlreview.tech_book'' doesn''t exist'+ line: 1- namespace: bb.advisorcode: 208status: ERRORtitle: statement.dml-dry-runcontent: '"DELETE FROM tech_book WHERE name like `%abc`" dry runs failed: Error 1146: Table ''testsqlreview.tech_book'' doesn''t exist'+ line: 1run: false- statement: ' INSERT INTO t_copy SELECT * FROM t'result:@@ -218,26 +257,31 @@status: ERRORtitle: statement.select.no-select-allcontent: '"INSERT INTO t_copy SELECT * FROM t" uses SELECT all'+ line: 1- namespace: bb.advisorcode: 202status: ERRORtitle: statement.where.requirecontent: '"INSERT INTO t_copy SELECT * FROM t" requires WHERE clause'+ line: 1- namespace: bb.advisorcode: 1101status: WARNtitle: statement.insert.row-limitcontent: '"INSERT INTO t_copy SELECT * FROM t" dry runs failed: Error 1146: Table ''testsqlreview.t_copy'' doesn''t exist'+ line: 1- namespace: bb.advisorcode: 1107status: WARNtitle: statement.insert.must-specify-columncontent: The INSERT statement must specify columns but "INSERT INTO t_copy SELECT * FROM t" does not+ line: 1- namespace: bb.advisorcode: 208status: ERRORtitle: statement.dml-dry-runcontent: '"INSERT INTO t_copy SELECT * FROM t" dry runs failed: Error 1146: Table ''testsqlreview.t_copy'' doesn''t exist'+ line: 1run: false- statement: ' INSERT INTO t VALUES (1, 1, now(), 1, now())'result:@@ -246,11 +290,13 @@status: WARNtitle: statement.insert.must-specify-columncontent: The INSERT statement must specify columns but "INSERT INTO t VALUES (1, 1, now(), 1, now())" does not+ line: 1- namespace: bb.advisorcode: 208status: ERRORtitle: statement.dml-dry-runcontent: '"INSERT INTO t VALUES (1, 1, now(), 1, now())" dry runs failed: Error 1146: Table ''testsqlreview.t'' doesn''t exist'+ line: 1run: false- statement: DELETE FROM tech_book WHERE id = (SELECT max(id) FROM tech_book WHERE name = 'bytebase')result:@@ -259,11 +305,13 @@status: WARNtitle: statement.affected-row-limitcontent: '"DELETE FROM tech_book WHERE id = (SELECT max(id) FROM tech_book WHERE name = ''bytebase'')" dry runs failed: Error 1146: Table ''testsqlreview.tech_book'' doesn''t exist'+ line: 1- namespace: bb.advisorcode: 208status: ERRORtitle: statement.dml-dry-runcontent: '"DELETE FROM tech_book WHERE id = (SELECT max(id) FROM tech_book WHERE name = ''bytebase'')" dry runs failed: Error 1146: Table ''testsqlreview.tech_book'' doesn''t exist'+ line: 1run: false- statement: COMMIT;result:@@ -272,6 +320,7 @@status: ERRORtitle: statement.disallow-commitcontent: 'Commit is not allowed, related statement: "COMMIT;"'+ line: 1run: false- statement: CREATE TABLE user(id INT PRIMARY KEY COMMENT 'comment',name VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'comment',room_id INT NOT NULL DEFAULT 0 COMMENT 'comment',creator_id INT NOT NULL DEFAULT 0 COMMENT 'comment',created_ts TIMESTAMP NOT NULL DEFAULT NOW() COMMENT 'comment',updater_id INT NOT NULL DEFAULT 0 COMMENT 'comment',updated_ts TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',INDEX idx_user_name(name),UNIQUE KEY uk_user_id_name(id, name)) ENGINE = INNODB COMMENT 'comment'result:@@ -280,6 +329,7 @@status: SUCCESStitle: OKcontent: ""+ line: 0run: true- statement: INSERT INTO user(id, name) values (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')result:@@ -288,6 +338,7 @@status: SUCCESStitle: OKcontent: ""+ line: 0run: true- statement: DELETE FROM user WHERE id < 10result:@@ -296,6 +347,7 @@status: SUCCESStitle: OKcontent: ""+ line: 0run: false- statement: INSERT INTO user(id, name) values (6, 'f'), (7, 'g'), (8, 'h'), (9, 'i'), (10, 'j')result:@@ -304,6 +356,7 @@status: SUCCESStitle: OKcontent: ""+ line: 0run: true- statement: DELETE FROM user WHERE id <= 10result:@@ -312,6 +365,7 @@status: WARNtitle: statement.affected-row-limitcontent: '"DELETE FROM user WHERE id <= 10" affected 10 rows. The count exceeds 5.'+ line: 1run: false- statement: |-INSERT INTO user(id, name) SELECT id, name FROM (SELECT 1 AS id, 'a' AS name WHERE 1=1 UNION ALL@@ -340,6 +394,7 @@SELECT 8 AS id, 'h' AS name WHERE 1=1 UNION ALLSELECT 9 AS id, 'i' AS name WHERE 1=1 UNION ALLSELECT 10 AS id, 'j' AS name WHERE 1=1) value_table WHERE 1=1" inserts 10 rows. The count exceeds 5.+ line: 10run: false- statement: INSERT INTO user(id, name) SELECT id, name FROM user WHERE id=1 LIMIT 1result:@@ -348,6 +403,7 @@status: WARNtitle: statement.disallow-limitcontent: LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but "INSERT INTO user(id, name) SELECT id, name FROM user WHERE id=1 LIMIT 1" uses+ line: 1run: false- statement: ' ALTER TABLE user PARTITION BY HASH(id) PARTITIONS 8;'result:@@ -356,36 +412,42 @@status: WARNtitle: table.disallow-partitioncontent: Table partition is forbidden, but "ALTER TABLE user PARTITION BY HASH(id) PARTITIONS 8;" creates+ line: 1run: false- statement: |4-- ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '' COMMENT 'COMMENT' FIRST;- ALTER TABLE user ADD COLUMN c_column int NOT NULL DEFAULT 0 COMMENT 'comment';+ ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '' COMMENT 'COMMENT' FIRST;+ ALTER TABLE user ADD COLUMN c_column int NOT NULL DEFAULT 0 COMMENT 'comment';result:- namespace: bb.advisorcode: 207status: WARNtitle: statement.merge-alter-tablecontent: There are 2 statements to modify table `user`+ line: 2- namespace: bb.advisorcode: 403status: WARNtitle: column.disallow-change-typecontent: '"ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '''' COMMENT ''COMMENT'' FIRST;" changes column type'+ line: 1- namespace: bb.advisorcode: 406status: WARNtitle: column.disallow-changecontent: '"ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '''' COMMENT ''COMMENT'' FIRST;" contains CHANGE COLUMN statement'+ line: 1- namespace: bb.advisorcode: 407status: WARNtitle: column.disallow-changing-ordercontent: '"ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '''' COMMENT ''COMMENT'' FIRST;" changes column order'+ line: 1- namespace: bb.advisorcode: 111status: WARNtitle: schema.backward-compatibilitycontent: '"ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '''' COMMENT ''COMMENT'' FIRST;" may cause incompatibility with the existing data and code'+ line: 1run: false- statement: ' DROP TABLE user;'result:@@ -394,9 +456,11 @@status: ERRORtitle: table.drop-naming-conventioncontent: '`user` mismatches drop table naming convention, naming format should be "_delete$"'+ line: 1- namespace: bb.advisorcode: 103status: WARNtitle: schema.backward-compatibilitycontent: '"DROP TABLE user;" may cause incompatibility with the existing data and code'+ line: 1run: falsediff --git a/tests/test-data/sql_review_pg.yaml b/tests/test-data/sql_review_pg.yamlindex 38286e70f2..1efde2fce4 100644--- a/tests/test-data/sql_review_pg.yaml+++ b/tests/test-data/sql_review_pg.yaml@@ -16,6 +16,7 @@status: SUCCESStitle: OKcontent: ""+ line: 0run: false- statement: CREATE TABLE user(id);result:@@ -24,6 +25,7 @@status: ERRORtitle: Syntax errorcontent: syntax error at or near "user"+ line: 0run: false- statement: |-CREATE TABLE "userTable"(@@ -39,26 +41,31 @@status: WARNtitle: naming.tablecontent: '"userTable" mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 7- namespace: bb.advisorcode: 302status: WARNtitle: naming.columncontent: '"userTable"."roomId" mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 4- namespace: bb.advisorcode: 304status: WARNtitle: naming.index.ukcontent: Unique key in table "userTable" mismatches the naming convention, expect "^$|^uk_userTable_id_name$" but found "uk1"+ line: 5- namespace: bb.advisorcode: 305status: WARNtitle: naming.index.fkcontent: Foreign key in table "userTable" mismatches the naming convention, expect "^$|^fk_userTable_roomId_room_id$" but found "fk1"+ line: 6- namespace: bb.advisorcode: 601status: ERRORtitle: table.require-pkcontent: 'Table "public"."userTable" requires PRIMARY KEY, related statement: "CREATE TABLE \"userTable\"(\n id INT,\n name VARCHAR(255),\n \"roomId\" INT,\n CONSTRAINT uk1 UNIQUE (id, name),\n CONSTRAINT fk1 FOREIGN KEY (\"roomId\") REFERENCES room(id)\n )"'+ line: 7- namespace: bb.advisorcode: 602status: ERROR@@ -71,26 +78,31 @@CONSTRAINT uk1 UNIQUE (id, name),CONSTRAINT fk1 FOREIGN KEY ("roomId") REFERENCES room(id))"+ line: 7- namespace: bb.advisorcode: 401status: WARNtitle: column.requiredcontent: 'Table "userTable" requires columns: created_ts, creator_id, updated_ts, updater_id'+ line: 7- namespace: bb.advisorcode: 402status: WARNtitle: column.no-nullcontent: Column "id" in "public"."userTable" cannot have NULL value+ line: 2- namespace: bb.advisorcode: 402status: WARNtitle: column.no-nullcontent: Column "name" in "public"."userTable" cannot have NULL value+ line: 3- namespace: bb.advisorcode: 402status: WARNtitle: column.no-nullcontent: Column "roomId" in "public"."userTable" cannot have NULL value+ line: 4run: false- statement: DELETE FROM tresult:@@ -99,6 +111,7 @@status: ERRORtitle: statement.where.requirecontent: '"DELETE FROM t" requires WHERE clause'+ line: 1run: false- statement: DELETE FROM t WHERE a like '%abc'result:@@ -107,6 +120,7 @@status: ERRORtitle: statement.where.no-leading-wildcard-likecontent: '"DELETE FROM t WHERE a like ''%abc''" uses leading wildcard LIKE'+ line: 1run: false- statement: DELETE FROM t WHERE a = (SELECT max(id) FROM "user" WHERE name = 'bytebase')result:@@ -115,6 +129,7 @@status: SUCCESStitle: OKcontent: ""+ line: 0run: false- statement: INSERT INTO t VALUES (1), (2)result:@@ -123,6 +138,7 @@status: SUCCESStitle: OKcontent: ""+ line: 0run: false- statement: |-CREATE TABLE tech_book(@@ -139,6 +155,7 @@status: SUCCESStitle: OKcontent: ""+ line: 0run: true- statement: ALTER INDEX pk_tech_book_id RENAME TO pk1result:@@ -147,4 +164,5 @@status: WARNtitle: naming.index.pkcontent: Primary key in table "tech_book" mismatches the naming convention, expect "^$|^pk_tech_book_id$" but found "pk1"+ line: 1run: false