Skip to content

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

fix: handle nil pointer in column_comment_convention (#9314)

zll6002088ec9259be
diff --git a/backend/plugin/advisor/mysqlwip/advisor_column_comment_convention.go b/backend/plugin/advisor/mysqlwip/advisor_column_comment_convention.go
index bae199bcfa..9b77a26602 100644
--- a/backend/plugin/advisor/mysqlwip/advisor_column_comment_convention.go
+++ b/backend/plugin/advisor/mysqlwip/advisor_column_comment_convention.go
@@ -152,9 +152,15 @@ func (checker *columnCommentConventionChecker) EnterAlterTable(ctx *mysql.AlterT
func (checker *columnCommentConventionChecker) checkFieldDefinition(tableName, columnName string, ctx mysql.IFieldDefinitionContext) {
comment := ""
for _, attribute := range ctx.AllColumnAttribute() {
+ if attribute == nil || attribute.GetValue() == nil {
+ continue
+ }
if attribute.GetValue().GetTokenType() != mysql.MySQLParserCOMMENT_SYMBOL {
continue
}
+ if attribute.TextLiteral() == nil {
+ continue
+ }
comment = mysqlparser.NormalizeMySQLTextLiteral(attribute.TextLiteral())
if checker.maxLength >= 0 && len(comment) > checker.maxLength {
checker.adviceList = append(checker.adviceList, advisor.Advice{
diff --git a/backend/plugin/advisor/mysqlwip/test/column_comment.yaml b/backend/plugin/advisor/mysqlwip/test/column_comment.yaml
index f0be71ec1a..3c59a0aa38 100644
--- a/backend/plugin/advisor/mysqlwip/test/column_comment.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/column_comment.yaml
@@ -1,3 +1,54 @@
+- 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: 408
+ title: column.comment
+ content: Column `userTable`.`id` requires comments
+ line: 2
+ details: ""
+ - status: WARN
+ code: 408
+ title: column.comment
+ content: Column `userTable`.`name` requires comments
+ line: 3
+ details: ""
+ - status: WARN
+ code: 408
+ title: column.comment
+ content: Column `userTable`.`roomId` requires comments
+ line: 4
+ details: ""
+- 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';
+ want:
+ - status: SUCCESS
+ code: 0
+ title: OK
+ content: ""
+ line: 0
+ details: ""
- statement: CREATE TABLE t(a int COMMENT 'comments');
want:
- status: SUCCESS