Skip to content

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

chore(schema system): refine error content and title (#1465)

rebelice913de2f34d5f
diff --git a/common/error.go b/common/error.go
index 8cb5318067..70346412ae 100644
--- a/common/error.go
+++ b/common/error.go
@@ -68,7 +68,7 @@ const (
// 10301 column rule advisor error code
NoRequiredColumn Code = 10301
- ColumnCanNull Code = 10302
+ ColumnCanNotNull Code = 10302
NotInnoDBEngine Code = 10401
diff --git a/plugin/advisor/mysql/advisor_column_no_null.go b/plugin/advisor/mysql/advisor_column_no_null.go
index 1931c552a6..9d4c995c07 100644
--- a/plugin/advisor/mysql/advisor_column_no_null.go
+++ b/plugin/advisor/mysql/advisor_column_no_null.go
@@ -33,7 +33,10 @@ func (adv *ColumnNoNullAdvisor) Check(ctx advisor.Context, statement string) ([]
if err != nil {
return nil, err
}
- checker := &columnNoNullChecker{level: level}
+ checker := &columnNoNullChecker{
+ level: level,
+ title: string(ctx.Rule.Type),
+ }
for _, stmtNode := range root {
(stmtNode).Accept(checker)
@@ -53,6 +56,7 @@ func (adv *ColumnNoNullAdvisor) Check(ctx advisor.Context, statement string) ([]
type columnNoNullChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
}
type columnName struct {
@@ -103,9 +107,9 @@ func (v *columnNoNullChecker) Enter(in ast.Node) (ast.Node, bool) {
for _, column := range columns {
v.adviceList = append(v.adviceList, advisor.Advice{
Status: v.level,
- Code: common.ColumnCanNull,
- Title: "Column can have NULL value",
- Content: fmt.Sprintf("`%s`.`%s` can have NULL value", column.tableName, column.columnName),
+ Code: common.ColumnCanNotNull,
+ Title: v.title,
+ Content: fmt.Sprintf("`%s`.`%s` can not have NULL value", column.tableName, column.columnName),
})
}
diff --git a/plugin/advisor/mysql/advisor_column_no_null_test.go b/plugin/advisor/mysql/advisor_column_no_null_test.go
index e88ccaa42f..dfbb83c02c 100644
--- a/plugin/advisor/mysql/advisor_column_no_null_test.go
+++ b/plugin/advisor/mysql/advisor_column_no_null_test.go
@@ -15,15 +15,15 @@ func TestColumnNoNull(t *testing.T) {
want: []advisor.Advice{
{
Status: advisor.Warn,
- Code: common.ColumnCanNull,
- Title: "Column can have NULL value",
- Content: "`book`.`id` can have NULL value",
+ Code: common.ColumnCanNotNull,
+ Title: "column.no-null",
+ Content: "`book`.`id` can not have NULL value",
},
{
Status: advisor.Warn,
- Code: common.ColumnCanNull,
- Title: "Column can have NULL value",
- Content: "`book`.`name` can have NULL value",
+ Code: common.ColumnCanNotNull,
+ Title: "column.no-null",
+ Content: "`book`.`name` can not have NULL value",
},
},
},
@@ -32,9 +32,9 @@ func TestColumnNoNull(t *testing.T) {
want: []advisor.Advice{
{
Status: advisor.Warn,
- Code: common.ColumnCanNull,
- Title: "Column can have NULL value",
- Content: "`book`.`name` can have NULL value",
+ Code: common.ColumnCanNotNull,
+ Title: "column.no-null",
+ Content: "`book`.`name` can not have NULL value",
},
},
},
@@ -43,9 +43,9 @@ func TestColumnNoNull(t *testing.T) {
want: []advisor.Advice{
{
Status: advisor.Warn,
- Code: common.ColumnCanNull,
- Title: "Column can have NULL value",
- Content: "`book`.`name` can have NULL value",
+ Code: common.ColumnCanNotNull,
+ Title: "column.no-null",
+ Content: "`book`.`name` can not have NULL value",
},
},
},
@@ -65,9 +65,9 @@ func TestColumnNoNull(t *testing.T) {
want: []advisor.Advice{
{
Status: advisor.Warn,
- Code: common.ColumnCanNull,
- Title: "Column can have NULL value",
- Content: "`book`.`id` can have NULL value",
+ Code: common.ColumnCanNotNull,
+ Title: "column.no-null",
+ Content: "`book`.`id` can not have NULL value",
},
},
},
@@ -87,9 +87,9 @@ func TestColumnNoNull(t *testing.T) {
want: []advisor.Advice{
{
Status: advisor.Warn,
- Code: common.ColumnCanNull,
- Title: "Column can have NULL value",
- Content: "`book`.`name` can have NULL value",
+ Code: common.ColumnCanNotNull,
+ Title: "column.no-null",
+ Content: "`book`.`name` can not have NULL value",
},
},
},
diff --git a/plugin/advisor/mysql/advisor_column_required.go b/plugin/advisor/mysql/advisor_column_required.go
index 43e15cbe74..f5dc63220a 100644
--- a/plugin/advisor/mysql/advisor_column_required.go
+++ b/plugin/advisor/mysql/advisor_column_required.go
@@ -46,6 +46,7 @@ func (adv *ColumnRequirementAdvisor) Check(ctx advisor.Context, statement string
}
checker := &columnRequirementChecker{
level: level,
+ title: string(ctx.Rule.Type),
requiredColumns: requiredColumns,
tables: make(tableState),
}
@@ -60,6 +61,7 @@ func (adv *ColumnRequirementAdvisor) Check(ctx advisor.Context, statement string
type columnRequirementChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
requiredColumns columnSet
tables tableState
}
@@ -122,7 +124,7 @@ func (v *columnRequirementChecker) generateAdviceList() []advisor.Advice {
v.adviceList = append(v.adviceList, advisor.Advice{
Status: v.level,
Code: common.NoRequiredColumn,
- Title: "Require columns",
+ Title: v.title,
Content: fmt.Sprintf("Table `%s` requires columns: %s", tableName, strings.Join(missingColumns, ", ")),
})
}
diff --git a/plugin/advisor/mysql/advisor_column_required_test.go b/plugin/advisor/mysql/advisor_column_required_test.go
index 057acf3fe8..5cfc1ba710 100644
--- a/plugin/advisor/mysql/advisor_column_required_test.go
+++ b/plugin/advisor/mysql/advisor_column_required_test.go
@@ -18,7 +18,7 @@ func TestColumnRequirement(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
- Title: "Require columns",
+ Title: "column.required",
Content: "Table `book` requires columns: created_ts, creator_id, updated_ts, updater_id",
},
},
@@ -51,7 +51,7 @@ func TestColumnRequirement(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
- Title: "Require columns",
+ Title: "column.required",
Content: "Table `book` requires columns: creator_id",
},
},
@@ -85,7 +85,7 @@ func TestColumnRequirement(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
- Title: "Require columns",
+ Title: "column.required",
Content: "Table `book` requires columns: creator_id",
},
},
@@ -119,7 +119,7 @@ func TestColumnRequirement(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
- Title: "Require columns",
+ Title: "column.required",
Content: "Table `book` requires columns: creator_id",
},
},
@@ -153,7 +153,7 @@ func TestColumnRequirement(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
- Title: "Require columns",
+ Title: "column.required",
Content: "Table `book` requires columns: updater_id",
},
},
@@ -189,13 +189,13 @@ func TestColumnRequirement(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
- Title: "Require columns",
+ Title: "column.required",
Content: "Table `book` requires columns: creator_id",
},
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
- Title: "Require columns",
+ Title: "column.required",
Content: "Table `student` requires columns: creator_id, updater_id",
},
},
diff --git a/plugin/advisor/mysql/advisor_migration_compatibility.go b/plugin/advisor/mysql/advisor_migration_compatibility.go
index c03bbd3c73..1093a380f6 100644
--- a/plugin/advisor/mysql/advisor_migration_compatibility.go
+++ b/plugin/advisor/mysql/advisor_migration_compatibility.go
@@ -35,7 +35,10 @@ func (adv *CompatibilityAdvisor) Check(ctx advisor.Context, statement string) ([
return nil, err
}
- c := &compatibilityChecker{level: level}
+ c := &compatibilityChecker{
+ level: level,
+ title: string(ctx.Rule.Type),
+ }
for _, stmtNode := range root {
(stmtNode).Accept(c)
}
@@ -54,6 +57,7 @@ func (adv *CompatibilityAdvisor) Check(ctx advisor.Context, statement string) ([
type compatibilityChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
}
// Enter implements the ast.Visitor interface
@@ -148,7 +152,7 @@ func (v *compatibilityChecker) Enter(in ast.Node) (ast.Node, bool) {
v.adviceList = append(v.adviceList, advisor.Advice{
Status: v.level,
Code: code,
- Title: "Potential incompatible migration",
+ Title: v.title,
Content: fmt.Sprintf("\"%s\" may cause incompatibility with the existing data and code", in.Text()),
})
}
diff --git a/plugin/advisor/mysql/advisor_migration_compatibility_test.go b/plugin/advisor/mysql/advisor_migration_compatibility_test.go
index 701b909943..40fd37dcde 100644
--- a/plugin/advisor/mysql/advisor_migration_compatibility_test.go
+++ b/plugin/advisor/mysql/advisor_migration_compatibility_test.go
@@ -18,7 +18,7 @@ func TestBasic(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityDropDatabase,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"DROP DATABASE d1\" may cause incompatibility with the existing data and code",
},
},
@@ -29,7 +29,7 @@ func TestBasic(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityDropTable,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"DROP TABLE t1\" may cause incompatibility with the existing data and code",
},
},
@@ -40,7 +40,7 @@ func TestBasic(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityRenameTable,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"RENAME TABLE t1 to t2\" may cause incompatibility with the existing data and code",
},
},
@@ -51,7 +51,7 @@ func TestBasic(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityDropTable,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"DROP VIEW v1\" may cause incompatibility with the existing data and code",
},
},
@@ -62,7 +62,7 @@ func TestBasic(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAddUniqueKey,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"CREATE UNIQUE INDEX idx1 ON t1 (f1)\" may cause incompatibility with the existing data and code",
},
},
@@ -73,13 +73,13 @@ func TestBasic(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityDropTable,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"DROP TABLE t1;\" may cause incompatibility with the existing data and code",
},
{
Status: advisor.Warn,
Code: common.CompatibilityDropTable,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"DROP TABLE t2;\" may cause incompatibility with the existing data and code",
},
},
@@ -112,7 +112,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityRenameColumn,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 RENAME COLUMN f1 to f2\" may cause incompatibility with the existing data and code",
},
},
@@ -123,7 +123,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityDropColumn,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 DROP COLUMN f1\" may cause incompatibility with the existing data and code",
},
},
@@ -134,7 +134,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAddPrimaryKey,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 ADD PRIMARY KEY (f1)\" may cause incompatibility with the existing data and code",
},
},
@@ -145,7 +145,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAddUniqueKey,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 ADD UNIQUE (f1)\" may cause incompatibility with the existing data and code",
},
},
@@ -156,7 +156,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAddUniqueKey,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 ADD UNIQUE KEY (f1)\" may cause incompatibility with the existing data and code",
},
},
@@ -167,7 +167,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAddUniqueKey,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 ADD UNIQUE INDEX (f1)\" may cause incompatibility with the existing data and code",
},
},
@@ -178,7 +178,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAddForeignKey,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 ADD FOREIGN KEY (f1) REFERENCES t2(f2)\" may cause incompatibility with the existing data and code",
},
},
@@ -189,7 +189,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAddCheck,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 ADD CHECK (f1 > 0)\" may cause incompatibility with the existing data and code",
},
},
@@ -210,7 +210,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAlterCheck,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 ALTER CHECK chk1 ENFORCED\" may cause incompatibility with the existing data and code",
},
},
@@ -231,7 +231,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAddCheck,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 ADD CONSTRAINT CHECK (f1 > 0)\" may cause incompatibility with the existing data and code",
},
},
@@ -253,7 +253,7 @@ func TestAlterTable(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityRenameTable,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 RENAME TO t2\" may cause incompatibility with the existing data and code",
},
},
@@ -275,7 +275,7 @@ func TestAlterTableChangeColumnType(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAlterColumn,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 CHANGE f1 f2 TEXT\" may cause incompatibility with the existing data and code",
},
},
@@ -286,7 +286,7 @@ func TestAlterTableChangeColumnType(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAlterColumn,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 MODIFY f1 TEXT\" may cause incompatibility with the existing data and code",
},
},
@@ -297,7 +297,7 @@ func TestAlterTableChangeColumnType(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAlterColumn,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 MODIFY f1 TEXT NULL\" may cause incompatibility with the existing data and code",
},
},
@@ -308,7 +308,7 @@ func TestAlterTableChangeColumnType(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAlterColumn,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 MODIFY f1 TEXT NOT NULL\" may cause incompatibility with the existing data and code",
},
},
@@ -319,7 +319,7 @@ func TestAlterTableChangeColumnType(t *testing.T) {
{
Status: advisor.Warn,
Code: common.CompatibilityAlterColumn,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"ALTER TABLE t1 MODIFY f1 TEXT COMMENT 'bla'\" may cause incompatibility with the existing data and code",
},
},
diff --git a/plugin/advisor/mysql/advisor_naming_column.go b/plugin/advisor/mysql/advisor_naming_column.go
index 927a373791..2125ea293a 100644
--- a/plugin/advisor/mysql/advisor_naming_column.go
+++ b/plugin/advisor/mysql/advisor_naming_column.go
@@ -41,6 +41,7 @@ func (adv *NamingColumnConventionAdvisor) Check(ctx advisor.Context, statement s
}
checker := &namingColumnConventionChecker{
level: level,
+ title: string(ctx.Rule.Type),
format: format,
tables: make(tableState),
}
@@ -64,6 +65,7 @@ func (adv *NamingColumnConventionAdvisor) Check(ctx advisor.Context, statement s
type namingColumnConventionChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
format *regexp.Regexp
tables tableState
}
@@ -104,7 +106,7 @@ func (v *namingColumnConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
v.adviceList = append(v.adviceList, advisor.Advice{
Status: v.level,
Code: common.NamingColumnConventionMismatch,
- Title: "Mismatch column naming convention",
+ Title: v.title,
Content: fmt.Sprintf("`%s`.`%s` mismatches column naming convention, naming format should be %q", tableName, column, v.format),
})
}
diff --git a/plugin/advisor/mysql/advisor_naming_column_test.go b/plugin/advisor/mysql/advisor_naming_column_test.go
index 98ba4d8457..2aac6bf8d9 100644
--- a/plugin/advisor/mysql/advisor_naming_column_test.go
+++ b/plugin/advisor/mysql/advisor_naming_column_test.go
@@ -18,7 +18,7 @@ func TestNamingColumnConvention(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
- Title: "Mismatch column naming convention",
+ Title: "naming.column",
Content: "`book`.`creatorId` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
},
@@ -41,7 +41,7 @@ func TestNamingColumnConvention(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
- Title: "Mismatch column naming convention",
+ Title: "naming.column",
Content: "`book`.`creatorId` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
},
@@ -69,7 +69,7 @@ func TestNamingColumnConvention(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
- Title: "Mismatch column naming convention",
+ Title: "naming.column",
Content: "`book`.`creatorId` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
},
@@ -107,7 +107,7 @@ func TestNamingColumnConvention(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
- Title: "Mismatch column naming convention",
+ Title: "naming.column",
Content: "`book`.`contentString` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
},
@@ -126,25 +126,25 @@ func TestNamingColumnConvention(t *testing.T) {
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
- Title: "Mismatch column naming convention",
+ Title: "naming.column",
Content: "`book`.`createdTs` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
- Title: "Mismatch column naming convention",
+ Title: "naming.column",
Content: "`book`.`updaterId` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
- Title: "Mismatch column naming convention",
+ Title: "naming.column",
Content: "`student`.`createdTs` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
- Title: "Mismatch column naming convention",
+ Title: "naming.column",
Content: "`student`.`updatedTs` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
},
diff --git a/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go b/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
index 8b6ad41b3a..9a53be10bb 100644
--- a/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
+++ b/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
@@ -42,6 +42,7 @@ func (check *NamingFKConventionAdvisor) Check(ctx advisor.Context, statement str
}
checker := &namingFKConventionChecker{
level: level,
+ title: string(ctx.Rule.Type),
format: format,
templateList: templateList,
}
@@ -64,6 +65,7 @@ func (check *NamingFKConventionAdvisor) Check(ctx advisor.Context, statement str
type namingFKConventionChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
format string
templateList []string
}
@@ -87,7 +89,7 @@ func (checker *namingFKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
checker.adviceList = append(checker.adviceList, advisor.Advice{
Status: checker.level,
Code: common.NamingFKConventionMismatch,
- Title: "Mismatch foreign key naming convention",
+ Title: checker.title,
Content: fmt.Sprintf("Foreign key in table `%s` mismatches the naming convention, expect %q but found `%s`", indexData.tableName, regex, indexData.indexName),
})
}
diff --git a/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go b/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go
index e778762386..218509e320 100644
--- a/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go
+++ b/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go
@@ -29,7 +29,7 @@ func TestNamingFKConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingFKConventionMismatch,
- Title: "Mismatch foreign key naming convention",
+ Title: "naming.index.fk",
Content: "Foreign key in table `tech_book` mismatches the naming convention, expect \"^fk_tech_book_author_id_author_id$\" but found `fk_author_id`",
},
},
@@ -51,7 +51,7 @@ func TestNamingFKConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingFKConventionMismatch,
- Title: "Mismatch foreign key naming convention",
+ 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`",
},
},
diff --git a/plugin/advisor/mysql/advisor_naming_index_convention.go b/plugin/advisor/mysql/advisor_naming_index_convention.go
index 8ad6cfc508..0f8a393db5 100644
--- a/plugin/advisor/mysql/advisor_naming_index_convention.go
+++ b/plugin/advisor/mysql/advisor_naming_index_convention.go
@@ -47,6 +47,7 @@ func (check *NamingIndexConventionAdvisor) Check(ctx advisor.Context, statement
}
checker := &namingIndexConventionChecker{
level: level,
+ title: string(ctx.Rule.Type),
format: format,
templateList: templateList,
catalog: ctx.Catalog,
@@ -70,6 +71,7 @@ func (check *NamingIndexConventionAdvisor) Check(ctx advisor.Context, statement
type namingIndexConventionChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
format string
templateList []string
catalog catalog.Service
@@ -94,7 +96,7 @@ func (checker *namingIndexConventionChecker) Enter(in ast.Node) (ast.Node, bool)
checker.adviceList = append(checker.adviceList, advisor.Advice{
Status: checker.level,
Code: common.NamingIndexConventionMismatch,
- Title: "Mismatch index naming convention",
+ Title: checker.title,
Content: fmt.Sprintf("Index in table `%s` mismatches the naming convention, expect %q but found `%s`", indexData.tableName, regex, indexData.indexName),
})
}
diff --git a/plugin/advisor/mysql/advisor_naming_index_convention_test.go b/plugin/advisor/mysql/advisor_naming_index_convention_test.go
index c51478670c..bdc171b1dd 100644
--- a/plugin/advisor/mysql/advisor_naming_index_convention_test.go
+++ b/plugin/advisor/mysql/advisor_naming_index_convention_test.go
@@ -31,7 +31,7 @@ func TestNamingIndexConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingIndexConventionMismatch,
- Title: "Mismatch index naming convention",
+ Title: "naming.index.idx",
Content: "Index in table `tech_book` mismatches the naming convention, expect \"^idx_tech_book_id_name$\" but found `tech_book_id_name`",
},
},
@@ -60,7 +60,7 @@ func TestNamingIndexConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingIndexConventionMismatch,
- Title: "Mismatch index naming convention",
+ Title: "naming.index.idx",
Content: "Index in table `tech_book` mismatches the naming convention, expect \"^idx_tech_book_id_name$\" but found `idx_tech_book`",
},
},
@@ -82,7 +82,7 @@ func TestNamingIndexConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingIndexConventionMismatch,
- Title: "Mismatch index naming convention",
+ Title: "naming.index.idx",
Content: "Index in table `tech_book` mismatches the naming convention, expect \"^idx_tech_book_id_name$\" but found `tech_book_id_name`",
},
},
@@ -104,7 +104,7 @@ func TestNamingIndexConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingIndexConventionMismatch,
- Title: "Mismatch index naming convention",
+ Title: "naming.index.idx",
Content: "Index in table `tech_book` mismatches the naming convention, expect \"^idx_tech_book_name$\" but found ``",
},
},
diff --git a/plugin/advisor/mysql/advisor_naming_table.go b/plugin/advisor/mysql/advisor_naming_table.go
index a5818b942d..19755e305e 100644
--- a/plugin/advisor/mysql/advisor_naming_table.go
+++ b/plugin/advisor/mysql/advisor_naming_table.go
@@ -41,6 +41,7 @@ func (adv *NamingTableConventionAdvisor) Check(ctx advisor.Context, statement st
}
checker := &namingTableConventionChecker{
level: level,
+ title: string(ctx.Rule.Type),
format: format,
}
for _, stmtNode := range root {
@@ -61,6 +62,7 @@ func (adv *NamingTableConventionAdvisor) Check(ctx advisor.Context, statement st
type namingTableConventionChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
format *regexp.Regexp
}
@@ -92,7 +94,7 @@ func (v *namingTableConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
v.adviceList = append(v.adviceList, advisor.Advice{
Status: v.level,
Code: common.NamingTableConventionMismatch,
- Title: "Mismatch table naming convention",
+ Title: v.title,
Content: fmt.Sprintf("`%s` mismatches table naming convention, naming format should be %q", tableName, v.format),
})
}
diff --git a/plugin/advisor/mysql/advisor_naming_table_test.go b/plugin/advisor/mysql/advisor_naming_table_test.go
index cfa152b29d..cc6d38a9f8 100644
--- a/plugin/advisor/mysql/advisor_naming_table_test.go
+++ b/plugin/advisor/mysql/advisor_naming_table_test.go
@@ -18,7 +18,7 @@ func TestNamingTableConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingTableConventionMismatch,
- Title: "Mismatch table naming convention",
+ Title: "naming.table",
Content: "`techBook` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
},
@@ -40,7 +40,7 @@ func TestNamingTableConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingTableConventionMismatch,
- Title: "Mismatch table naming convention",
+ Title: "naming.table",
Content: "`TechBook` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
},
@@ -62,7 +62,7 @@ func TestNamingTableConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingTableConventionMismatch,
- Title: "Mismatch table naming convention",
+ Title: "naming.table",
Content: "`LiteraryBook` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
},
@@ -73,13 +73,13 @@ func TestNamingTableConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingTableConventionMismatch,
- Title: "Mismatch table naming convention",
+ Title: "naming.table",
Content: "`TechBook` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
{
Status: advisor.Error,
Code: common.NamingTableConventionMismatch,
- Title: "Mismatch table naming convention",
+ Title: "naming.table",
Content: "`LiteraryBook` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
},
diff --git a/plugin/advisor/mysql/advisor_naming_unique_key_convention.go b/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
index 413af76bc9..e853561246 100644
--- a/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
+++ b/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
@@ -46,6 +46,7 @@ func (check *NamingUKConventionAdvisor) Check(ctx advisor.Context, statement str
}
checker := &namingUKConventionChecker{
level: level,
+ title: string(ctx.Rule.Type),
format: format,
templateList: templateList,
catalog: ctx.Catalog,
@@ -68,6 +69,7 @@ func (check *NamingUKConventionAdvisor) Check(ctx advisor.Context, statement str
type namingUKConventionChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
format string
templateList []string
catalog catalog.Service
@@ -92,7 +94,7 @@ func (checker *namingUKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
checker.adviceList = append(checker.adviceList, advisor.Advice{
Status: checker.level,
Code: common.NamingUKConventionMismatch,
- Title: "Mismatch unique key naming convention",
+ Title: checker.title,
Content: fmt.Sprintf("Unique key in table `%s` mismatches the naming convention, expect %q but found `%s`", indexData.tableName, regex, indexData.indexName),
})
}
diff --git a/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go b/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go
index 057eeafe34..cc48d6eb28 100644
--- a/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go
+++ b/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go
@@ -31,7 +31,7 @@ func TestNamingUKConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
- Title: "Mismatch unique key naming convention",
+ Title: "naming.index.uk",
Content: "Unique key in table `tech_book` mismatches the naming convention, expect \"^uk_tech_book_id_name$\" but found `tech_book_id_name`",
},
},
@@ -53,7 +53,7 @@ func TestNamingUKConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
- Title: "Mismatch unique key naming convention",
+ Title: "naming.index.uk",
Content: "Unique key in table `tech_book` mismatches the naming convention, expect \"^uk_tech_book_id_name$\" but found `tech_book_id_name`",
},
},
@@ -82,7 +82,7 @@ func TestNamingUKConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
- Title: "Mismatch unique key naming convention",
+ Title: "naming.index.uk",
Content: "Unique key in table `tech_book` mismatches the naming convention, expect \"^uk_tech_book_id_name$\" but found `uk_tech_book`",
},
},
@@ -104,7 +104,7 @@ func TestNamingUKConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
- Title: "Mismatch unique key naming convention",
+ Title: "naming.index.uk",
Content: "Unique key in table `tech_book` mismatches the naming convention, expect \"^uk_tech_book_name$\" but found ``",
},
},
@@ -115,7 +115,7 @@ func TestNamingUKConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
- Title: "Mismatch unique key naming convention",
+ Title: "naming.index.uk",
Content: "Unique key in table `tech_book` mismatches the naming convention, expect \"^uk_tech_book_name$\" but found ``",
},
},
@@ -126,7 +126,7 @@ func TestNamingUKConvention(t *testing.T) {
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
- Title: "Mismatch unique key naming convention",
+ Title: "naming.index.uk",
Content: "Unique key in table `tech_book` mismatches the naming convention, expect \"^uk_tech_book_name$\" but found ``",
},
},
diff --git a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go b/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go
index bfa5d3eec5..d32ac007de 100644
--- a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go
+++ b/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go
@@ -49,7 +49,7 @@ func (adv *NoLeadingWildcardLikeAdvisor) Check(ctx advisor.Context, statement st
checker.adviceList = append(checker.adviceList, advisor.Advice{
Status: checker.level,
Code: common.StatementLeadingWildcardLike,
- Title: "No leading wildcard LIKE",
+ Title: string(ctx.Rule.Type),
Content: fmt.Sprintf("\"%s\" uses leading wildcard LIKE", checker.text),
})
}
diff --git a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go b/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go
index a3cef77f1e..fb3e9dea57 100644
--- a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go
+++ b/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go
@@ -27,7 +27,7 @@ func TestNoLeadingWildcardLike(t *testing.T) {
{
Status: advisor.Error,
Code: common.StatementLeadingWildcardLike,
- Title: "No leading wildcard LIKE",
+ Title: "statement.where.no-leading-wildcard-like",
Content: "\"SELECT * FROM t WHERE a LIKE '%abc'\" uses leading wildcard LIKE",
},
},
@@ -38,7 +38,7 @@ func TestNoLeadingWildcardLike(t *testing.T) {
{
Status: advisor.Error,
Code: common.StatementLeadingWildcardLike,
- Title: "No leading wildcard LIKE",
+ Title: "statement.where.no-leading-wildcard-like",
Content: "\"SELECT * FROM t WHERE a LIKE 'abc' OR a LIKE '%abc'\" uses leading wildcard LIKE",
},
},
@@ -49,7 +49,7 @@ func TestNoLeadingWildcardLike(t *testing.T) {
{
Status: advisor.Error,
Code: common.StatementLeadingWildcardLike,
- Title: "No leading wildcard LIKE",
+ Title: "statement.where.no-leading-wildcard-like",
Content: "\"SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc'\" uses leading wildcard LIKE",
},
},
@@ -60,7 +60,7 @@ func TestNoLeadingWildcardLike(t *testing.T) {
{
Status: advisor.Error,
Code: common.StatementLeadingWildcardLike,
- Title: "No leading wildcard LIKE",
+ Title: "statement.where.no-leading-wildcard-like",
Content: "\"SELECT * FROM (SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc') t1\" uses leading wildcard LIKE",
},
},
diff --git a/plugin/advisor/mysql/advisor_stmt_no_select_all.go b/plugin/advisor/mysql/advisor_stmt_no_select_all.go
index 0b137d5648..7f703117f0 100644
--- a/plugin/advisor/mysql/advisor_stmt_no_select_all.go
+++ b/plugin/advisor/mysql/advisor_stmt_no_select_all.go
@@ -33,7 +33,10 @@ func (adv *NoSelectAllAdvisor) Check(ctx advisor.Context, statement string) ([]a
if err != nil {
return nil, err
}
- checker := &noSelectAllChecker{level: level}
+ checker := &noSelectAllChecker{
+ level: level,
+ title: string(ctx.Rule.Type),
+ }
for _, stmtNode := range root {
checker.text = stmtNode.Text()
(stmtNode).Accept(checker)
@@ -53,6 +56,7 @@ func (adv *NoSelectAllAdvisor) Check(ctx advisor.Context, statement string) ([]a
type noSelectAllChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
text string
}
@@ -64,7 +68,7 @@ func (v *noSelectAllChecker) Enter(in ast.Node) (ast.Node, bool) {
v.adviceList = append(v.adviceList, advisor.Advice{
Status: v.level,
Code: common.StatementSelectAll,
- Title: "Not SELECT all",
+ Title: v.title,
Content: fmt.Sprintf("\"%s\" uses SELECT all", v.text),
})
break
diff --git a/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go b/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go
index 7182ce8d10..00b87463b7 100644
--- a/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go
+++ b/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go
@@ -16,7 +16,7 @@ func TestNoSelectAll(t *testing.T) {
{
Status: advisor.Error,
Code: common.StatementSelectAll,
- Title: "Not SELECT all",
+ Title: "statement.select.no-select-all",
Content: "\"SELECT * FROM t\" uses SELECT all",
},
},
@@ -38,7 +38,7 @@ func TestNoSelectAll(t *testing.T) {
{
Status: advisor.Error,
Code: common.StatementSelectAll,
- Title: "Not SELECT all",
+ Title: "statement.select.no-select-all",
Content: "\"SELECT a, b FROM (SELECT * from t1 JOIN t2) t\" uses SELECT all",
},
},
diff --git a/plugin/advisor/mysql/advisor_stmt_where_required.go b/plugin/advisor/mysql/advisor_stmt_where_required.go
index 1bfbf2077f..c2f9ffc84c 100644
--- a/plugin/advisor/mysql/advisor_stmt_where_required.go
+++ b/plugin/advisor/mysql/advisor_stmt_where_required.go
@@ -34,7 +34,10 @@ func (adv *WhereRequirementAdvisor) Check(ctx advisor.Context, statement string)
if err != nil {
return nil, err
}
- checker := &whereRequirementChecker{level: level}
+ checker := &whereRequirementChecker{
+ level: level,
+ title: string(ctx.Rule.Type),
+ }
for _, stmtNode := range root {
checker.text = stmtNode.Text()
(stmtNode).Accept(checker)
@@ -54,6 +57,7 @@ func (adv *WhereRequirementAdvisor) Check(ctx advisor.Context, statement string)
type whereRequirementChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
text string
}
@@ -82,7 +86,7 @@ func (v *whereRequirementChecker) Enter(in ast.Node) (ast.Node, bool) {
v.adviceList = append(v.adviceList, advisor.Advice{
Status: v.level,
Code: code,
- Title: "Require WHERE clause",
+ Title: v.title,
Content: fmt.Sprintf("\"%s\" requires WHERE clause", v.text),
})
}
diff --git a/plugin/advisor/mysql/advisor_stmt_where_required_test.go b/plugin/advisor/mysql/advisor_stmt_where_required_test.go
index 02cf2b9a46..8751b48c71 100644
--- a/plugin/advisor/mysql/advisor_stmt_where_required_test.go
+++ b/plugin/advisor/mysql/advisor_stmt_where_required_test.go
@@ -16,7 +16,7 @@ func TestWhereRequirement(t *testing.T) {
{
Status: advisor.Warn,
Code: common.StatementNoWhere,
- Title: "Require WHERE clause",
+ Title: "statement.where.require",
Content: "\"DELETE FROM t1\" requires WHERE clause",
},
},
@@ -27,7 +27,7 @@ func TestWhereRequirement(t *testing.T) {
{
Status: advisor.Warn,
Code: common.StatementNoWhere,
- Title: "Require WHERE clause",
+ Title: "statement.where.require",
Content: "\"UPDATE t1 SET a = 1\" requires WHERE clause",
},
},
@@ -60,7 +60,7 @@ func TestWhereRequirement(t *testing.T) {
{
Status: advisor.Warn,
Code: common.StatementNoWhere,
- Title: "Require WHERE clause",
+ Title: "statement.where.require",
Content: "\"SELECT a FROM t\" requires WHERE clause",
},
},
@@ -82,7 +82,7 @@ func TestWhereRequirement(t *testing.T) {
{
Status: advisor.Warn,
Code: common.StatementNoWhere,
- Title: "Require WHERE clause",
+ Title: "statement.where.require",
Content: "\"SELECT a FROM t WHERE a > (SELECT max(id) FROM user)\" requires WHERE clause",
},
},
diff --git a/plugin/advisor/mysql/advisor_table_require_pk.go b/plugin/advisor/mysql/advisor_table_require_pk.go
index bf6d8e1d5e..25fce0473f 100644
--- a/plugin/advisor/mysql/advisor_table_require_pk.go
+++ b/plugin/advisor/mysql/advisor_table_require_pk.go
@@ -44,6 +44,7 @@ func (adv *TableRequirePKAdvisor) Check(ctx advisor.Context, statement string) (
}
checker := &tableRequirePKChecker{
level: level,
+ title: string(ctx.Rule.Type),
tables: make(tablePK),
catalog: ctx.Catalog,
}
@@ -58,6 +59,7 @@ func (adv *TableRequirePKAdvisor) Check(ctx advisor.Context, statement string) (
type tableRequirePKChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
tables tablePK
catalog catalog.Service
}
@@ -123,7 +125,7 @@ func (v *tableRequirePKChecker) generateAdviceList() []advisor.Advice {
v.adviceList = append(v.adviceList, advisor.Advice{
Status: v.level,
Code: common.TableNoPK,
- Title: "Require PRIMARY KEY",
+ Title: v.title,
Content: fmt.Sprintf("Table `%s` requires PRIMARY KEY", tableName),
})
}
diff --git a/plugin/advisor/mysql/advisor_table_require_pk_test.go b/plugin/advisor/mysql/advisor_table_require_pk_test.go
index 7961f2525f..0a99b11729 100644
--- a/plugin/advisor/mysql/advisor_table_require_pk_test.go
+++ b/plugin/advisor/mysql/advisor_table_require_pk_test.go
@@ -38,7 +38,7 @@ func TestRequirePK(t *testing.T) {
{
Status: advisor.Error,
Code: common.TableNoPK,
- Title: "Require PRIMARY KEY",
+ Title: "table.require-pk",
Content: "Table `t` requires PRIMARY KEY",
},
},
@@ -74,7 +74,7 @@ func TestRequirePK(t *testing.T) {
{
Status: advisor.Error,
Code: common.TableNoPK,
- Title: "Require PRIMARY KEY",
+ Title: "table.require-pk",
Content: "Table `t` requires PRIMARY KEY",
},
},
@@ -86,7 +86,7 @@ func TestRequirePK(t *testing.T) {
{
Status: advisor.Error,
Code: common.TableNoPK,
- Title: "Require PRIMARY KEY",
+ Title: "table.require-pk",
Content: "Table `t` requires PRIMARY KEY",
},
},
@@ -170,7 +170,7 @@ func TestRequirePK(t *testing.T) {
{
Status: advisor.Error,
Code: common.TableNoPK,
- Title: "Require PRIMARY KEY",
+ Title: "table.require-pk",
Content: "Table `t` requires PRIMARY KEY",
},
},
@@ -182,7 +182,7 @@ func TestRequirePK(t *testing.T) {
{
Status: advisor.Error,
Code: common.TableNoPK,
- Title: "Require PRIMARY KEY",
+ Title: "table.require-pk",
Content: "Table `t` requires PRIMARY KEY",
},
},
@@ -207,7 +207,7 @@ func TestRequirePK(t *testing.T) {
{
Status: advisor.Error,
Code: common.TableNoPK,
- Title: "Require PRIMARY KEY",
+ Title: "table.require-pk",
Content: "Table `t` requires PRIMARY KEY",
},
},
diff --git a/plugin/advisor/mysql/advisor_use_innodb.go b/plugin/advisor/mysql/advisor_use_innodb.go
index 69759e917f..463e63a927 100644
--- a/plugin/advisor/mysql/advisor_use_innodb.go
+++ b/plugin/advisor/mysql/advisor_use_innodb.go
@@ -42,6 +42,7 @@ func (adv *UseInnoDBAdvisor) Check(ctx advisor.Context, statement string) ([]adv
checker := &useInnoDBChecker{
level: level,
+ title: string(ctx.Rule.Type),
}
for _, stmtNode := range root {
@@ -62,6 +63,7 @@ func (adv *UseInnoDBAdvisor) Check(ctx advisor.Context, statement string) ([]adv
type useInnoDBChecker struct {
adviceList []advisor.Advice
level advisor.Status
+ title string
}
// Enter implements the ast.Visitor interface
@@ -116,7 +118,7 @@ func (v *useInnoDBChecker) Enter(in ast.Node) (ast.Node, bool) {
v.adviceList = append(v.adviceList, advisor.Advice{
Status: v.level,
Code: code,
- Title: "InnoDB engine is not used",
+ Title: v.title,
Content: fmt.Sprintf("\"%s\" doesn't use InnoDB engine", in.Text()),
})
}
diff --git a/plugin/advisor/mysql/advisor_use_innodb_test.go b/plugin/advisor/mysql/advisor_use_innodb_test.go
index 962bf91894..b7dbca8559 100644
--- a/plugin/advisor/mysql/advisor_use_innodb_test.go
+++ b/plugin/advisor/mysql/advisor_use_innodb_test.go
@@ -38,7 +38,7 @@ func TestUseInnoDB(t *testing.T) {
{
Status: advisor.Error,
Code: common.NotInnoDBEngine,
- Title: "InnoDB engine is not used",
+ Title: "engine.mysql.use-innodb",
Content: "\"CREATE TABLE book(id int) ENGINE = CSV\" doesn't use InnoDB engine",
},
},
@@ -60,7 +60,7 @@ func TestUseInnoDB(t *testing.T) {
{
Status: advisor.Error,
Code: common.NotInnoDBEngine,
- Title: "InnoDB engine is not used",
+ Title: "engine.mysql.use-innodb",
Content: "\"ALTER TABLE book ENGINE = CSV\" doesn't use InnoDB engine",
},
},
@@ -82,7 +82,7 @@ func TestUseInnoDB(t *testing.T) {
{
Status: advisor.Error,
Code: common.NotInnoDBEngine,
- Title: "InnoDB engine is not used",
+ Title: "engine.mysql.use-innodb",
Content: "\"SET default_storage_engine=CSV\" doesn't use InnoDB engine",
},
},
diff --git a/tests/schema_system_test.go b/tests/schema_system_test.go
index 8b2244304f..a8acd475da 100644
--- a/tests/schema_system_test.go
+++ b/tests/schema_system_test.go
@@ -88,68 +88,68 @@ func TestSchemaSystem(t *testing.T) {
{
Status: api.TaskCheckStatusError,
Code: common.NotInnoDBEngine,
- Title: "InnoDB engine is not used",
+ Title: "engine.mysql.use-innodb",
Content: fmt.Sprintf("%q doesn't use InnoDB engine", statements[1]),
},
{
Status: api.TaskCheckStatusWarn,
Code: common.NamingTableConventionMismatch,
- Title: "Mismatch table naming convention",
+ Title: "naming.table",
Content: "`userTable` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
{
Status: api.TaskCheckStatusWarn,
Code: common.NamingColumnConventionMismatch,
- Title: "Mismatch column naming convention",
+ Title: "naming.column",
Content: "`userTable`.`roomId` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",
},
{
Status: api.TaskCheckStatusWarn,
Code: common.NamingIndexConventionMismatch,
- Title: "Mismatch index naming convention",
+ Title: "naming.index.idx",
Content: "Index in table `userTable` mismatches the naming convention, expect \"^idx_userTable_name$\" but found `idx1`",
},
{
Status: api.TaskCheckStatusWarn,
Code: common.NamingUKConventionMismatch,
- Title: "Mismatch unique key naming convention",
+ Title: "naming.index.uk",
Content: "Unique key in table `userTable` mismatches the naming convention, expect \"^uk_userTable_id_name$\" but found `uk1`",
},
{
Status: api.TaskCheckStatusWarn,
Code: common.NamingFKConventionMismatch,
- Title: "Mismatch foreign key naming convention",
+ Title: "naming.index.fk",
Content: "Foreign key in table `userTable` mismatches the naming convention, expect \"^fk_userTable_roomId_room_id$\" but found `fk1`",
},
{
Status: api.TaskCheckStatusError,
Code: common.TableNoPK,
- Title: "Require PRIMARY KEY",
+ Title: "table.require-pk",
Content: "Table `userTable` requires PRIMARY KEY",
},
{
Status: api.TaskCheckStatusWarn,
Code: common.NoRequiredColumn,
- Title: "Require columns",
+ Title: "column.required",
Content: "Table `userTable` requires columns: created_ts, creator_id, updated_ts, updater_id",
},
{
Status: api.TaskCheckStatusWarn,
- Code: common.ColumnCanNull,
- Title: "Column can have NULL value",
- Content: "`userTable`.`id` can have NULL value",
+ Code: common.ColumnCanNotNull,
+ Title: "column.no-null",
+ Content: "`userTable`.`id` can not have NULL value",
},
{
Status: api.TaskCheckStatusWarn,
- Code: common.ColumnCanNull,
- Title: "Column can have NULL value",
- Content: "`userTable`.`name` can have NULL value",
+ Code: common.ColumnCanNotNull,
+ Title: "column.no-null",
+ Content: "`userTable`.`name` can not have NULL value",
},
{
Status: api.TaskCheckStatusWarn,
- Code: common.ColumnCanNull,
- Title: "Column can have NULL value",
- Content: "`userTable`.`roomId` can have NULL value",
+ Code: common.ColumnCanNotNull,
+ Title: "column.no-null",
+ Content: "`userTable`.`roomId` can not have NULL value",
},
},
},
@@ -159,7 +159,7 @@ func TestSchemaSystem(t *testing.T) {
{
Status: api.TaskCheckStatusError,
Code: common.StatementNoWhere,
- Title: "Require WHERE clause",
+ Title: "statement.where.require",
Content: "\"DELETE FROM t\" requires WHERE clause",
},
},
@@ -170,7 +170,7 @@ func TestSchemaSystem(t *testing.T) {
{
Status: api.TaskCheckStatusError,
Code: common.StatementLeadingWildcardLike,
- Title: "No leading wildcard LIKE",
+ Title: "statement.where.no-leading-wildcard-like",
Content: "\"DELETE FROM t WHERE a like `%abc`\" uses leading wildcard LIKE",
},
},
@@ -181,13 +181,13 @@ func TestSchemaSystem(t *testing.T) {
{
Status: api.TaskCheckStatusError,
Code: common.StatementSelectAll,
- Title: "Not SELECT all",
+ Title: "statement.select.no-select-all",
Content: "\"INSERT INTO t_copy SELECT * FROM t\" uses SELECT all",
},
{
Status: api.TaskCheckStatusError,
Code: common.StatementNoWhere,
- Title: "Require WHERE clause",
+ Title: "statement.where.require",
Content: "\"INSERT INTO t_copy SELECT * FROM t\" requires WHERE clause",
},
},
@@ -209,7 +209,7 @@ func TestSchemaSystem(t *testing.T) {
{
Status: api.TaskCheckStatusWarn,
Code: common.CompatibilityDropTable,
- Title: "Potential incompatible migration",
+ Title: "schema.backward-compatibility",
Content: "\"DROP TABLE user\" may cause incompatibility with the existing data and code",
},
},