Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: refactor /plugin/advisor/mysql test framework (#3887)
rebelice31c96a657fa1
diff --git a/plugin/advisor/mysql/advisor_charset_allowlist_test.go b/plugin/advisor/mysql/advisor_charset_allowlist_test.godeleted file mode 100644index 7cbc3655f3..0000000000--- a/plugin/advisor/mysql/advisor_charset_allowlist_test.go+++ /dev/null@@ -1,152 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestCharsetAllowlist(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a int) CHARSET utf8mb4`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a varchar(255))`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a int) CHARSET ascii`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCharset,- Title: "system.charset.allowlist",- Content: "\"CREATE TABLE t(a int) CHARSET ascii\" used disabled charset 'ascii'",- Line: 1,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t CHARSET ascii`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCharset,- Title: "system.charset.allowlist",- Content: "\"ALTER TABLE t CHARSET ascii\" used disabled charset 'ascii'",- Line: 3,- },- },- },- {- Statement: `ALTER DATABASE test CHARSET ascii`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCharset,- Title: "system.charset.allowlist",- Content: "\"ALTER DATABASE test CHARSET ascii\" used disabled charset 'ascii'",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(a varchar(255) CHARSET ascii)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCharset,- Title: "system.charset.allowlist",- Content: "\"CREATE TABLE t(a varchar(255) CHARSET ascii)\" used disabled charset 'ascii'",- Line: 1,- },- },- },- {- Statement: `- CREATE TABLE t(b int);- ALTER TABLE t ADD COLUMN a varchar(255) CHARSET ascii`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCharset,- Title: "system.charset.allowlist",- Content: "\"ALTER TABLE t ADD COLUMN a varchar(255) CHARSET ascii\" used disabled charset 'ascii'",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t MODIFY COLUMN a varchar(255) CHARSET ascii`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCharset,- Title: "system.charset.allowlist",- Content: "\"ALTER TABLE t MODIFY COLUMN a varchar(255) CHARSET ascii\" used disabled charset 'ascii'",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t CHANGE COLUMN a a varchar(255) CHARSET ascii`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCharset,- Title: "system.charset.allowlist",- Content: "\"ALTER TABLE t CHANGE COLUMN a a varchar(255) CHARSET ascii\" used disabled charset 'ascii'",- Line: 3,- },- },- },- {- Statement: "/* this is a comment */",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }-- payload, err := json.Marshal(advisor.StringArrayTypeRulePayload{- List: []string{"utf8mb4"},- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &CharsetAllowlistAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleCharsetAllowlist,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_collation_allowlist_test.go b/plugin/advisor/mysql/advisor_collation_allowlist_test.godeleted file mode 100644index 60408ae7c3..0000000000--- a/plugin/advisor/mysql/advisor_collation_allowlist_test.go+++ /dev/null@@ -1,141 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestCollationAllowlist(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a int) COLLATE utf8mb4_polish_ci`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a varchar(255))`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a int) COLLATE latin1_bin`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCollation,- Title: "system.collation.allowlist",- Content: "\"CREATE TABLE t(a int) COLLATE latin1_bin\" used disabled collation 'latin1_bin'",- Line: 1,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t COLLATE latin1_bin`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCollation,- Title: "system.collation.allowlist",- Content: "\"ALTER TABLE t COLLATE latin1_bin\" used disabled collation 'latin1_bin'",- Line: 3,- },- },- },- {- Statement: `ALTER DATABASE test COLLATE latin1_bin`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCollation,- Title: "system.collation.allowlist",- Content: "\"ALTER DATABASE test COLLATE latin1_bin\" used disabled collation 'latin1_bin'",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCollation,- Title: "system.collation.allowlist",- Content: "\"CREATE TABLE t(a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin)\" used disabled collation 'latin1_bin'",- Line: 1,- },- },- },- {- Statement: `- CREATE TABLE t(b int);- ALTER TABLE t ADD COLUMN a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCollation,- Title: "system.collation.allowlist",- Content: "\"ALTER TABLE t ADD COLUMN a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin\" used disabled collation 'latin1_bin'",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t MODIFY COLUMN a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCollation,- Title: "system.collation.allowlist",- Content: "\"ALTER TABLE t MODIFY COLUMN a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin\" used disabled collation 'latin1_bin'",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t CHANGE COLUMN a a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledCollation,- Title: "system.collation.allowlist",- Content: "\"ALTER TABLE t CHANGE COLUMN a a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin\" used disabled collation 'latin1_bin'",- Line: 3,- },- },- },- }-- payload, err := json.Marshal(advisor.StringArrayTypeRulePayload{- List: []string{"utf8mb4_polish_ci"},- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &CollationAllowlistAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleCollationAllowlist,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_colum_require_default_test.go b/plugin/advisor/mysql/advisor_colum_require_default_test.godeleted file mode 100644index 12e3291a62..0000000000--- a/plugin/advisor/mysql/advisor_colum_require_default_test.go+++ /dev/null@@ -1,70 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumRequireDefault(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a int primary key, b int default 1)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE t(- a int,- b int default 1- )`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoDefault,- Title: "column.require-default",- Content: "Column `t`.`a` doesn't have DEFAULT.",- Line: 3,- },- },- },- {- Statement: `- ALTER TABLE tech_book ADD COLUMN a BLOB;- ALTER TABLE tech_book ADD COLUMN b timestamp;- ALTER TABLE tech_book MODIFY COLUMN a varchar(220);- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoDefault,- Title: "column.require-default",- Content: "Column `tech_book`.`b` doesn't have DEFAULT.",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.NoDefault,- Title: "column.require-default",- Content: "Column `tech_book`.`a` doesn't have DEFAULT.",- Line: 4,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &ColumRequireDefaultAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnRequireDefault,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_auto_increment_initial_value_test.go b/plugin/advisor/mysql/advisor_column_auto_increment_initial_value_test.godeleted file mode 100644index aaf54dfcad..0000000000--- a/plugin/advisor/mysql/advisor_column_auto_increment_initial_value_test.go+++ /dev/null@@ -1,61 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnAutoIncrementInitialValue(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a int)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a int auto_increment) auto_increment = 1`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a int auto_increment) auto_increment = 2`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.AutoIncrementColumnInitialValueNotMatch,- Title: "column.auto-increment-initial-value",- Content: "The initial auto-increment value in table `t` is 2, which doesn't equal 1",- Line: 1,- },- },- },- }-- payload, err := json.Marshal(advisor.NumberTypeRulePayload{- Number: 1,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &ColumnAutoIncrementInitialValueAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnAutoIncrementInitialValue,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_auto_increment_must_integer_test.go b/plugin/advisor/mysql/advisor_column_auto_increment_must_integer_test.godeleted file mode 100644index e6110e6f16..0000000000--- a/plugin/advisor/mysql/advisor_column_auto_increment_must_integer_test.go+++ /dev/null@@ -1,85 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnAutoIncrementMustInteger(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a INT AUTO_INCREMENT)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a varchar(255) AUTO_INCREMENT)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.AutoIncrementColumnNotInteger,- Title: "column.auto-increment-must-integer",- Content: "Auto-increment column `t`.`a` requires integer type",- Line: 1,- },- },- },- {- Statement: `- CREATE TABLE t(b int);- ALTER TABLE t ADD COLUMN a varchar(255) AUTO_INCREMENT`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.AutoIncrementColumnNotInteger,- Title: "column.auto-increment-must-integer",- Content: "Auto-increment column `t`.`a` requires integer type",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t MODIFY COLUMN a varchar(255) AUTO_INCREMENT`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.AutoIncrementColumnNotInteger,- Title: "column.auto-increment-must-integer",- Content: "Auto-increment column `t`.`a` requires integer type",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(b int);- ALTER TABLE t CHANGE COLUMN b a varchar(255) AUTO_INCREMENT`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.AutoIncrementColumnNotInteger,- Title: "column.auto-increment-must-integer",- Content: "Auto-increment column `t`.`a` requires integer type",- Line: 3,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &ColumnAutoIncrementMustIntegerAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnAutoIncrementMustInteger,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned_test.go b/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned_test.godeleted file mode 100644index 4f6a6708f7..0000000000--- a/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned_test.go+++ /dev/null@@ -1,85 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnAutoIncrementMustUnsigned(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a INT UNSIGNED AUTO_INCREMENT)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a INT AUTO_INCREMENT)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.AutoIncrementColumnSigned,- Title: "column.auto-increment-must-unsigned",- Content: "Auto-increment column `t`.`a` is not UNSIGNED type",- Line: 1,- },- },- },- {- Statement: `- CREATE TABLE t(b int);- ALTER TABLE t ADD COLUMN a INT AUTO_INCREMENT`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.AutoIncrementColumnSigned,- Title: "column.auto-increment-must-unsigned",- Content: "Auto-increment column `t`.`a` is not UNSIGNED type",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t MODIFY COLUMN a INT AUTO_INCREMENT`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.AutoIncrementColumnSigned,- Title: "column.auto-increment-must-unsigned",- Content: "Auto-increment column `t`.`a` is not UNSIGNED type",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(b int);- ALTER TABLE t CHANGE COLUMN b a INT AUTO_INCREMENT`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.AutoIncrementColumnSigned,- Title: "column.auto-increment-must-unsigned",- Content: "Auto-increment column `t`.`a` is not UNSIGNED type",- Line: 3,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &ColumnAutoIncrementMustUnsignedAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnAutoIncrementMustUnsigned,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_comment_convention_test.go b/plugin/advisor/mysql/advisor_column_comment_convention_test.godeleted file mode 100644index d1717ce095..0000000000--- a/plugin/advisor/mysql/advisor_column_comment_convention_test.go+++ /dev/null@@ -1,117 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnCommentConvention(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a int COMMENT 'some comments')`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(- a int COMMENT 'some comments',- b int,- c int)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoColumnComment,- Title: "column.comment",- Content: "Column `t`.`b` requires comments",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.NoColumnComment,- Title: "column.comment",- Content: "Column `t`.`c` requires comments",- Line: 4,- },- },- },- {- Statement: `- CREATE TABLE t(a int COMMENT 'comment');- ALTER TABLE t ADD COLUMN b int`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoColumnComment,- Title: "column.comment",- Content: "Column `t`.`b` requires comments",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int COMMENT 'this is comment');- ALTER TABLE t CHANGE COLUMN a b int`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoColumnComment,- Title: "column.comment",- Content: "Column `t`.`b` requires comments",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(b int COMMENT 'It is comment');- ALTER TABLE t MODIFY COLUMN b int`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoColumnComment,- Title: "column.comment",- Content: "Column `t`.`b` requires comments",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(b int COMMENT 'It is COMMENT');- ALTER TABLE t MODIFY COLUMN b int COMMENT 'abcdefghiakljhakljdsfalugelkhnabsdguelkadf'`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ColumnCommentTooLong,- Title: "column.comment",- Content: "The length of column `t`.`b` comment should be within 20 characters",- Line: 3,- },- },- },- }-- payload, err := json.Marshal(advisor.CommentConventionRulePayload{- Required: true,- MaxLength: 20,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &ColumnCommentConventionAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnCommentConvention,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_current_time_count_limit_test.go b/plugin/advisor/mysql/advisor_column_current_time_count_limit_test.godeleted file mode 100644index 19fd0710c1..0000000000--- a/plugin/advisor/mysql/advisor_column_current_time_count_limit_test.go+++ /dev/null@@ -1,79 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnCurrentTimeCountLimit(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a timestamp, b timestamp)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE t(- a timestamp default now(),- b timestamp default current_timestamp(),- c timestamp default localtime- )`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DefaultCurrentTimeColumnCountExceedsLimit,- Title: "column.current-time-count-limit",- Content: "Table `t` has 3 DEFAULT CURRENT_TIMESTAMP() columns. The count greater than 2.",- Line: 6,- },- },- },- {- Statement: `- CREATE TABLE t(- a timestamp default now() on update localtime,- b timestamp default current_timestamp() on update localtimestamp()- )`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.OnUpdateCurrentTimeColumnCountExceedsLimit,- Title: "column.current-time-count-limit",- Content: "Table `t` has 2 ON UPDATE CURRENT_TIMESTAMP() columns. The count greater than 1.",- Line: 5,- },- },- },- {- Statement: `- ALTER TABLE tech_book ADD COLUMN a timestamp default now() on update localtime;- ALTER TABLE tech_book ADD COLUMN b timestamp default current_timestamp() on update localtimestamp();- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.OnUpdateCurrentTimeColumnCountExceedsLimit,- Title: "column.current-time-count-limit",- Content: "Table `tech_book` has 2 ON UPDATE CURRENT_TIMESTAMP() columns. The count greater than 1.",- Line: 3,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &ColumnCurrentTimeCountLimitAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleCurrentTimeColumnCountLimit,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_disallow_changing_order_test.go b/plugin/advisor/mysql/advisor_column_disallow_changing_order_test.godeleted file mode 100644index ee8b9d8bed..0000000000--- a/plugin/advisor/mysql/advisor_column_disallow_changing_order_test.go+++ /dev/null@@ -1,89 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnDisallowChangingOrder(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t MODIFY COLUMN a int`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t MODIFY COLUMN a int FIRST`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ChangeColumnOrder,- Title: "column.disallow-changing-order",- Content: "\"ALTER TABLE t MODIFY COLUMN a int FIRST\" changes column order",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(b int, a1 int);- ALTER TABLE t CHANGE COLUMN a1 a int FIRST`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ChangeColumnOrder,- Title: "column.disallow-changing-order",- Content: "\"ALTER TABLE t CHANGE COLUMN a1 a int FIRST\" changes column order",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int, b int);- ALTER TABLE t MODIFY COLUMN a int AFTER b`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ChangeColumnOrder,- Title: "column.disallow-changing-order",- Content: "\"ALTER TABLE t MODIFY COLUMN a int AFTER b\" changes column order",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a1 int, b int);- ALTER TABLE t CHANGE COLUMN a1 a int AFTER b`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ChangeColumnOrder,- Title: "column.disallow-changing-order",- Content: "\"ALTER TABLE t CHANGE COLUMN a1 a int AFTER b\" changes column order",- Line: 3,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &ColumnDisallowChangingOrderAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnDisallowChangingOrder,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_disallow_changing_test.go b/plugin/advisor/mysql/advisor_column_disallow_changing_test.godeleted file mode 100644index b9ba66c87b..0000000000--- a/plugin/advisor/mysql/advisor_column_disallow_changing_test.go+++ /dev/null@@ -1,47 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnDisallowChanging(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `- CREATE TABLE t(b int);- ALTER TABLE t ADD COLUMN a int`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE t(b int);- ALTER TABLE t CHANGE COLUMN b a int`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.UseChangeColumnStatement,- Title: "column.disallow-change",- Content: "\"ALTER TABLE t CHANGE COLUMN b a int\" contains CHANGE COLUMN statement",- Line: 3,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &ColumnDisallowChangingAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnDisallowChange,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_disallow_changing_type_test.go b/plugin/advisor/mysql/advisor_column_disallow_changing_type_test.godeleted file mode 100644index 89246945cf..0000000000--- a/plugin/advisor/mysql/advisor_column_disallow_changing_type_test.go+++ /dev/null@@ -1,67 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnDisallowChangingType(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `ALTER TABLE tech_book MODIFY id INTEGER UNSIGNED`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ChangeColumnType,- Title: "column.disallow-change-type",- Content: "\"ALTER TABLE tech_book MODIFY id INTEGER UNSIGNED\" changes column type",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book MODIFY id int`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `ALTER TABLE tech_book MODIFY id bigint`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ChangeColumnType,- Title: "column.disallow-change-type",- Content: "\"ALTER TABLE tech_book MODIFY id bigint\" changes column type",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book CHANGE name uname varchar(20)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ChangeColumnType,- Title: "column.disallow-change-type",- Content: "\"ALTER TABLE tech_book CHANGE name uname varchar(20)\" changes column type",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &ColumnDisallowChangingTypeAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnDisallowChangeType,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_disallow_set_charset_test.go b/plugin/advisor/mysql/advisor_column_disallow_set_charset_test.godeleted file mode 100644index 3c906581ab..0000000000--- a/plugin/advisor/mysql/advisor_column_disallow_set_charset_test.go+++ /dev/null@@ -1,79 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnDisallowSetCharset(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a varchar(20))`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a varchar(20) CHARSET ascii)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.SetColumnCharset,- Title: "column.disallow-set-charset",- Content: "Disallow set column charset but \"CREATE TABLE t(a varchar(20) CHARSET ascii)\" does",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book ADD COLUMN a varchar(20) CHARSET ascii`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.SetColumnCharset,- Title: "column.disallow-set-charset",- Content: "Disallow set column charset but \"ALTER TABLE tech_book ADD COLUMN a varchar(20) CHARSET ascii\" does",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book MODIFY COLUMN id varchar(20) CHARSET ascii`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.SetColumnCharset,- Title: "column.disallow-set-charset",- Content: "Disallow set column charset but \"ALTER TABLE tech_book MODIFY COLUMN id varchar(20) CHARSET ascii\" does",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book CHANGE COLUMN name name varchar(20) CHARSET ascii`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.SetColumnCharset,- Title: "column.disallow-set-charset",- Content: "Disallow set column charset but \"ALTER TABLE tech_book CHANGE COLUMN name name varchar(20) CHARSET ascii\" does",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &ColumnDisallowSetCharsetAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnDisallowSetCharset,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_maximum_character_length_test.go b/plugin/advisor/mysql/advisor_column_maximum_character_length_test.godeleted file mode 100644index 775fcc336e..0000000000--- a/plugin/advisor/mysql/advisor_column_maximum_character_length_test.go+++ /dev/null@@ -1,97 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnMaximumCharacterLength(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(name char(20));`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(name varchar(225));`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(name char(225));`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CharLengthExceedsLimit,- Title: "column.maximum-character-length",- Content: "The length of the CHAR column `name` is bigger than 20, please use VARCHAR instead",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book ADD COLUMN name_2 char(225)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CharLengthExceedsLimit,- Title: "column.maximum-character-length",- Content: "The length of the CHAR column `name_2` is bigger than 20, please use VARCHAR instead",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book CHANGE COLUMN name name char(225)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CharLengthExceedsLimit,- Title: "column.maximum-character-length",- Content: "The length of the CHAR column `name` is bigger than 20, please use VARCHAR instead",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book MODIFY COLUMN name char(225)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CharLengthExceedsLimit,- Title: "column.maximum-character-length",- Content: "The length of the CHAR column `name` is bigger than 20, please use VARCHAR instead",- Line: 1,- },- },- },- }-- payload, err := json.Marshal(advisor.NumberTypeRulePayload{- Number: 20,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &ColumnMaximumCharacterLengthAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnMaximumCharacterLength,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_no_null_test.go b/plugin/advisor/mysql/advisor_column_no_null_test.godeleted file mode 100644index 4ad1995794..0000000000--- a/plugin/advisor/mysql/advisor_column_no_null_test.go+++ /dev/null@@ -1,131 +0,0 @@-package mysql--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnNoNull(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE book(- id int,- name varchar(255))`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ColumnCannotNull,- Title: "column.no-null",- Content: "`book`.`id` cannot have NULL value",- Line: 2,- },- {- Status: advisor.Warn,- Code: advisor.ColumnCannotNull,- Title: "column.no-null",- Content: "`book`.`name` cannot have NULL value",- Line: 3,- },- },- },- {- Statement: "CREATE TABLE book(id int PRIMARY KEY, name varchar(255))",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ColumnCannotNull,- Title: "column.no-null",- Content: "`book`.`name` cannot have NULL value",- Line: 1,- },- },- },- {- Statement: "CREATE TABLE book(id int NOT NULL, name varchar(255))",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ColumnCannotNull,- Title: "column.no-null",- Content: "`book`.`name` cannot have NULL value",- Line: 1,- },- },- },- {- Statement: "CREATE TABLE book(id int PRIMARY KEY, name varchar(255) NOT NULL)",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE book(a int NOT NULL);- ALTER TABLE book ADD COLUMN (id int, name varchar(255) NOT NULL);- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ColumnCannotNull,- Title: "column.no-null",- Content: "`book`.`id` cannot have NULL value",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE book(a int NOT NULL);- ALTER TABLE book ADD COLUMN (id int PRIMARY KEY, name varchar(255) NOT NULL);- `,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE book(id int NOT NULL);- ALTER TABLE book CHANGE COLUMN id name varchar(255);- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.ColumnCannotNull,- Title: "column.no-null",- Content: "`book`.`name` cannot have NULL value",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE book(id int NOT NULL);- ALTER TABLE book CHANGE COLUMN id name varchar(255) NOT NULL;`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &ColumnNoNullAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnNotNull,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_required_test.go b/plugin/advisor/mysql/advisor_column_required_test.godeleted file mode 100644index 2aac3d8768..0000000000--- a/plugin/advisor/mysql/advisor_column_required_test.go+++ /dev/null@@ -1,245 +0,0 @@-package mysql--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnRequirement(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "CREATE TABLE book(id int)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoRequiredColumn,- Title: "column.required",- Content: "Table `book` requires columns: created_ts, creator_id, updated_ts, updater_id",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator_id int,- created_ts timestamp,- updater_id int,- updated_ts timestamp)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator_id int,- created_ts timestamp,- updater_id int,- updated_ts timestamp);- ALTER TABLE book RENAME COLUMN creator_id TO creator;`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoRequiredColumn,- Title: "column.required",- Content: "Table `book` requires columns: creator_id",- Line: 7,- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator int,- created_ts timestamp,- updater_id int,- updated_ts timestamp);- ALTER TABLE book RENAME COLUMN creator TO creator_id;`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator_id int,- created_ts timestamp,- updater_id int,- updated_ts timestamp);- ALTER TABLE book CHANGE COLUMN creator_id creator int;`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoRequiredColumn,- Title: "column.required",- Content: "Table `book` requires columns: creator_id",- Line: 7,- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator int,- created_ts timestamp,- updater_id int,- updated_ts timestamp);- ALTER TABLE book CHANGE COLUMN creator creator_id int;`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator_id int,- created_ts timestamp,- updater_id int,- updated_ts timestamp);- ALTER TABLE book DROP COLUMN creator_id;`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoRequiredColumn,- Title: "column.required",- Content: "Table `book` requires columns: creator_id",- Line: 7,- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator_id int,- created_ts timestamp,- updater_id int,- updated_ts timestamp,- content varchar(255));- ALTER TABLE book DROP COLUMN content;`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator_id int,- created_ts timestamp,- updated_ts timestamp);- ALTER TABLE book ADD COLUMN content varchar(255);`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoRequiredColumn,- Title: "column.required",- Content: "Table `book` requires columns: updater_id",- Line: 5,- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator int,- created_ts timestamp,- updater_id int,- updated_ts timestamp);- ALTER TABLE book ADD COLUMN creator_id int;`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(- id int,- created_ts timestamp,- updater_id int,- updated_ts timestamp);- CREATE TABLE student(- id int,- created_ts timestamp,- updated_ts timestamp)--- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoRequiredColumn,- Title: "column.required",- Content: "Table `book` requires columns: creator_id",- Line: 5,- },- {- Status: advisor.Warn,- Code: advisor.NoRequiredColumn,- Title: "column.required",- Content: "Table `student` requires columns: creator_id, updater_id",- Line: 9,- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator int,- created_ts timestamp,- updater_id int,- updated_ts timestamp);- DROP TABLE book;`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }- payload, err := json.Marshal(advisor.StringArrayTypeRulePayload{- List: []string{- "id",- "created_ts",- "updated_ts",- "creator_id",- "updater_id",- },- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &ColumnRequirementAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleRequiredColumn,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_set_default_for_not_null_test.go b/plugin/advisor/mysql/advisor_column_set_default_for_not_null_test.godeleted file mode 100644index 0b2a315143..0000000000--- a/plugin/advisor/mysql/advisor_column_set_default_for_not_null_test.go+++ /dev/null@@ -1,173 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnSetDefaultForNotNull(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE book(- id int PRIMARY KEY DEFAULT 0- )`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(- id int PRIMARY KEY- )`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(- id int NOT NULL- )`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NotNullColumnWithNoDefault,- Title: "column.set-default-for-not-null",- Content: "Column `book`.`id` is NOT NULL but doesn't have DEFAULT",- Line: 2,- },- },- },- {- Statement: `CREATE TABLE book(- id int,- PRIMARY KEY (id)- )`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NotNullColumnWithNoDefault,- Title: "column.set-default-for-not-null",- Content: "Column `book`.`id` is NOT NULL but doesn't have DEFAULT",- Line: 2,- },- },- },- {- Statement: `- CREATE TABLE book(a int);- ALTER TABLE book ADD COLUMN id int PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE book(a int);- ALTER TABLE book ADD COLUMN id int NOT NULL`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NotNullColumnWithNoDefault,- Title: "column.set-default-for-not-null",- Content: "Column `book`.`id` is NOT NULL but doesn't have DEFAULT",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE book(id int);- ALTER TABLE book MODIFY COLUMN id int NOT NULL`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NotNullColumnWithNoDefault,- Title: "column.set-default-for-not-null",- Content: "Column `book`.`id` is NOT NULL but doesn't have DEFAULT",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE book(id int);- ALTER TABLE book MODIFY COLUMN id int PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE book(uid int);- ALTER TABLE book CHANGE COLUMN uid id int PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE book(uid int);- ALTER TABLE book CHANGE COLUMN uid id int NOT NULL`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NotNullColumnWithNoDefault,- Title: "column.set-default-for-not-null",- Content: "Column `book`.`id` is NOT NULL but doesn't have DEFAULT",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE book(uid int, id int);- ALTER TABLE book- CHANGE COLUMN uid uid int NOT NULL DEFAULT 0,- MODIFY COLUMN id int PRIMARY KEY DEFAULT 0,- ADD COLUMN name varchar(20) NOT NULL DEFAULT ''- `,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &ColumnSetDefaultForNotNullAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnSetDefaultForNotNull,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_column_type_restriction_test.go b/plugin/advisor/mysql/advisor_column_type_restriction_test.godeleted file mode 100644index 1bcc4f54bb..0000000000--- a/plugin/advisor/mysql/advisor_column_type_restriction_test.go+++ /dev/null@@ -1,113 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestColumnTypeRestriction(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a int)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a JSON, b BLOB, c TEXT)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledColumnType,- Title: "column.type-disallow-list",- Content: "Disallow column type JSON but column `t`.`a` is",- Line: 1,- },- {- Status: advisor.Warn,- Code: advisor.DisabledColumnType,- Title: "column.type-disallow-list",- Content: "Disallow column type BLOB but column `t`.`b` is",- Line: 1,- },- {- Status: advisor.Warn,- Code: advisor.DisabledColumnType,- Title: "column.type-disallow-list",- Content: "Disallow column type TEXT but column `t`.`c` is",- Line: 1,- },- },- },- {- Statement: `- CREATE TABLE t(d int);- ALTER TABLE t add COLUMN (a JSON, b BLOB, c TEXT)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledColumnType,- Title: "column.type-disallow-list",- Content: "Disallow column type JSON but column `t`.`a` is",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.DisabledColumnType,- Title: "column.type-disallow-list",- Content: "Disallow column type BLOB but column `t`.`b` is",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.DisabledColumnType,- Title: "column.type-disallow-list",- Content: "Disallow column type TEXT but column `t`.`c` is",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(c int, b int);- ALTER TABLE t CHANGE COLUMN c a JSON, MODIFY b BLOB`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DisabledColumnType,- Title: "column.type-disallow-list",- Content: "Disallow column type JSON but column `t`.`a` is",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.DisabledColumnType,- Title: "column.type-disallow-list",- Content: "Disallow column type BLOB but column `t`.`b` is",- Line: 3,- },- },- },- }-- payload, err := json.Marshal(advisor.StringArrayTypeRulePayload{- List: []string{"JSON", "BLOB", "TEXT"},- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &ColumnTypeRestrictionAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnTypeDisallowList,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_database_drop_empty_db_test.go b/plugin/advisor/mysql/advisor_database_drop_empty_db_test.godeleted file mode 100644index 38a1b103bb..0000000000--- a/plugin/advisor/mysql/advisor_database_drop_empty_db_test.go+++ /dev/null@@ -1,30 +0,0 @@-package mysql--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestMySQLDatabaseAllowDropIfEmpty(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "DROP DATABASE IF EXISTS test",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.DatabaseNotEmpty,- Title: "database.drop-empty-database",- Content: "Database `test` is not allowed to drop if not empty",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &DatabaseAllowDropIfEmptyAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleDropEmptyDatabase,- Level: advisor.SchemaRuleLevelError,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_index_key_number_limit_test.go b/plugin/advisor/mysql/advisor_index_key_number_limit_test.godeleted file mode 100644index 29d2ff3f52..0000000000--- a/plugin/advisor/mysql/advisor_index_key_number_limit_test.go+++ /dev/null@@ -1,95 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestIndexKeyNumberLimit(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a int, b int, primary key (a, b))`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(- a int,- b int,- primary key pk (a, b, b, b, b, b, b))`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexKeyNumberExceedsLimit,- Title: "index.key-number-limit",- Content: "The number of index `pk` in table `t` should be not greater than 5",- Line: 4,- },- },- },- {- Statement: `- CREATE TABLE t(a int, b int, c int, d int, e int, f int, g int);- CREATE INDEX idx ON t(a, b, c, d, e, f, g)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexKeyNumberExceedsLimit,- Title: "index.key-number-limit",- Content: "The number of index `idx` in table `t` should be not greater than 5",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int, b int, c int, d int, e int, f int, g int);- ALTER TABLE t ADD UNIQUE KEY uk (a, b, c, d, e, f, g)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexKeyNumberExceedsLimit,- Title: "index.key-number-limit",- Content: "The number of index `uk` in table `t` should be not greater than 5",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int, b int, c int, d int, e int, f int, g int);- ALTER TABLE t ADD FOREIGN KEY uk (a, b, c, d, e, f, g) REFERENCES t1(a, b, c, d, e, f, g)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexKeyNumberExceedsLimit,- Title: "index.key-number-limit",- Content: "The number of index `uk` in table `t` should be not greater than 5",- Line: 3,- },- },- },- }-- payload, err := json.Marshal(advisor.NumberTypeRulePayload{- Number: 5,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &IndexKeyNumberLimitAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleIndexKeyNumberLimit,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_index_no_duplicate_column_test.go b/plugin/advisor/mysql/advisor_index_no_duplicate_column_test.godeleted file mode 100644index 614cac2f3a..0000000000--- a/plugin/advisor/mysql/advisor_index_no_duplicate_column_test.go+++ /dev/null@@ -1,115 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestIndexNoDuplicateColumn(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t (a int, PRIMARY KEY (a))`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t (- a int,- INDEX idx_a (a, a))`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DuplicateColumnInIndex,- Title: "index.no-duplicate-column",- Content: "INDEX `idx_a` has duplicate column `t`.`a`",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- CREATE INDEX idx_a on t(a, a)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DuplicateColumnInIndex,- Title: "index.no-duplicate-column",- Content: "INDEX `idx_a` has duplicate column `t`.`a`",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD INDEX idx_a (a, a)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DuplicateColumnInIndex,- Title: "index.no-duplicate-column",- Content: "INDEX `idx_a` has duplicate column `t`.`a`",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD PRIMARY KEY pk_a (a, a)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DuplicateColumnInIndex,- Title: "index.no-duplicate-column",- Content: "PRIMARY KEY `pk_a` has duplicate column `t`.`a`",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD UNIQUE KEY uk_a (a, a)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DuplicateColumnInIndex,- Title: "index.no-duplicate-column",- Content: "UNIQUE KEY `uk_a` has duplicate column `t`.`a`",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD FOREIGN KEY fk_a (a, a) REFERENCES t1(a, b)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DuplicateColumnInIndex,- Title: "index.no-duplicate-column",- Content: "FOREIGN KEY `fk_a` has duplicate column `t`.`a`",- Line: 3,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &IndexNoDuplicateColumnAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleIndexNoDuplicateColumn,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_index_pk_type_test.go b/plugin/advisor/mysql/advisor_index_pk_type_test.godeleted file mode 100644index 173edb1b55..0000000000--- a/plugin/advisor/mysql/advisor_index_pk_type_test.go+++ /dev/null@@ -1,306 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestIndexPkType(t *testing.T) {- tests := []advisor.TestCase{- // CREATE TABLE COLUMN OPTION PRIMARY KEY- {- Statement: `CREATE TABLE t(id VARCHAR(5) PRIMARY KEY)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(id INT PRIMARY KEY)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- // CREATE TABLE TABLE OPTION PRIAMRY KEY- {- Statement: `CREATE TABLE t(id VARCHAR(5), PRIMARY KEY(id))`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(id INT, id2 VARCHAR(5), id3 VARCHAR(5), PRIMARY KEY(id, id2, id3))`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id2` is varchar(5)",- Line: 1,- },- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id3` is varchar(5)",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(id INT, id2 BIGINT, PRIMARY KEY(id, id2))`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(id INT, PRIMARY KEY(id))`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- // ALTER TABLE ADD COLUMN OPTION PRIMARY KEY- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD COLUMN id VARCHAR(5) PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD COLUMN id INT PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- // ALTER TABLE ADD COLUMN ADD PRIAMRY KEY CONSTRAINT- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD COLUMN id VARCHAR(5), ADD PRIMARY KEY (id)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD COLUMN id INT, ADD COLUMN id2 VARCHAR(5), ADD COLUMN id3 VARCHAR(5), ADD PRIMARY KEY (id, id2, id3)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id2` is varchar(5)",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id3` is varchar(5)",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD COLUMN id INT, ADD COLUMN id2 BIGINT, ADD PRIMARY KEY (id, id2)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD COLUMN id BIGINT, ADD PRIMARY KEY (id)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- // CRAETE TABLE; ALTER TABLE ADD PRIMARY KEY CONSTRAINT- {- Statement: `CREATE TABLE t(id VARCHAR(5));- ALTER TABLE t ADD PRIMARY KEY(id);- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)",- Line: 2,- },- },- },- {- Statement: `CREATE TABLE t(id INT, id2 VARCHAR(5), id3 VARCHAR(5));- ALTER TABLE t ADD PRIMARY KEY(id, id2, id3);- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id2` is varchar(5)",- Line: 2,- },- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id3` is varchar(5)",- Line: 2,- },- },- },- {- Statement: `CREATE TABLE t(id INT, id2 BIGINT);- ALTER TABLE t ADD PRIMARY KEY(id, id2);- `,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(id BIGINT);- ALTER TABLE t ADD PRIMARY KEY(id);- `,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- // ALTER TABLE MODIFY COLUMN- {- Statement: `- CREATE TABLE t(id int);- ALTER TABLE t MODIFY COLUMN id VARCHAR(5) PRIMARY KEY;`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(id int);- ALTER TABLE t MODIFY COLUMN id INT(5) PRIMARY KEY;`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- // ALTER TABLE CHANGE COLUMN- {- Statement: `- CREATE TABLE t(id int);- ALTER TABLE t CHANGE COLUMN id id2 VARCHAR(5) PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexPKType,- Title: "index.pk-type-limit",- Content: "Columns in primary key must be INT/BIGINT but `t`.`id2` is varchar(5)",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(id int);- ALTER TABLE t CHANGE COLUMN id id2 INT(5) PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &IndexPkTypeAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleIndexPKTypeLimit,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_index_total_number_limit_test.go b/plugin/advisor/mysql/advisor_index_total_number_limit_test.godeleted file mode 100644index dc6c7ce83e..0000000000--- a/plugin/advisor/mysql/advisor_index_total_number_limit_test.go+++ /dev/null@@ -1,109 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestIndexTotalNumberLimit(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a int, b int, c int, unique key(a, b, c))`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE INDEX idx_id_name on tech_book(id, name)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- // tech_book had 3 indexes originally.- Statement: `- CREATE INDEX idx_id_name_1 on tech_book(id, name);- CREATE INDEX idx_id_name_2 on tech_book(id, name);- CREATE INDEX idx_id_name_3 on tech_book(id, name);- CREATE INDEX idx_id_name_4 on tech_book(id, name);- CREATE INDEX idx_id_name_5 on tech_book(id, name);- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexCountExceedsLimit,- Title: "index.total-number-limit",- Content: "The count of index in table `tech_book` should be no more than 5, but found 8",- Line: 6,- },- },- },- {- Statement: `- CREATE TABLE t(a int PRIMARY KEY, b int, c int);- CREATE INDEX idx_a_b_1 on t(a, b);- CREATE INDEX idx_a_b_2 on t(a, b);- CREATE INDEX idx_a_b_3 on t(a, b);- CREATE INDEX idx_a_b_4 on t(a, b);- CREATE INDEX idx_a_b_5 on t(a, b);- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexCountExceedsLimit,- Title: "index.total-number-limit",- Content: "The count of index in table `t` should be no more than 5, but found 6",- Line: 7,- },- },- },- {- Statement: `- CREATE TABLE t(- a int PRIMARY KEY,- b int,- c int,- INDEX idx_a_b_1 (a, b),- INDEX idx_a_b_2 (a, b),- INDEX idx_a_b_3 (a, b),- INDEX idx_a_b_4 (a, b),- INDEX idx_a_b_5 (a, b));- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexCountExceedsLimit,- Title: "index.total-number-limit",- Content: "The count of index in table `t` should be no more than 5, but found 6",- Line: 10,- },- },- },- }-- payload, err := json.Marshal(advisor.NumberTypeRulePayload{- Number: 5,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &IndexTotalNumberLimitAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleIndexTotalNumberLimit,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_index_type_no_blob_test.go b/plugin/advisor/mysql/advisor_index_type_no_blob_test.godeleted file mode 100644index 53397ef18d..0000000000--- a/plugin/advisor/mysql/advisor_index_type_no_blob_test.go+++ /dev/null@@ -1,251 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestIndexTypeNoBlob(t *testing.T) {- tests := []advisor.TestCase{- // CREATE TABLE TABLE OPTION INDEX- {- Statement: `CREATE TABLE t(b BLOB, PRIMARY KEY(b(10)))`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`b` is blob",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(b BLOB, mb MEDIUMBLOB, lb LONGBLOB, id INT, PRIMARY KEY(b(1), mb(2), lb(3), id))`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`b` is blob",- Line: 1,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`mb` is mediumblob",- Line: 1,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`lb` is longblob",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(b BLOB, mb MEDIUMBLOB, lb LONGBLOB, id INT, UNIQUE INDEX(b(1), mb(2), lb(3), id))`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`b` is blob",- Line: 1,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`mb` is mediumblob",- Line: 1,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`lb` is longblob",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(b BLOB, mb MEDIUMBLOB, lb LONGBLOB, id iNT, INDEX(b(1), mb(2), lb(3), id))`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`b` is blob",- Line: 1,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`mb` is mediumblob",- Line: 1,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`lb` is longblob",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(id INT, PRIMARY KEY(id))`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- // ALTER TABLE ADD COLUMN ADD CONSTRAINT- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD COLUMN b BLOB, ADD COLUMN id INT, ADD PRIMARY KEY(b(1), id)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`b` is blob",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD COLUMN b BLOB, ADD COLUMN mb MEDIUMBLOB, ADD COLUMN lb LONGBLOB, ADD COLUMN id INT, ADD UNIQUE INDEX(b(1), mb(2), lb(3), id)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`b` is blob",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`mb` is mediumblob",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`lb` is longblob",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD COLUMN b BLOB, ADD COLUMN mb MEDIUMBLOB, ADD COLUMN lb LONGBLOB, ADD COLUMN id INT, ADD INDEX(b(1), mb(2), lb(3), id)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`b` is blob",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`mb` is mediumblob",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`lb` is longblob",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD COLUMN b BLOB, ADD COLUMN mb MEDIUMBLOB, ADD COLUMN lb LONGBLOB, ADD COLUMN id INT, ADD INDEX(id)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- // CREATE INDEX STATEMENT- {- Statement: `CREATE TABLE t(b blob, mb mediumblob, lb longblob, id int);- CREATE INDEX idx_b ON t(b(5));- CREATE INDEX idx_mb ON t(mb(5));- CREATE INDEX idx_lb ON t(lb(5));- CREATE INDEX idx_id ON t(id);- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`b` is blob",- Line: 2,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`mb` is mediumblob",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.IndexTypeNoBlob,- Title: "index.type-no-blob",- Content: "Columns in index must not be BLOB but `t`.`lb` is longblob",- Line: 4,- },- },- },- {- Statement: `CREATE TABLE t(b blob, mb mediumblob, lb longblob, id int);- CREATE INDEX idx_id ON t(id);- `,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &IndexTypeNoBlobAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleIndexTypeNoBlob,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand_test.go b/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand_test.godeleted file mode 100644index 1addd0a47a..0000000000--- a/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand_test.go+++ /dev/null@@ -1,43 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestInsertDisallowOrderByRand(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `INSERT INTO tech_book VALUES(1, "a")`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `INSERT INTO tech_book SELECT * FROM tech_book ORDER BY rand()`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.InsertUseOrderByRand,- Title: "statement.insert.disallow-order-by-rand",- Content: "\"INSERT INTO tech_book SELECT * FROM tech_book ORDER BY rand()\" uses ORDER BY RAND in the INSERT statement",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &InsertDisallowOrderByRandAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementInsertDisallowOrderByRand,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_insert_must_specify_column_test.go b/plugin/advisor/mysql/advisor_insert_must_specify_column_test.godeleted file mode 100644index 8d08944f52..0000000000--- a/plugin/advisor/mysql/advisor_insert_must_specify_column_test.go+++ /dev/null@@ -1,43 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestInsertMustSpecifyColumn(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `INSERT INTO tech_book(id, name) VALUES (1, '1')`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `INSERT INTO tech_book VALUES (1, '1')`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.InsertNotSpecifyColumn,- Title: "statement.insert.must-specify-column",- Content: "The INSERT statement must specify columns but \"INSERT INTO tech_book VALUES (1, '1')\" does not",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &InsertMustSpecifyColumnAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementInsertMustSpecifyColumn,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_insert_row_limit_test.go b/plugin/advisor/mysql/advisor_insert_row_limit_test.godeleted file mode 100644index bc67b0d384..0000000000--- a/plugin/advisor/mysql/advisor_insert_row_limit_test.go+++ /dev/null@@ -1,60 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestInsertRowLimit(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `INSERT INTO tech_book values(1, 'a')`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `INSERT INTO tech_book values(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f')`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.InsertTooManyRows,- Title: "statement.insert.row-limit",- Content: "\"INSERT INTO tech_book values(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f')\" inserts 6 rows. The count exceeds 5.",- Line: 1,- },- },- },- {- Statement: `INSERT INTO tech_book SELECT * FROM tech_book`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }- payload, err := json.Marshal(advisor.NumberTypeRulePayload{- Number: 5,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &InsertRowLimitAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementInsertRowLimit,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_migration_compatibility_test.go b/plugin/advisor/mysql/advisor_migration_compatibility_test.godeleted file mode 100644index 74359ca1bd..0000000000--- a/plugin/advisor/mysql/advisor_migration_compatibility_test.go+++ /dev/null@@ -1,383 +0,0 @@-package mysql--import (- "testing"-- _ "github.com/pingcap/tidb/types/parser_driver"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestBasic(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "DROP DATABASE test",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityDropDatabase,- Title: "schema.backward-compatibility",- Content: "\"DROP DATABASE test\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "DROP TABLE tech_book",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityDropTable,- Title: "schema.backward-compatibility",- Content: "\"DROP TABLE tech_book\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "RENAME TABLE tech_book to t2",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityRenameTable,- Title: "schema.backward-compatibility",- Content: "\"RENAME TABLE tech_book to t2\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "DROP VIEW v1",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityDropTable,- Title: "schema.backward-compatibility",- Content: "\"DROP VIEW v1\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "CREATE UNIQUE INDEX idx1 ON tech_book (id)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAddUniqueKey,- Title: "schema.backward-compatibility",- Content: "\"CREATE UNIQUE INDEX idx1 ON tech_book (id)\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "CREATE TABLE t1(a int);DROP TABLE t1;DROP TABLE tech_book;",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityDropTable,- Title: "schema.backward-compatibility",- Content: "\"DROP TABLE t1;\" may cause incompatibility with the existing data and code",- Line: 1,- },- {- Status: advisor.Warn,- Code: advisor.CompatibilityDropTable,- Title: "schema.backward-compatibility",- Content: "\"DROP TABLE tech_book;\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- CREATE UNIQUE INDEX uk_t_a on t(a);- `,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE t ADD PRIMARY KEY (a);- `,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleSchemaBackwardCompatibility,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}--func TestAlterTable(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "ALTER TABLE tech_book ADD f1 TEXT",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "ALTER TABLE tech_book RENAME COLUMN id to f2",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityRenameColumn,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book RENAME COLUMN id to f2\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book DROP COLUMN id",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityDropColumn,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book DROP COLUMN id\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book DROP PRIMARY KEY;ALTER TABLE tech_book ADD PRIMARY KEY (id)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAddPrimaryKey,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book ADD PRIMARY KEY (id)\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ADD UNIQUE (id)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAddUniqueKey,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book ADD UNIQUE (id)\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ADD UNIQUE KEY (id)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAddUniqueKey,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book ADD UNIQUE KEY (id)\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ADD UNIQUE INDEX (id)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAddUniqueKey,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book ADD UNIQUE INDEX (id)\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ADD FOREIGN KEY (id) REFERENCES t2(f2)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAddForeignKey,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book ADD FOREIGN KEY (id) REFERENCES t2(f2)\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ADD CHECK (id > 0)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAddCheck,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book ADD CHECK (id > 0)\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ADD CHECK (id > 0) NOT ENFORCED",- Want: []advisor.Advice{- {- Status: advisor.Success,- Title: "OK",- Content: "",- },- },- },- {- Statement: "ALTER TABLE tech_book ALTER CHECK chk1 ENFORCED",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAlterCheck,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book ALTER CHECK chk1 ENFORCED\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ALTER CHECK chk1 NOT ENFORCED",- Want: []advisor.Advice{- {- Status: advisor.Success,- Title: "OK",- Content: "",- },- },- },- {- Statement: "ALTER TABLE tech_book ADD CONSTRAINT CHECK (id > 0)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAddCheck,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book ADD CONSTRAINT CHECK (id > 0)\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ADD CONSTRAINT CHECK (id > 0) NOT ENFORCED",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "ALTER TABLE tech_book RENAME TO t2",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityRenameTable,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book RENAME TO t2\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleSchemaBackwardCompatibility,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}--func TestAlterTableChangeColumnType(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "ALTER TABLE tech_book CHANGE name f2 TEXT",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAlterColumn,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book CHANGE name f2 TEXT\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book MODIFY name TEXT",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAlterColumn,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book MODIFY name TEXT\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book MODIFY name TEXT NULL",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAlterColumn,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book MODIFY name TEXT NULL\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book MODIFY name TEXT NOT NULL",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAlterColumn,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book MODIFY name TEXT NOT NULL\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book MODIFY name TEXT COMMENT 'bla'",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CompatibilityAlterColumn,- Title: "schema.backward-compatibility",- Content: "\"ALTER TABLE tech_book MODIFY name TEXT COMMENT 'bla'\" may cause incompatibility with the existing data and code",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleSchemaBackwardCompatibility,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_naming_auto_increment_column_test.go b/plugin/advisor/mysql/advisor_naming_auto_increment_column_test.godeleted file mode 100644index 55adfe634c..0000000000--- a/plugin/advisor/mysql/advisor_naming_auto_increment_column_test.go+++ /dev/null@@ -1,87 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestNamingAutoIncrementColumn(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE book(id int AUTO_INCREMENT)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(a int AUTO_INCREMENT)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NamingAutoIncrementColumnConventionMismatch,- Title: "naming.column.auto-increment",- Content: "`book`.`a` mismatches auto_increment column naming convention, naming format should be \"id\"",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book ADD COLUMN a int AUTO_INCREMENT`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NamingAutoIncrementColumnConventionMismatch,- Title: "naming.column.auto-increment",- Content: "`tech_book`.`a` mismatches auto_increment column naming convention, naming format should be \"id\"",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book CHANGE COLUMN id a int AUTO_INCREMENT`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NamingAutoIncrementColumnConventionMismatch,- Title: "naming.column.auto-increment",- Content: "`tech_book`.`a` mismatches auto_increment column naming convention, naming format should be \"id\"",- Line: 1,- },- },- },- {- Statement: `ALTER TABLE tech_book MODIFY COLUMN name int AUTO_INCREMENT`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NamingAutoIncrementColumnConventionMismatch,- Title: "naming.column.auto-increment",- Content: "`tech_book`.`name` mismatches auto_increment column naming convention, naming format should be \"id\"",- Line: 1,- },- },- },- }-- payload, err := json.Marshal(advisor.NamingRulePayload{- Format: "id",- MaxLength: 64,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &NamingAutoIncrementColumnAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleAutoIncrementColumnNaming,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_naming_column_test.go b/plugin/advisor/mysql/advisor_naming_column_test.godeleted file mode 100644index 4cf6bc2953..0000000000--- a/plugin/advisor/mysql/advisor_naming_column_test.go+++ /dev/null@@ -1,186 +0,0 @@-package mysql--import (- "encoding/json"- "fmt"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestNamingColumnConvention(t *testing.T) {- invalidColumnName := advisor.RandomString(65)-- tests := []advisor.TestCase{- {- Statement: "CREATE TABLE book(id int, creatorId int)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NamingColumnConventionMismatch,- Title: "naming.column",- Content: "`book`.`creatorId` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 1,- },- },- },- {- Statement: fmt.Sprintf("CREATE TABLE book(id int, %s int)", invalidColumnName),- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NamingColumnConventionMismatch,- Title: "naming.column",- Content: fmt.Sprintf("`book`.`%s` mismatches column naming convention, its length should be within 64 characters", invalidColumnName),- Line: 1,- },- },- },- {- Statement: "CREATE TABLE book(id int, creator_id int)",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(id int, creator_id int);- ALTER TABLE book RENAME COLUMN creator_id TO creatorId`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NamingColumnConventionMismatch,- Title: "naming.column",- Content: "`book`.`creatorId` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 2,- },- },- },- {- Statement: `ALTER TABLE tech_book RENAME COLUMN id TO creator_id;`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator_id int,- created_ts timestamp,- updater_id int,- updated_ts timestamp);- ALTER TABLE book CHANGE COLUMN creator_id creatorId int;`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NamingColumnConventionMismatch,- Title: "naming.column",- Content: "`book`.`creatorId` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 7,- },- },- },- {- Statement: `ALTER TABLE tech_book CHANGE COLUMN id creator_id int;`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `ALTER TABLE tech_book DROP COLUMN id;`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE book(- id int,- creator_id int,- created_ts timestamp,- updated_ts timestamp);- ALTER TABLE book ADD COLUMN contentString varchar(255);`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NamingColumnConventionMismatch,- Title: "naming.column",- Content: "`book`.`contentString` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 6,- },- },- },- {- Statement: `CREATE TABLE book(- id int,- createdTs timestamp,- updaterId int,- updated_ts timestamp);- CREATE TABLE student(- id int,- createdTs timestamp,- updatedTs timestamp);`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NamingColumnConventionMismatch,- Title: "naming.column",- Content: "`book`.`createdTs` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 3,- },- {- Status: advisor.Warn,- Code: advisor.NamingColumnConventionMismatch,- Title: "naming.column",- Content: "`book`.`updaterId` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 4,- },- {- Status: advisor.Warn,- Code: advisor.NamingColumnConventionMismatch,- Title: "naming.column",- Content: "`student`.`createdTs` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 8,- },- {- Status: advisor.Warn,- Code: advisor.NamingColumnConventionMismatch,- Title: "naming.column",- Content: "`student`.`updatedTs` mismatches column naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 9,- },- },- },- }-- payload, err := json.Marshal(advisor.NamingRulePayload{- Format: "^[a-z]+(_[a-z]+)*$",- MaxLength: 64,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &NamingColumnConventionAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleColumnNaming,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go b/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.godeleted file mode 100644index 6f719913be..0000000000--- a/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go+++ /dev/null@@ -1,105 +0,0 @@-package mysql--import (- "encoding/json"- "fmt"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestNamingFKConvention(t *testing.T) {- invalidFKName := advisor.RandomString(65)-- tests := []advisor.TestCase{- {- Statement: "ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id)",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES author (id)",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingFKConventionMismatch,- 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`",- Line: 1,- },- },- },- {- Statement: fmt.Sprintf("ALTER TABLE tech_book ADD CONSTRAINT %s FOREIGN KEY (author_id) REFERENCES author (id)", invalidFKName),- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingFKConventionMismatch,- Title: "naming.index.fk",- Content: fmt.Sprintf("Foreign key in table `tech_book` mismatches the naming convention, expect \"^$|^fk_tech_book_author_id_author_id$\" but found `%s`", invalidFKName),- Line: 1,- },- {- Status: advisor.Error,- Code: advisor.NamingFKConventionMismatch,- Title: "naming.index.fk",- Content: fmt.Sprintf("Foreign key `%s` in table `tech_book` mismatches the naming convention, its length should be within 64 characters", invalidFKName),- Line: 1,- },- },- },- {- Statement: "CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id_author_id (author_id) REFERENCES author (id))",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE TABLE book(id INT, author_id INT, FOREIGN KEY (author_id) REFERENCES author (id))",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id (author_id) REFERENCES author (id))",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingFKConventionMismatch,- 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: 1,- },- },- },- }-- payload, err := json.Marshal(advisor.NamingRulePayload{- Format: "^$|^fk_{{referencing_table}}_{{referencing_column}}_{{referenced_table}}_{{referenced_column}}$",- MaxLength: 64,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &NamingFKConventionAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleFKNaming,- Level: advisor.SchemaRuleLevelError,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_naming_index_convention_test.go b/plugin/advisor/mysql/advisor_naming_index_convention_test.godeleted file mode 100644index 77534f2413..0000000000--- a/plugin/advisor/mysql/advisor_naming_index_convention_test.go+++ /dev/null@@ -1,147 +0,0 @@-package mysql--import (- "encoding/json"- "fmt"- "strings"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestNamingIndexConvention(t *testing.T) {- invalidIndexName := advisor.RandomString(65)-- tests := []advisor.TestCase{- {- Statement: "CREATE INDEX idx_tech_book_id_name ON tech_book(id, name)",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE INDEX tech_book_id_name ON tech_book(id, name)",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingIndexConventionMismatch,- 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`",- Line: 1,- },- },- },- {- Statement: fmt.Sprintf("CREATE INDEX %s ON tech_book(id, name)", invalidIndexName),- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingIndexConventionMismatch,- Title: "naming.index.idx",- Content: fmt.Sprintf("Index in table `tech_book` mismatches the naming convention, expect \"^$|^idx_tech_book_id_name$\" but found `%s`", invalidIndexName),- Line: 1,- },- {- Status: advisor.Error,- Code: advisor.NamingIndexConventionMismatch,- Title: "naming.index.idx",- Content: fmt.Sprintf("Index `%s` in table `tech_book` mismatches the naming convention, its length should be within 64 characters", invalidIndexName),- Line: 1,- },- },- },- {- Statement: fmt.Sprintf(- "ALTER TABLE tech_book RENAME INDEX %s TO idx_tech_book_%s",- advisor.MockOldIndexName,- strings.Join(advisor.MockIndexColumnList, "_"),- ),- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: fmt.Sprintf(- "ALTER TABLE tech_book RENAME INDEX %s TO idx_tech_book",- advisor.MockOldIndexName,- ),- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingIndexConventionMismatch,- 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`",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ADD INDEX idx_tech_book_id_name (id, name)",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "ALTER TABLE tech_book ADD INDEX tech_book_id_name (id, name)",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingIndexConventionMismatch,- 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`",- Line: 1,- },- },- },- {- Statement: "CREATE TABLE tech_book_copy(id INT PRIMARY KEY, name VARCHAR(20), INDEX idx_tech_book_copy_name (name))",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE TABLE tech_book_copy(id INT PRIMARY KEY, name VARCHAR(20), INDEX (name))",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }-- payload, err := json.Marshal(advisor.NamingRulePayload{- Format: "^$|^idx_{{table}}_{{column_list}}$",- MaxLength: 64,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &NamingIndexConventionAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleIDXNaming,- Level: advisor.SchemaRuleLevelError,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_naming_table_test.go b/plugin/advisor/mysql/advisor_naming_table_test.godeleted file mode 100644index d97f7fe91f..0000000000--- a/plugin/advisor/mysql/advisor_naming_table_test.go+++ /dev/null@@ -1,128 +0,0 @@-package mysql--import (- "encoding/json"- "fmt"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestMySQLNamingTableConvention(t *testing.T) {- invalidTableName := advisor.RandomString(65)-- tests := []advisor.TestCase{- {- Statement: "CREATE TABLE techBook(id int, name varchar(255))",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingTableConventionMismatch,- Title: "naming.table",- Content: "`techBook` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 1,- },- },- },- {- Statement: "CREATE TABLE tech_book_copy(id int, name varchar(255))",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: fmt.Sprintf("CREATE TABLE %s(id int, name varchar(255))", invalidTableName),- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingTableConventionMismatch,- Title: "naming.table",- Content: fmt.Sprintf("`%s` mismatches table naming convention, its length should be within 64 characters", invalidTableName),- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book RENAME TO TechBook",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingTableConventionMismatch,- Title: "naming.table",- Content: "`TechBook` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book RENAME TO tech_book_copy",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "RENAME TABLE tech_book TO tech_book_copy, tech_book_copy TO LiteraryBook",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingTableConventionMismatch,- Title: "naming.table",- Content: "`LiteraryBook` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 1,- },- },- },- {- Statement: "CREATE TABLE literary_book(a int);RENAME TABLE tech_book TO TechBook, literary_book TO LiteraryBook",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingTableConventionMismatch,- Title: "naming.table",- Content: "`TechBook` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 1,- },- {- Status: advisor.Error,- Code: advisor.NamingTableConventionMismatch,- Title: "naming.table",- Content: "`LiteraryBook` mismatches table naming convention, naming format should be \"^[a-z]+(_[a-z]+)*$\"",- Line: 1,- },- },- },- {- Statement: "CREATE TABLE literary_book(a int);RENAME TABLE tech_book TO tech_book_copy, literary_book TO literary_book_copy",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }- payload, err := json.Marshal(advisor.NamingRulePayload{- Format: "^[a-z]+(_[a-z]+)*$",- MaxLength: 64,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &NamingTableConventionAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleTableNaming,- Level: advisor.SchemaRuleLevelError,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go b/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.godeleted file mode 100644index e7549562a9..0000000000--- a/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go+++ /dev/null@@ -1,158 +0,0 @@-package mysql--import (- "encoding/json"- "fmt"- "strings"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestNamingUKConvention(t *testing.T) {- invalidUKName := advisor.RandomString(65)-- tests := []advisor.TestCase{- {- Statement: "CREATE UNIQUE INDEX uk_tech_book_id_name ON tech_book(id, name)",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE UNIQUE INDEX tech_book_id_name ON tech_book(id, name)",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingUKConventionMismatch,- 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`",- Line: 1,- },- },- },- {- Statement: fmt.Sprintf("CREATE UNIQUE INDEX %s ON tech_book(id, name)", invalidUKName),- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingUKConventionMismatch,- Title: "naming.index.uk",- Content: fmt.Sprintf("Unique key in table `tech_book` mismatches the naming convention, expect \"^$|^uk_tech_book_id_name$\" but found `%s`", invalidUKName),- Line: 1,- },- {- Status: advisor.Error,- Code: advisor.NamingUKConventionMismatch,- Title: "naming.index.uk",- Content: fmt.Sprintf("Unique key `%s` in table `tech_book` mismatches the naming convention, its length should be within 64 characters", invalidUKName),- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ADD UNIQUE uk_tech_book_id_name (id, name)",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "ALTER TABLE tech_book ADD UNIQUE tech_book_id_name (id, name)",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingUKConventionMismatch,- 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`",- Line: 1,- },- },- },- {- Statement: fmt.Sprintf(- "ALTER TABLE tech_book RENAME INDEX %s TO uk_tech_book_%s",- advisor.MockOldUKName,- strings.Join(advisor.MockIndexColumnList, "_"),- ),- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: fmt.Sprintf(- "ALTER TABLE tech_book RENAME INDEX %s TO uk_tech_book",- advisor.MockOldUKName,- ),- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NamingUKConventionMismatch,- 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`",- Line: 1,- },- },- },- {- Statement: "CREATE TABLE book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE INDEX uk_book_name (name))",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE TABLE book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE KEY (name))",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE TABLE book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE INDEX (name))",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }-- payload, err := json.Marshal(advisor.NamingRulePayload{- Format: "^$|^uk_{{table}}_{{column_list}}$",- MaxLength: 64,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &NamingUKConventionAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleUKNaming,- Level: advisor.SchemaRuleLevelError,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_statement_affected_row_limit_test.go b/plugin/advisor/mysql/advisor_statement_affected_row_limit_test.godeleted file mode 100644index 90b3bff835..0000000000--- a/plugin/advisor/mysql/advisor_statement_affected_row_limit_test.go+++ /dev/null@@ -1,49 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestStatementAffectedRowLimit(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `DELETE FROM tech_book WHERE a > 1`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `UPDATE tech_book SET id = 1`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }-- payload, err := json.Marshal(advisor.NumberTypeRulePayload{- Number: 5,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &StatementAffectedRowLimitAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementAffectedRowLimit,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_statement_dml_dry_run_test.go b/plugin/advisor/mysql/advisor_statement_dml_dry_run_test.godeleted file mode 100644index a6181d6792..0000000000--- a/plugin/advisor/mysql/advisor_statement_dml_dry_run_test.go+++ /dev/null@@ -1,42 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestStatementDmlDryRun(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `INSERT INTO tech_book values(1, 'a')`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `DELETE FROM tech_book`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &StatementDmlDryRunAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementDMLDryRun,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_statement_merge_alter_table_test.go b/plugin/advisor/mysql/advisor_statement_merge_alter_table_test.godeleted file mode 100644index 1331883097..0000000000--- a/plugin/advisor/mysql/advisor_statement_merge_alter_table_test.go+++ /dev/null@@ -1,94 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestStatementMergeAlterTable(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `ALTER TABLE tech_book ADD COLUMN a int`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `- ALTER TABLE tech_book ADD COLUMN a int;- ALTER TABLE tech_book ADD COLUMN b int;- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementRedundantAlterTable,- Title: "statement.merge-alter-table",- Content: "There are 2 statements to modify table `tech_book`",- Line: 3,- },- },- },- {- Statement: `- CREATE TABLE t(a int);- ALTER TABLE tech_book ADD COLUMN a int;- ALTER TABLE t ADD COLUMN b int;- ALTER TABLE tech_book ADD COLUMN b int;- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementRedundantAlterTable,- Title: "statement.merge-alter-table",- Content: "There are 2 statements to modify table `t`",- Line: 4,- },- {- Status: advisor.Warn,- Code: advisor.StatementRedundantAlterTable,- Title: "statement.merge-alter-table",- Content: "There are 2 statements to modify table `tech_book`",- Line: 5,- },- },- },- {- 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;- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementRedundantAlterTable,- Title: "statement.merge-alter-table",- Content: "There are 2 statements to modify table `tech_book`",- Line: 4,- },- {- Status: advisor.Warn,- Code: advisor.StatementRedundantAlterTable,- Title: "statement.merge-alter-table",- Content: "There are 2 statements to modify table `t`",- Line: 5,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &StatementMergeAlterTableAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementMergeAlterTable,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_stmt_disallow_commit_test.go b/plugin/advisor/mysql/advisor_stmt_disallow_commit_test.godeleted file mode 100644index c618070264..0000000000--- a/plugin/advisor/mysql/advisor_stmt_disallow_commit_test.go+++ /dev/null@@ -1,63 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestStatementDisallowCommit(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `- START TRANSACTION;- CREATE TABLE techBook(id int, name varchar(255));- COMMIT;- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementDisallowCommit,- Title: "statement.disallow-commit",- Content: "Commit is not allowed, related statement: \"COMMIT;\"",- Line: 4,- },- },- },- {- Statement: `- START TRANSACTION;- CREATE TABLE techBook(id int, name varchar(255));- COMMIT;-- START TRANSACTION;- INSERT INTO techBook(id, name) VALUES(1, "book");- COMMIT;- `,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementDisallowCommit,- Title: "statement.disallow-commit",- Content: "Commit is not allowed, related statement: \"COMMIT;\"",- Line: 4,- },- {- Status: advisor.Warn,- Code: advisor.StatementDisallowCommit,- Title: "statement.disallow-commit",- Content: "Commit is not allowed, related statement: \"COMMIT;\"",- Line: 8,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &StatementDisallowCommitAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementDisallowCommit,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_stmt_disallow_limit_test.go b/plugin/advisor/mysql/advisor_stmt_disallow_limit_test.godeleted file mode 100644index 956b6d06f9..0000000000--- a/plugin/advisor/mysql/advisor_stmt_disallow_limit_test.go+++ /dev/null@@ -1,79 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestDisallowLimit(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: ``,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `INSERT INTO tech_book SELECT * FROM tech_book LIMIT 1`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.InsertUseLimit,- Title: "statement.disallow-limit",- Content: "LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but \"INSERT INTO tech_book SELECT * FROM tech_book LIMIT 1\" uses",- Line: 1,- },- },- },- {- Statement: `INSERT INTO tech_book SELECT * FROM tech_book UNION SELECT * FROM tech_book LIMIT 1`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.InsertUseLimit,- Title: "statement.disallow-limit",- Content: "LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but \"INSERT INTO tech_book SELECT * FROM tech_book UNION SELECT * FROM tech_book LIMIT 1\" uses",- Line: 1,- },- },- },- {- Statement: `UPDATE tech_book SET name = 'my name' LIMIT 10`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.UpdateUseLimit,- Title: "statement.disallow-limit",- Content: "LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but \"UPDATE tech_book SET name = 'my name' LIMIT 10\" uses",- Line: 1,- },- },- },- {- Statement: `DELETE FROM tech_book LIMIT 10`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DeleteUseLimit,- Title: "statement.disallow-limit",- Content: "LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but \"DELETE FROM tech_book LIMIT 10\" uses",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &DisallowLimitAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementDisallowLimit,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_stmt_disallow_order_by_test.go b/plugin/advisor/mysql/advisor_stmt_disallow_order_by_test.godeleted file mode 100644index 528dcc821f..0000000000--- a/plugin/advisor/mysql/advisor_stmt_disallow_order_by_test.go+++ /dev/null@@ -1,55 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestDisallowOrderBy(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `INSERT INTO tech_book values(1, 'a')`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `UPDATE tech_book SET name = 'my name' ORDER BY id`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.UpdateUseOrderBy,- Title: "statement.disallow-order-by",- Content: "ORDER BY clause is forbidden in DELETE and UPDATE statements, but \"UPDATE tech_book SET name = 'my name' ORDER BY id\" uses",- Line: 1,- },- },- },- {- Statement: `DELETE FROM tech_book ORDER BY id`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.DeleteUseOrderBy,- Title: "statement.disallow-order-by",- Content: "ORDER BY clause is forbidden in DELETE and UPDATE statements, but \"DELETE FROM tech_book ORDER BY id\" uses",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &DisallowOrderByAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementDisallowOrderBy,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}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.godeleted file mode 100644index 5e5ed2c38f..0000000000--- a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go+++ /dev/null@@ -1,77 +0,0 @@-package mysql--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestNoLeadingWildcardLike(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "SELECT * FROM t WHERE a LIKE 'abc%'",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "SELECT * FROM t WHERE a LIKE '%abc'",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.StatementLeadingWildcardLike,- Title: "statement.where.no-leading-wildcard-like",- Content: "\"SELECT * FROM t WHERE a LIKE '%abc'\" uses leading wildcard LIKE",- Line: 1,- },- },- },- {- Statement: "SELECT * FROM t WHERE a LIKE 'abc' OR a LIKE '%abc'",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.StatementLeadingWildcardLike,- Title: "statement.where.no-leading-wildcard-like",- Content: "\"SELECT * FROM t WHERE a LIKE 'abc' OR a LIKE '%abc'\" uses leading wildcard LIKE",- Line: 1,- },- },- },- {- Statement: "SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc'",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.StatementLeadingWildcardLike,- Title: "statement.where.no-leading-wildcard-like",- Content: "\"SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc'\" uses leading wildcard LIKE",- Line: 1,- },- },- },- {- Statement: "SELECT * FROM (SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc') t1",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.StatementLeadingWildcardLike,- 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",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &NoLeadingWildcardLikeAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementNoLeadingWildcardLike,- Level: advisor.SchemaRuleLevelError,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go b/plugin/advisor/mysql/advisor_stmt_no_select_all_test.godeleted file mode 100644index ea0b210ac3..0000000000--- a/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go+++ /dev/null@@ -1,53 +0,0 @@-package mysql--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestNoSelectAll(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "SELECT * FROM t",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.StatementSelectAll,- Title: "statement.select.no-select-all",- Content: "\"SELECT * FROM t\" uses SELECT all",- Line: 1,- },- },- },- {- Statement: "SELECT a, b FROM t",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "SELECT a, b FROM (SELECT * from t1 JOIN t2) t",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.StatementSelectAll,- Title: "statement.select.no-select-all",- Content: "\"SELECT a, b FROM (SELECT * from t1 JOIN t2) t\" uses SELECT all",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &NoSelectAllAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementNoSelectAll,- Level: advisor.SchemaRuleLevelError,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_stmt_where_required_test.go b/plugin/advisor/mysql/advisor_stmt_where_required_test.godeleted file mode 100644index 9d19c72b0c..0000000000--- a/plugin/advisor/mysql/advisor_stmt_where_required_test.go+++ /dev/null@@ -1,110 +0,0 @@-package mysql--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestWhereRequirement(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "INSERT INTO tech_book(id) values (1)",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "DELETE FROM tech_book",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementNoWhere,- Title: "statement.where.require",- Content: "\"DELETE FROM tech_book\" requires WHERE clause",- Line: 1,- },- },- },- {- Statement: "UPDATE tech_book SET id = 1",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementNoWhere,- Title: "statement.where.require",- Content: "\"UPDATE tech_book SET id = 1\" requires WHERE clause",- Line: 1,- },- },- },- {- Statement: "DELETE FROM tech_book WHERE id > 0",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "UPDATE tech_book SET id = 1 WHERE id > 10",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "SELECT id FROM tech_book",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementNoWhere,- Title: "statement.where.require",- Content: "\"SELECT id FROM tech_book\" requires WHERE clause",- Line: 1,- },- },- },- {- Statement: "SELECT id FROM tech_book WHERE id > 0",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "SELECT id FROM tech_book WHERE id > (SELECT max(id) FROM tech_book)",- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.StatementNoWhere,- Title: "statement.where.require",- Content: "\"SELECT id FROM tech_book WHERE id > (SELECT max(id) FROM tech_book)\" requires WHERE clause",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &WhereRequirementAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleStatementRequireWhere,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_table_comment_convention_test.go b/plugin/advisor/mysql/advisor_table_comment_convention_test.godeleted file mode 100644index 6943becc7d..0000000000--- a/plugin/advisor/mysql/advisor_table_comment_convention_test.go+++ /dev/null@@ -1,63 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestTableCommentConvention(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a int) COMMENT 'some comments'`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a int)`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.NoTableComment,- Title: "table.comment",- Content: "Table `t` requires comments",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(a int) COMMENT 'sdlfkjalkseblkjduafelbnlsdfkljayue'`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.TableCommentTooLong,- Title: "table.comment",- Content: "The length of table `t` comment should be within 20 characters",- Line: 1,- },- },- },- }-- payload, err := json.Marshal(advisor.CommentConventionRulePayload{- Required: true,- MaxLength: 20,- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &TableCommentConventionAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleTableCommentConvention,- Level: advisor.SchemaRuleLevelWarning,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_table_disallow_partition_test.go b/plugin/advisor/mysql/advisor_table_disallow_partition_test.godeleted file mode 100644index 43a369e2d6..0000000000--- a/plugin/advisor/mysql/advisor_table_disallow_partition_test.go+++ /dev/null@@ -1,61 +0,0 @@-package mysql--// Framework code is generated by the generator.--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestTableDisallowPartition(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: `CREATE TABLE t(a int)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(a int) PARTITION BY RANGE (a) (- PARTITION p0 VALUES LESS THAN (6),- PARTITION p1 VALUES LESS THAN (11)- )`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CreateTablePartition,- Title: "table.disallow-partition",- Content: "Table partition is forbidden, but \"CREATE TABLE t(a int) PARTITION BY RANGE (a) (\n\t\t\t\tPARTITION p0 VALUES LESS THAN (6),\n\t\t\t\tPARTITION p1 VALUES LESS THAN (11)\n\t\t\t)\" creates",- Line: 4,- },- },- },- {- Statement: `ALTER TABLE tech_book PARTITION BY RANGE (a) (- PARTITION p0 VALUES LESS THAN (6),- PARTITION p1 VALUES LESS THAN (11)- )`,- Want: []advisor.Advice{- {- Status: advisor.Warn,- Code: advisor.CreateTablePartition,- Title: "table.disallow-partition",- Content: "Table partition is forbidden, but \"ALTER TABLE tech_book PARTITION BY RANGE (a) (\n\t\t\t\tPARTITION p0 VALUES LESS THAN (6),\n\t\t\t\tPARTITION p1 VALUES LESS THAN (11)\n\t\t\t)\" creates",- Line: 4,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &TableDisallowPartitionAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleTableDisallowPartition,- Level: advisor.SchemaRuleLevelWarning,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_table_drop_naming_convention_test.go b/plugin/advisor/mysql/advisor_table_drop_naming_convention_test.godeleted file mode 100644index ff0ed7f676..0000000000--- a/plugin/advisor/mysql/advisor_table_drop_naming_convention_test.go+++ /dev/null@@ -1,60 +0,0 @@-package mysql--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestMySQLTableDropNamingConvention(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "DROP TABLE IF EXISTS foo_delete",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "DROP TABLE IF EXISTS foo",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.TableDropNamingConventionMismatch,- Title: "table.drop-naming-convention",- Content: "`foo` mismatches drop table naming convention, naming format should be \"_delete$\"",- Line: 1,- },- },- },- {- Statement: "DROP TABLE IF EXISTS foo_delete, bar",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.TableDropNamingConventionMismatch,- Title: "table.drop-naming-convention",- Content: "`bar` mismatches drop table naming convention, naming format should be \"_delete$\"",- Line: 1,- },- },- },- }-- payload, err := json.Marshal(advisor.NamingRulePayload{- Format: "_delete$",- })- require.NoError(t, err)- advisor.RunSQLReviewRuleTests(t, tests, &TableDropNamingConventionAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleTableDropNamingConvention,- Level: advisor.SchemaRuleLevelError,- Payload: string(payload),- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_table_no_fk_test.go b/plugin/advisor/mysql/advisor_table_no_fk_test.godeleted file mode 100644index c0e678c9bb..0000000000--- a/plugin/advisor/mysql/advisor_table_no_fk_test.go+++ /dev/null@@ -1,42 +0,0 @@-package mysql--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestTableNoFK(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id)",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.TableHasFK,- Title: "table.no-foreign-key",- Content: "Foreign key is not allowed in the table `tech_book`",- Line: 1,- },- },- },- {- Statement: "CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id_author_id (author_id) REFERENCES author (id))",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.TableHasFK,- Title: "table.no-foreign-key",- Content: "Foreign key is not allowed in the table `book`",- Line: 1,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &TableNoFKAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleTableNoFK,- Level: advisor.SchemaRuleLevelError,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_table_require_pk_test.go b/plugin/advisor/mysql/advisor_table_require_pk_test.godeleted file mode 100644index af135c874a..0000000000--- a/plugin/advisor/mysql/advisor_table_require_pk_test.go+++ /dev/null@@ -1,226 +0,0 @@-package mysql--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestRequirePK(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "CREATE TABLE t(id INT PRIMARY KEY)",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE TABLE t(id INT, PRIMARY KEY (id))",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE TABLE t(id INT)",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.TableNoPK,- Title: "table.require-pk",- Content: "Table `t` requires PRIMARY KEY",- Line: 1,- },- },- },- {- Statement: `CREATE TABLE t(id INT);- DROP TABLE t`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(id INT);- ALTER TABLE t ADD CONSTRAINT PRIMARY KEY (id)`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(id INT PRIMARY KEY);- ALTER TABLE t DROP PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.TableNoPK,- Title: "table.require-pk",- Content: "Table `t` requires PRIMARY KEY",- Line: 2,- },- },- },- {- Statement: "CREATE TABLE t(id INT PRIMARY KEY);\n" +- "ALTER TABLE t DROP INDEX `PRIMARY`",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.TableNoPK,- Title: "table.require-pk",- Content: "Table `t` requires PRIMARY KEY",- Line: 2,- },- },- },- {- Statement: `CREATE TABLE t(id INT);- ALTER TABLE t ADD COLUMN name varchar(30) PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(id INT);- ALTER TABLE t CHANGE COLUMN id id INT PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- // Use MockCatalogService- Statement: `ALTER TABLE tech_book CHANGE COLUMN id uid INT`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(id INT);- ALTER TABLE t MODIFY COLUMN id INT PRIMARY KEY`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- // Use MockCatalogService- Statement: `ALTER TABLE tech_book MODIFY COLUMN id INT`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(id INT, name varchar(30), PRIMARY KEY(id, name));- ALTER TABLE t DROP COLUMN id`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: `CREATE TABLE t(id INT, name varchar(30), comment varchar(255), PRIMARY KEY(id, name));- ALTER TABLE t DROP COLUMN id, DROP COLUMN name`,- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.TableNoPK,- Title: "table.require-pk",- Content: "Table `t` requires PRIMARY KEY",- Line: 2,- },- },- },- {- // Use MockCatalogService- Statement: `ALTER TABLE tech_book ADD COLUMN a int, DROP COLUMN id, DROP COLUMN name`,- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.TableNoPK,- Title: "table.require-pk",- Content: "Table `tech_book` requires PRIMARY KEY",- Line: 1,- },- },- },- {- // Use MockCatalogService- Statement: `ALTER TABLE tech_book DROP COLUMN name`,- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- // Use MockCatalogService- Statement: `ALTER TABLE tech_book CHANGE COLUMN id uid int;- ALTER TABLE tech_book ADD COLUMN a int, DROP COLUMN uid, DROP COLUMN name`,- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.TableNoPK,- Title: "table.require-pk",- Content: "Table `tech_book` requires PRIMARY KEY",- Line: 2,- },- },- },- }-- advisor.RunSQLReviewRuleTests(t, tests, &TableRequirePKAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleTableRequirePK,- Level: advisor.SchemaRuleLevelError,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/advisor_use_innodb_test.go b/plugin/advisor/mysql/advisor_use_innodb_test.godeleted file mode 100644index 370844b117..0000000000--- a/plugin/advisor/mysql/advisor_use_innodb_test.go+++ /dev/null@@ -1,97 +0,0 @@-package mysql--import (- "testing"-- "github.com/bytebase/bytebase/plugin/advisor"-)--func TestUseInnoDB(t *testing.T) {- tests := []advisor.TestCase{- {- Statement: "CREATE TABLE book(id int) ENGINE = INNODB",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE TABLE book(id int)",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "CREATE TABLE book(id int) ENGINE = CSV",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NotInnoDBEngine,- Title: "engine.mysql.use-innodb",- Content: "\"CREATE TABLE book(id int) ENGINE = CSV\" doesn't use InnoDB engine",- Line: 1,- },- },- },- {- Statement: "ALTER TABLE tech_book ENGINE = INNODB",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "ALTER TABLE tech_book ENGINE = CSV",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NotInnoDBEngine,- Title: "engine.mysql.use-innodb",- Content: "\"ALTER TABLE tech_book ENGINE = CSV\" doesn't use InnoDB engine",- Line: 1,- },- },- },- {- Statement: "SET default_storage_engine=INNODB",- Want: []advisor.Advice{- {- Status: advisor.Success,- Code: advisor.Ok,- Title: "OK",- Content: "",- },- },- },- {- Statement: "SET default_storage_engine=CSV",- Want: []advisor.Advice{- {- Status: advisor.Error,- Code: advisor.NotInnoDBEngine,- Title: "engine.mysql.use-innodb",- Content: "\"SET default_storage_engine=CSV\" doesn't use InnoDB engine",- Line: 1,- },- },- },- }- advisor.RunSQLReviewRuleTests(t, tests, &UseInnoDBAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleMySQLEngine,- Level: advisor.SchemaRuleLevelError,- Payload: "",- }, advisor.MockMySQLDatabase)-}diff --git a/plugin/advisor/mysql/mysql_rules_test.go b/plugin/advisor/mysql/mysql_rules_test.gonew file mode 100644index 0000000000..7450f8cc1d--- /dev/null+++ b/plugin/advisor/mysql/mysql_rules_test.go@@ -0,0 +1,123 @@+package mysql++import (+ "testing"++ "github.com/bytebase/bytebase/plugin/advisor"+ "github.com/bytebase/bytebase/plugin/advisor/db"++ // Register pingcap parser driver.+ _ "github.com/pingcap/tidb/types/parser_driver"+)++func TestMySQLRules(t *testing.T) {+ mysqlRules := []advisor.SQLReviewRuleType{+ advisor.SchemaRuleMySQLEngine,+ // advisor.SchemaRuleTableNaming enforce the table name format.+ advisor.SchemaRuleTableNaming,+ // advisor.SchemaRuleColumnNaming enforce the column name format.+ advisor.SchemaRuleColumnNaming,+ // advisor.SchemaRuleUKNaming enforce the unique key name format.+ advisor.SchemaRuleUKNaming,+ // advisor.SchemaRuleFKNaming enforce the foreign key name format.+ advisor.SchemaRuleFKNaming,+ // advisor.SchemaRuleIDXNaming enforce the index name format.+ advisor.SchemaRuleIDXNaming,+ // advisor.SchemaRuleAutoIncrementColumnNaming enforce the auto_increment column name format.+ advisor.SchemaRuleAutoIncrementColumnNaming,++ // advisor.SchemaRuleStatementNoSelectAll disallow 'SELECT *'.+ advisor.SchemaRuleStatementNoSelectAll,+ // advisor.SchemaRuleStatementRequireWhere require 'WHERE' clause.+ advisor.SchemaRuleStatementRequireWhere,+ // advisor.SchemaRuleStatementNoLeadingWildcardLike disallow leading '%' in LIKE, e.g. LIKE foo = '%x' is not allowed.+ advisor.SchemaRuleStatementNoLeadingWildcardLike,+ // advisor.SchemaRuleStatementDisallowCommit disallow using commit in the issue.+ advisor.SchemaRuleStatementDisallowCommit,+ // advisor.SchemaRuleStatementDisallowLimit disallow the LIMIT clause in INSERT, DELETE and UPDATE statements.+ advisor.SchemaRuleStatementDisallowLimit,+ // advisor.SchemaRuleStatementDisallowOrderBy disallow the ORDER BY clause in DELETE and UPDATE statements.+ advisor.SchemaRuleStatementDisallowOrderBy,+ // advisor.SchemaRuleStatementMergeAlterTable disallow redundant ALTER TABLE statements.+ advisor.SchemaRuleStatementMergeAlterTable,+ // advisor.SchemaRuleStatementInsertRowLimit enforce the insert row limit.+ advisor.SchemaRuleStatementInsertRowLimit,+ // advisor.SchemaRuleStatementInsertMustSpecifyColumn enforce the insert column specified.+ advisor.SchemaRuleStatementInsertMustSpecifyColumn,+ // advisor.SchemaRuleStatementInsertDisallowOrderByRand disallow the order by rand in the INSERT statement.+ advisor.SchemaRuleStatementInsertDisallowOrderByRand,+ // advisor.SchemaRuleStatementAffectedRowLimit enforce the UPDATE/DELETE affected row limit.+ advisor.SchemaRuleStatementAffectedRowLimit,+ // advisor.SchemaRuleStatementDMLDryRun dry run the dml.+ advisor.SchemaRuleStatementDMLDryRun,++ // advisor.SchemaRuleTableRequirePK require the table to have a primary key.+ advisor.SchemaRuleTableRequirePK,+ // advisor.SchemaRuleTableNoFK require the table disallow the foreign key.+ advisor.SchemaRuleTableNoFK,+ // advisor.SchemaRuleTableDropNamingConvention require only the table following the naming convention can be deleted.+ advisor.SchemaRuleTableDropNamingConvention,+ // advisor.SchemaRuleTableCommentConvention enforce the table comment convention.+ advisor.SchemaRuleTableCommentConvention,+ // advisor.SchemaRuleTableDisallowPartition disallow the table partition.+ advisor.SchemaRuleTableDisallowPartition,++ // advisor.SchemaRuleRequiredColumn enforce the required columns in each table.+ advisor.SchemaRuleRequiredColumn,+ // advisor.SchemaRuleColumnNotNull enforce the columns cannot have NULL value.+ advisor.SchemaRuleColumnNotNull,+ // advisor.SchemaRuleColumnDisallowChangeType disallow change column type.+ advisor.SchemaRuleColumnDisallowChangeType,+ // advisor.SchemaRuleColumnSetDefaultForNotNull require the not null column to set default value.+ advisor.SchemaRuleColumnSetDefaultForNotNull,+ // advisor.SchemaRuleColumnDisallowChange disallow CHANGE COLUMN statement.+ advisor.SchemaRuleColumnDisallowChange,+ // advisor.SchemaRuleColumnDisallowChangingOrder disallow changing column order.+ advisor.SchemaRuleColumnDisallowChangingOrder,+ // advisor.SchemaRuleColumnCommentConvention enforce the column comment convention.+ advisor.SchemaRuleColumnCommentConvention,+ // advisor.SchemaRuleColumnAutoIncrementMustInteger require the auto-increment column to be integer.+ advisor.SchemaRuleColumnAutoIncrementMustInteger,+ // advisor.SchemaRuleColumnTypeDisallowList enforce the column type disallow list.+ advisor.SchemaRuleColumnTypeDisallowList,+ // advisor.SchemaRuleColumnDisallowSetCharset disallow set column charset.+ advisor.SchemaRuleColumnDisallowSetCharset,+ // advisor.SchemaRuleColumnMaximumCharacterLength enforce the maximum character length.+ advisor.SchemaRuleColumnMaximumCharacterLength,+ // advisor.SchemaRuleColumnAutoIncrementInitialValue enforce the initial auto-increment value.+ advisor.SchemaRuleColumnAutoIncrementInitialValue,+ // advisor.SchemaRuleColumnAutoIncrementMustUnsigned enforce the auto-increment column to be unsigned.+ advisor.SchemaRuleColumnAutoIncrementMustUnsigned,+ // advisor.SchemaRuleCurrentTimeColumnCountLimit enforce the current column count limit.+ advisor.SchemaRuleCurrentTimeColumnCountLimit,+ // advisor.SchemaRuleColumnRequireDefault enforce the column default.+ advisor.SchemaRuleColumnRequireDefault,++ // advisor.SchemaRuleSchemaBackwardCompatibility enforce the MySQL and TiDB support check whether the schema change is backward compatible.+ advisor.SchemaRuleSchemaBackwardCompatibility,++ // advisor.SchemaRuleDropEmptyDatabase enforce the MySQL and TiDB support check if the database is empty before users drop it.+ advisor.SchemaRuleDropEmptyDatabase,++ // advisor.SchemaRuleIndexNoDuplicateColumn require the index no duplicate column.+ advisor.SchemaRuleIndexNoDuplicateColumn,+ // advisor.SchemaRuleIndexKeyNumberLimit enforce the index key number limit.+ advisor.SchemaRuleIndexKeyNumberLimit,+ // advisor.SchemaRuleIndexPKTypeLimit enforce the type restriction of columns in primary key.+ advisor.SchemaRuleIndexPKTypeLimit,+ // advisor.SchemaRuleIndexTypeNoBlob enforce the type restriction of columns in index.+ advisor.SchemaRuleIndexTypeNoBlob,+ // advisor.SchemaRuleIndexTotalNumberLimit enforce the index total number limit.+ advisor.SchemaRuleIndexTotalNumberLimit,++ // advisor.SchemaRuleCharsetAllowlist enforce the charset allowlist.+ advisor.SchemaRuleCharsetAllowlist,++ // advisor.SchemaRuleCollationAllowlist enforce the collation allowlist.+ advisor.SchemaRuleCollationAllowlist,+ }++ for _, rule := range mysqlRules {+ advisor.RunSQLReviewRuleTest(t, rule, db.MySQL, false /* record */)+ }+}diff --git a/plugin/advisor/mysql/test/column_auto_increment_initial_value.yaml b/plugin/advisor/mysql/test/column_auto_increment_initial_value.yamlnew file mode 100644index 0000000000..d2a3a3798f--- /dev/null+++ b/plugin/advisor/mysql/test/column_auto_increment_initial_value.yaml@@ -0,0 +1,21 @@+- statement: CREATE TABLE t(a int)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(a int auto_increment) auto_increment = 20+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(a int auto_increment) auto_increment = 2+ want:+ - status: WARN+ code: 416+ title: column.auto-increment-initial-value+ content: The initial auto-increment value in table `t` is 2, which doesn't equal 20+ line: 1diff --git a/plugin/advisor/mysql/test/column_auto_increment_must_integer.yaml b/plugin/advisor/mysql/test/column_auto_increment_must_integer.yamlnew file mode 100644index 0000000000..e2068c3783--- /dev/null+++ b/plugin/advisor/mysql/test/column_auto_increment_must_integer.yaml@@ -0,0 +1,41 @@+- statement: CREATE TABLE t(a INT AUTO_INCREMENT)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(a varchar(255) AUTO_INCREMENT)+ want:+ - status: WARN+ code: 410+ title: column.auto-increment-must-integer+ content: Auto-increment column `t`.`a` requires integer type+ line: 1+- statement: |4-+ CREATE TABLE t(b int);+ ALTER TABLE t ADD COLUMN a varchar(255) AUTO_INCREMENT+ want:+ - status: WARN+ code: 410+ title: column.auto-increment-must-integer+ content: Auto-increment column `t`.`a` requires integer type+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t MODIFY COLUMN a varchar(255) AUTO_INCREMENT+ want:+ - status: WARN+ code: 410+ title: column.auto-increment-must-integer+ content: Auto-increment column `t`.`a` requires integer type+ line: 2+- statement: |4-+ CREATE TABLE t(b int);+ ALTER TABLE t CHANGE COLUMN b a varchar(255) AUTO_INCREMENT+ want:+ - status: WARN+ code: 410+ title: column.auto-increment-must-integer+ content: Auto-increment column `t`.`a` requires integer type+ line: 2diff --git a/plugin/advisor/mysql/test/column_auto_increment_must_unsigned.yaml b/plugin/advisor/mysql/test/column_auto_increment_must_unsigned.yamlnew file mode 100644index 0000000000..d6654427dd--- /dev/null+++ b/plugin/advisor/mysql/test/column_auto_increment_must_unsigned.yaml@@ -0,0 +1,41 @@+- statement: CREATE TABLE t(a INT UNSIGNED AUTO_INCREMENT)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(a INT AUTO_INCREMENT)+ want:+ - status: WARN+ code: 417+ title: column.auto-increment-must-unsigned+ content: Auto-increment column `t`.`a` is not UNSIGNED type+ line: 1+- statement: |4-+ CREATE TABLE t(b int);+ ALTER TABLE t ADD COLUMN a INT AUTO_INCREMENT+ want:+ - status: WARN+ code: 417+ title: column.auto-increment-must-unsigned+ content: Auto-increment column `t`.`a` is not UNSIGNED type+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t MODIFY COLUMN a INT AUTO_INCREMENT+ want:+ - status: WARN+ code: 417+ title: column.auto-increment-must-unsigned+ content: Auto-increment column `t`.`a` is not UNSIGNED type+ line: 2+- statement: |4-+ CREATE TABLE t(b int);+ ALTER TABLE t CHANGE COLUMN b a INT AUTO_INCREMENT+ want:+ - status: WARN+ code: 417+ title: column.auto-increment-must-unsigned+ content: Auto-increment column `t`.`a` is not UNSIGNED type+ line: 2diff --git a/plugin/advisor/mysql/test/column_comment.yaml b/plugin/advisor/mysql/test/column_comment.yamlnew file mode 100644index 0000000000..17dee44a0e--- /dev/null+++ b/plugin/advisor/mysql/test/column_comment.yaml@@ -0,0 +1,79 @@+- statement: CREATE TABLE t(a int COMMENT 'comments')+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(+ a int COMMENT 'some comments',+ b int,+ c int)+ want:+ - status: WARN+ code: 409+ title: column.comment+ content: The length of column `t`.`a` comment should be within 10 characters+ line: 2+ - status: WARN+ code: 408+ title: column.comment+ content: Column `t`.`b` requires comments+ line: 3+ - status: WARN+ code: 408+ title: column.comment+ content: Column `t`.`c` requires comments+ line: 4+- statement: |4-+ CREATE TABLE t(a int COMMENT 'comment');+ ALTER TABLE t ADD COLUMN b int+ want:+ - status: WARN+ code: 408+ title: column.comment+ content: Column `t`.`b` requires comments+ line: 2+- statement: |4-+ CREATE TABLE t(a int COMMENT 'this is comment');+ ALTER TABLE t CHANGE COLUMN a b int+ want:+ - status: WARN+ code: 409+ title: column.comment+ content: The length of column `t`.`a` comment should be within 10 characters+ line: 1+ - status: WARN+ code: 408+ title: column.comment+ content: Column `t`.`b` requires comments+ line: 2+- statement: |4-+ CREATE TABLE t(b int COMMENT 'It is comment');+ ALTER TABLE t MODIFY COLUMN b int+ want:+ - status: WARN+ code: 409+ title: column.comment+ content: The length of column `t`.`b` comment should be within 10 characters+ line: 1+ - status: WARN+ code: 408+ title: column.comment+ content: Column `t`.`b` requires comments+ line: 2+- statement: |4-+ CREATE TABLE t(b int COMMENT 'It is COMMENT');+ ALTER TABLE t MODIFY COLUMN b int COMMENT 'abcdefghiakljhakljdsfalugelkhnabsdguelkadf'+ want:+ - status: WARN+ code: 409+ title: column.comment+ content: The length of column `t`.`b` comment should be within 10 characters+ line: 1+ - status: WARN+ code: 409+ title: column.comment+ content: The length of column `t`.`b` comment should be within 10 characters+ line: 2diff --git a/plugin/advisor/mysql/test/column_current_time_count_limit.yaml b/plugin/advisor/mysql/test/column_current_time_count_limit.yamlnew file mode 100644index 0000000000..56f9481f1e--- /dev/null+++ b/plugin/advisor/mysql/test/column_current_time_count_limit.yaml@@ -0,0 +1,39 @@+- statement: CREATE TABLE t(a timestamp, b timestamp)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE t(+ a timestamp default now(),+ b timestamp default current_timestamp(),+ c timestamp default localtime+ )+ want:+ - status: WARN+ code: 418+ title: column.current-time-count-limit+ content: Table `t` has 3 DEFAULT CURRENT_TIMESTAMP() columns. The count greater than 2.+ line: 5+- statement: |4-+ CREATE TABLE t(+ a timestamp default now() on update localtime,+ b timestamp default current_timestamp() on update localtimestamp()+ )+ want:+ - status: WARN+ code: 419+ title: column.current-time-count-limit+ content: Table `t` has 2 ON UPDATE CURRENT_TIMESTAMP() columns. The count greater than 1.+ line: 4+- statement: |4-+ ALTER TABLE tech_book ADD COLUMN a timestamp default now() on update localtime;+ ALTER TABLE tech_book ADD COLUMN b timestamp default current_timestamp() on update localtimestamp();+ want:+ - status: WARN+ code: 419+ title: column.current-time-count-limit+ content: Table `tech_book` has 2 ON UPDATE CURRENT_TIMESTAMP() columns. The count greater than 1.+ line: 2diff --git a/plugin/advisor/mysql/test/column_disallow_change.yaml b/plugin/advisor/mysql/test/column_disallow_change.yamlnew file mode 100644index 0000000000..ad6d770554--- /dev/null+++ b/plugin/advisor/mysql/test/column_disallow_change.yaml@@ -0,0 +1,18 @@+- statement: |4-+ CREATE TABLE t(b int);+ ALTER TABLE t ADD COLUMN a int+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE t(b int);+ ALTER TABLE t CHANGE COLUMN b a int+ want:+ - status: WARN+ code: 406+ title: column.disallow-change+ content: '"ALTER TABLE t CHANGE COLUMN b a int" contains CHANGE COLUMN statement'+ line: 2diff --git a/plugin/advisor/mysql/test/column_disallow_change_type.yaml b/plugin/advisor/mysql/test/column_disallow_change_type.yamlnew file mode 100644index 0000000000..f8f8b61239--- /dev/null+++ b/plugin/advisor/mysql/test/column_disallow_change_type.yaml@@ -0,0 +1,28 @@+- statement: ALTER TABLE tech_book MODIFY id INTEGER UNSIGNED+ want:+ - status: WARN+ code: 403+ title: column.disallow-change-type+ content: '"ALTER TABLE tech_book MODIFY id INTEGER UNSIGNED" changes column type'+ line: 1+- statement: ALTER TABLE tech_book MODIFY id int+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: ALTER TABLE tech_book MODIFY id bigint+ want:+ - status: WARN+ code: 403+ title: column.disallow-change-type+ content: '"ALTER TABLE tech_book MODIFY id bigint" changes column type'+ line: 1+- statement: ALTER TABLE tech_book CHANGE name uname varchar(20)+ want:+ - status: WARN+ code: 403+ title: column.disallow-change-type+ content: '"ALTER TABLE tech_book CHANGE name uname varchar(20)" changes column type'+ line: 1diff --git a/plugin/advisor/mysql/test/column_disallow_changing_order.yaml b/plugin/advisor/mysql/test/column_disallow_changing_order.yamlnew file mode 100644index 0000000000..d7cfe4801d--- /dev/null+++ b/plugin/advisor/mysql/test/column_disallow_changing_order.yaml@@ -0,0 +1,45 @@+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t MODIFY COLUMN a int+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t MODIFY COLUMN a int FIRST+ want:+ - status: WARN+ code: 407+ title: column.disallow-changing-order+ content: '"ALTER TABLE t MODIFY COLUMN a int FIRST" changes column order'+ line: 2+- statement: |4-+ CREATE TABLE t(b int, a1 int);+ ALTER TABLE t CHANGE COLUMN a1 a int FIRST+ want:+ - status: WARN+ code: 407+ title: column.disallow-changing-order+ content: '"ALTER TABLE t CHANGE COLUMN a1 a int FIRST" changes column order'+ line: 2+- statement: |4-+ CREATE TABLE t(a int, b int);+ ALTER TABLE t MODIFY COLUMN a int AFTER b+ want:+ - status: WARN+ code: 407+ title: column.disallow-changing-order+ content: '"ALTER TABLE t MODIFY COLUMN a int AFTER b" changes column order'+ line: 2+- statement: |4-+ CREATE TABLE t(a1 int, b int);+ ALTER TABLE t CHANGE COLUMN a1 a int AFTER b+ want:+ - status: WARN+ code: 407+ title: column.disallow-changing-order+ content: '"ALTER TABLE t CHANGE COLUMN a1 a int AFTER b" changes column order'+ line: 2diff --git a/plugin/advisor/mysql/test/column_disallow_set_charset.yaml b/plugin/advisor/mysql/test/column_disallow_set_charset.yamlnew file mode 100644index 0000000000..a09814a422--- /dev/null+++ b/plugin/advisor/mysql/test/column_disallow_set_charset.yaml@@ -0,0 +1,35 @@+- statement: CREATE TABLE t(a varchar(20))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(a varchar(20) CHARSET ascii)+ want:+ - status: WARN+ code: 414+ title: column.disallow-set-charset+ content: Disallow set column charset but "CREATE TABLE t(a varchar(20) CHARSET ascii)" does+ line: 1+- statement: ALTER TABLE tech_book ADD COLUMN a varchar(20) CHARSET ascii+ want:+ - status: WARN+ code: 414+ title: column.disallow-set-charset+ content: Disallow set column charset but "ALTER TABLE tech_book ADD COLUMN a varchar(20) CHARSET ascii" does+ line: 1+- statement: ALTER TABLE tech_book MODIFY COLUMN id varchar(20) CHARSET ascii+ want:+ - status: WARN+ code: 414+ title: column.disallow-set-charset+ content: Disallow set column charset but "ALTER TABLE tech_book MODIFY COLUMN id varchar(20) CHARSET ascii" does+ line: 1+- statement: ALTER TABLE tech_book CHANGE COLUMN name name varchar(20) CHARSET ascii+ want:+ - status: WARN+ code: 414+ title: column.disallow-set-charset+ content: Disallow set column charset but "ALTER TABLE tech_book CHANGE COLUMN name name varchar(20) CHARSET ascii" does+ line: 1diff --git a/plugin/advisor/mysql/test/column_maximum_character_length.yaml b/plugin/advisor/mysql/test/column_maximum_character_length.yamlnew file mode 100644index 0000000000..ba36c9f8f4--- /dev/null+++ b/plugin/advisor/mysql/test/column_maximum_character_length.yaml@@ -0,0 +1,42 @@+- statement: CREATE TABLE t(name char(20));+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(name varchar(225));+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(name char(225));+ want:+ - status: WARN+ code: 415+ title: column.maximum-character-length+ content: The length of the CHAR column `name` is bigger than 20, please use VARCHAR instead+ line: 1+- statement: ALTER TABLE tech_book ADD COLUMN name_2 char(225)+ want:+ - status: WARN+ code: 415+ title: column.maximum-character-length+ content: The length of the CHAR column `name_2` is bigger than 20, please use VARCHAR instead+ line: 1+- statement: ALTER TABLE tech_book CHANGE COLUMN name name char(225)+ want:+ - status: WARN+ code: 415+ title: column.maximum-character-length+ content: The length of the CHAR column `name` is bigger than 20, please use VARCHAR instead+ line: 1+- statement: ALTER TABLE tech_book MODIFY COLUMN name char(225)+ want:+ - status: WARN+ code: 415+ title: column.maximum-character-length+ content: The length of the CHAR column `name` is bigger than 20, please use VARCHAR instead+ line: 1diff --git a/plugin/advisor/mysql/test/column_no_null.yaml b/plugin/advisor/mysql/test/column_no_null.yamlnew file mode 100644index 0000000000..0848ac06f1--- /dev/null+++ b/plugin/advisor/mysql/test/column_no_null.yaml@@ -0,0 +1,72 @@+- statement: |-+ CREATE TABLE book(+ id int,+ name varchar(255))+ want:+ - status: WARN+ code: 402+ title: column.no-null+ content: '`book`.`id` cannot have NULL value'+ line: 2+ - status: WARN+ code: 402+ title: column.no-null+ content: '`book`.`name` cannot have NULL value'+ line: 3+- statement: CREATE TABLE book(id int PRIMARY KEY, name varchar(255))+ want:+ - status: WARN+ code: 402+ title: column.no-null+ content: '`book`.`name` cannot have NULL value'+ line: 1+- statement: CREATE TABLE book(id int NOT NULL, name varchar(255))+ want:+ - status: WARN+ code: 402+ title: column.no-null+ content: '`book`.`name` cannot have NULL value'+ line: 1+- statement: CREATE TABLE book(id int PRIMARY KEY, name varchar(255) NOT NULL)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE book(a int NOT NULL);+ ALTER TABLE book ADD COLUMN (id int, name varchar(255) NOT NULL);+ want:+ - status: WARN+ code: 402+ title: column.no-null+ content: '`book`.`id` cannot have NULL value'+ line: 2+- statement: |4-+ CREATE TABLE book(a int NOT NULL);+ ALTER TABLE book ADD COLUMN (id int PRIMARY KEY, name varchar(255) NOT NULL);+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE book(id int NOT NULL);+ ALTER TABLE book CHANGE COLUMN id name varchar(255);+ want:+ - status: WARN+ code: 402+ title: column.no-null+ content: '`book`.`name` cannot have NULL value'+ line: 2+- statement: |4-+ CREATE TABLE book(id int NOT NULL);+ ALTER TABLE book CHANGE COLUMN id name varchar(255) NOT NULL;+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/column_require_default.yaml b/plugin/advisor/mysql/test/column_require_default.yamlnew file mode 100644index 0000000000..3d54a477b5--- /dev/null+++ b/plugin/advisor/mysql/test/column_require_default.yaml@@ -0,0 +1,33 @@+- statement: CREATE TABLE t(a int primary key, b int default 1)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE t(+ a int,+ b int default 1+ )+ want:+ - status: WARN+ code: 420+ title: column.require-default+ content: Column `t`.`a` doesn't have DEFAULT.+ line: 2+- statement: |4-+ ALTER TABLE tech_book ADD COLUMN a BLOB;+ ALTER TABLE tech_book ADD COLUMN b timestamp;+ ALTER TABLE tech_book MODIFY COLUMN a varchar(220);+ want:+ - status: WARN+ code: 420+ title: column.require-default+ content: Column `tech_book`.`b` doesn't have DEFAULT.+ line: 2+ - status: WARN+ code: 420+ title: column.require-default+ content: Column `tech_book`.`a` doesn't have DEFAULT.+ line: 3diff --git a/plugin/advisor/mysql/test/column_required.yaml b/plugin/advisor/mysql/test/column_required.yamlnew file mode 100644index 0000000000..b860fb4a44--- /dev/null+++ b/plugin/advisor/mysql/test/column_required.yaml@@ -0,0 +1,167 @@+- statement: CREATE TABLE book(id int)+ want:+ - status: WARN+ code: 401+ title: column.required+ content: 'Table `book` requires columns: created_ts, creator_id, updated_ts, updater_id'+ line: 1+- statement: |-+ CREATE TABLE book(+ id int,+ creator_id int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE book(+ id int,+ creator_id int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp);+ ALTER TABLE book RENAME COLUMN creator_id TO creator;+ want:+ - status: WARN+ code: 401+ title: column.required+ content: 'Table `book` requires columns: creator_id'+ line: 7+- statement: |-+ CREATE TABLE book(+ id int,+ creator int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp);+ ALTER TABLE book RENAME COLUMN creator TO creator_id;+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE book(+ id int,+ creator_id int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp);+ ALTER TABLE book CHANGE COLUMN creator_id creator int;+ want:+ - status: WARN+ code: 401+ title: column.required+ content: 'Table `book` requires columns: creator_id'+ line: 7+- statement: |-+ CREATE TABLE book(+ id int,+ creator int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp);+ ALTER TABLE book CHANGE COLUMN creator creator_id int;+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE book(+ id int,+ creator_id int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp);+ ALTER TABLE book DROP COLUMN creator_id;+ want:+ - status: WARN+ code: 401+ title: column.required+ content: 'Table `book` requires columns: creator_id'+ line: 7+- statement: |-+ CREATE TABLE book(+ id int,+ creator_id int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp,+ content varchar(255));+ ALTER TABLE book DROP COLUMN content;+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE book(+ id int,+ creator_id int,+ created_ts timestamp,+ updated_ts timestamp);+ ALTER TABLE book ADD COLUMN content varchar(255);+ want:+ - status: WARN+ code: 401+ title: column.required+ content: 'Table `book` requires columns: updater_id'+ line: 5+- statement: |-+ CREATE TABLE book(+ id int,+ creator int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp);+ ALTER TABLE book ADD COLUMN creator_id int;+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE book(+ id int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp);+ CREATE TABLE student(+ id int,+ created_ts timestamp,+ updated_ts timestamp)+ want:+ - status: WARN+ code: 401+ title: column.required+ content: 'Table `book` requires columns: creator_id'+ line: 5+ - status: WARN+ code: 401+ title: column.required+ content: 'Table `student` requires columns: creator_id, updater_id'+ line: 9+- statement: |-+ CREATE TABLE book(+ id int,+ creator int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp);+ DROP TABLE book;+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/column_set_default_for_not_null.yaml b/plugin/advisor/mysql/test/column_set_default_for_not_null.yamlnew file mode 100644index 0000000000..ce85bd3051--- /dev/null+++ b/plugin/advisor/mysql/test/column_set_default_for_not_null.yaml@@ -0,0 +1,102 @@+- statement: |-+ CREATE TABLE book(+ id int PRIMARY KEY DEFAULT 0+ )+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE book(+ id int PRIMARY KEY+ )+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE book(+ id int NOT NULL+ )+ want:+ - status: WARN+ code: 404+ title: column.set-default-for-not-null+ content: Column `book`.`id` is NOT NULL but doesn't have DEFAULT+ line: 2+- statement: |-+ CREATE TABLE book(+ id int,+ PRIMARY KEY (id)+ )+ want:+ - status: WARN+ code: 404+ title: column.set-default-for-not-null+ content: Column `book`.`id` is NOT NULL but doesn't have DEFAULT+ line: 2+- statement: |4-+ CREATE TABLE book(a int);+ ALTER TABLE book ADD COLUMN id int PRIMARY KEY+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE book(a int);+ ALTER TABLE book ADD COLUMN id int NOT NULL+ want:+ - status: WARN+ code: 404+ title: column.set-default-for-not-null+ content: Column `book`.`id` is NOT NULL but doesn't have DEFAULT+ line: 2+- statement: |4-+ CREATE TABLE book(id int);+ ALTER TABLE book MODIFY COLUMN id int NOT NULL+ want:+ - status: WARN+ code: 404+ title: column.set-default-for-not-null+ content: Column `book`.`id` is NOT NULL but doesn't have DEFAULT+ line: 2+- statement: |4-+ CREATE TABLE book(id int);+ ALTER TABLE book MODIFY COLUMN id int PRIMARY KEY+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE book(uid int);+ ALTER TABLE book CHANGE COLUMN uid id int PRIMARY KEY+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE book(uid int);+ ALTER TABLE book CHANGE COLUMN uid id int NOT NULL+ want:+ - status: WARN+ code: 404+ title: column.set-default-for-not-null+ content: Column `book`.`id` is NOT NULL but doesn't have DEFAULT+ line: 2+- statement: "\n\t\t\t\tCREATE TABLE book(uid int, id int);\n\t\t\t\tALTER TABLE book \n\t\t\t\t\tCHANGE COLUMN uid uid int NOT NULL DEFAULT 0,\n\t\t\t\t\tMODIFY COLUMN id int PRIMARY KEY DEFAULT 0,\n\t\t\t\t\tADD COLUMN name varchar(20) NOT NULL DEFAULT ''\n\t\t\t\t"+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/column_type_disallow_list.yaml b/plugin/advisor/mysql/test/column_type_disallow_list.yamlnew file mode 100644index 0000000000..620066096b--- /dev/null+++ b/plugin/advisor/mysql/test/column_type_disallow_list.yaml@@ -0,0 +1,32 @@+- statement: CREATE TABLE t(a int)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(a JSON, b BLOB, c TEXT)+ want:+ - status: WARN+ code: 411+ title: column.type-disallow-list+ content: Disallow column type JSON but column `t`.`a` is+ line: 1+- statement: |4-+ CREATE TABLE t(d int);+ ALTER TABLE t add COLUMN (a JSON, b BLOB, c TEXT)+ want:+ - status: WARN+ code: 411+ title: column.type-disallow-list+ content: Disallow column type JSON but column `t`.`a` is+ line: 2+- statement: |4-+ CREATE TABLE t(c int, b int);+ ALTER TABLE t CHANGE COLUMN c a JSON, MODIFY b BLOB+ want:+ - status: WARN+ code: 411+ title: column.type-disallow-list+ content: Disallow column type JSON but column `t`.`a` is+ line: 2diff --git a/plugin/advisor/mysql/test/database_drop_empty_database.yaml b/plugin/advisor/mysql/test/database_drop_empty_database.yamlnew file mode 100644index 0000000000..7baaf278d4--- /dev/null+++ b/plugin/advisor/mysql/test/database_drop_empty_database.yaml@@ -0,0 +1,7 @@+- statement: DROP DATABASE IF EXISTS test+ want:+ - status: WARN+ code: 701+ title: database.drop-empty-database+ content: Database `test` is not allowed to drop if not empty+ line: 1diff --git a/plugin/advisor/mysql/test/engine_mysql_use_innodb.yaml b/plugin/advisor/mysql/test/engine_mysql_use_innodb.yamlnew file mode 100644index 0000000000..93e84e11ef--- /dev/null+++ b/plugin/advisor/mysql/test/engine_mysql_use_innodb.yaml@@ -0,0 +1,49 @@+- statement: CREATE TABLE book(id int) ENGINE = INNODB+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE book(id int)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE book(id int) ENGINE = CSV+ want:+ - status: WARN+ code: 501+ title: engine.mysql.use-innodb+ content: '"CREATE TABLE book(id int) ENGINE = CSV" doesn''t use InnoDB engine'+ line: 1+- statement: ALTER TABLE tech_book ENGINE = INNODB+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: ALTER TABLE tech_book ENGINE = CSV+ want:+ - status: WARN+ code: 501+ title: engine.mysql.use-innodb+ content: '"ALTER TABLE tech_book ENGINE = CSV" doesn''t use InnoDB engine'+ line: 1+- statement: SET default_storage_engine=INNODB+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: SET default_storage_engine=CSV+ want:+ - status: WARN+ code: 501+ title: engine.mysql.use-innodb+ content: '"SET default_storage_engine=CSV" doesn''t use InnoDB engine'+ line: 1diff --git a/plugin/advisor/mysql/test/index_key_number_limit.yaml b/plugin/advisor/mysql/test/index_key_number_limit.yamlnew file mode 100644index 0000000000..64cf0f02d2--- /dev/null+++ b/plugin/advisor/mysql/test/index_key_number_limit.yaml@@ -0,0 +1,45 @@+- statement: CREATE TABLE t(a int, b int, primary key (a, b))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(+ a int,+ b int,+ primary key pk (a, b, b, b, b, b, b))+ want:+ - status: WARN+ code: 802+ title: index.key-number-limit+ content: The number of index `pk` in table `t` should be not greater than 5+ line: 4+- statement: |4-+ CREATE TABLE t(a int, b int, c int, d int, e int, f int, g int);+ CREATE INDEX idx ON t(a, b, c, d, e, f, g)+ want:+ - status: WARN+ code: 802+ title: index.key-number-limit+ content: The number of index `idx` in table `t` should be not greater than 5+ line: 2+- statement: |4-+ CREATE TABLE t(a int, b int, c int, d int, e int, f int, g int);+ ALTER TABLE t ADD UNIQUE KEY uk (a, b, c, d, e, f, g)+ want:+ - status: WARN+ code: 802+ title: index.key-number-limit+ content: The number of index `uk` in table `t` should be not greater than 5+ line: 2+- statement: |4-+ CREATE TABLE t(a int, b int, c int, d int, e int, f int, g int);+ ALTER TABLE t ADD FOREIGN KEY uk (a, b, c, d, e, f, g) REFERENCES t1(a, b, c, d, e, f, g)+ want:+ - status: WARN+ code: 802+ title: index.key-number-limit+ content: The number of index `uk` in table `t` should be not greater than 5+ line: 2diff --git a/plugin/advisor/mysql/test/index_no_duplicate_column.yaml b/plugin/advisor/mysql/test/index_no_duplicate_column.yamlnew file mode 100644index 0000000000..0ce0a3e342--- /dev/null+++ b/plugin/advisor/mysql/test/index_no_duplicate_column.yaml@@ -0,0 +1,62 @@+- statement: CREATE TABLE t (a int, PRIMARY KEY (a))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t (+ a int,+ INDEX idx_a (a, a))+ want:+ - status: WARN+ code: 812+ title: index.no-duplicate-column+ content: INDEX `idx_a` has duplicate column `t`.`a`+ line: 3+- statement: |4-+ CREATE TABLE t(a int);+ CREATE INDEX idx_a on t(a, a)+ want:+ - status: WARN+ code: 812+ title: index.no-duplicate-column+ content: INDEX `idx_a` has duplicate column `t`.`a`+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD INDEX idx_a (a, a)+ want:+ - status: WARN+ code: 812+ title: index.no-duplicate-column+ content: INDEX `idx_a` has duplicate column `t`.`a`+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD PRIMARY KEY pk_a (a, a)+ want:+ - status: WARN+ code: 812+ title: index.no-duplicate-column+ content: PRIMARY KEY `pk_a` has duplicate column `t`.`a`+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD UNIQUE KEY uk_a (a, a)+ want:+ - status: WARN+ code: 812+ title: index.no-duplicate-column+ content: UNIQUE KEY `uk_a` has duplicate column `t`.`a`+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD FOREIGN KEY fk_a (a, a) REFERENCES t1(a, b)+ want:+ - status: WARN+ code: 812+ title: index.no-duplicate-column+ content: FOREIGN KEY `fk_a` has duplicate column `t`.`a`+ line: 2diff --git a/plugin/advisor/mysql/test/index_pk_type_limit.yaml b/plugin/advisor/mysql/test/index_pk_type_limit.yamlnew file mode 100644index 0000000000..92c82d8bcb--- /dev/null+++ b/plugin/advisor/mysql/test/index_pk_type_limit.yaml@@ -0,0 +1,183 @@+- statement: CREATE TABLE t(id VARCHAR(5) PRIMARY KEY)+ want:+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)+ line: 1+- statement: CREATE TABLE t(id INT PRIMARY KEY)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(id VARCHAR(5), PRIMARY KEY(id))+ want:+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)+ line: 1+- statement: CREATE TABLE t(id INT, id2 VARCHAR(5), id3 VARCHAR(5), PRIMARY KEY(id, id2, id3))+ want:+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id2` is varchar(5)+ line: 1+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id3` is varchar(5)+ line: 1+- statement: CREATE TABLE t(id INT, id2 BIGINT, PRIMARY KEY(id, id2))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(id INT, PRIMARY KEY(id))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD COLUMN id VARCHAR(5) PRIMARY KEY+ want:+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD COLUMN id INT PRIMARY KEY+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD COLUMN id VARCHAR(5), ADD PRIMARY KEY (id)+ want:+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD COLUMN id INT, ADD COLUMN id2 VARCHAR(5), ADD COLUMN id3 VARCHAR(5), ADD PRIMARY KEY (id, id2, id3)+ want:+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id2` is varchar(5)+ line: 2+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id3` is varchar(5)+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD COLUMN id INT, ADD COLUMN id2 BIGINT, ADD PRIMARY KEY (id, id2)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD COLUMN id BIGINT, ADD PRIMARY KEY (id)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(id VARCHAR(5));+ ALTER TABLE t ADD PRIMARY KEY(id);+ want:+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)+ line: 2+- statement: |-+ CREATE TABLE t(id INT, id2 VARCHAR(5), id3 VARCHAR(5));+ ALTER TABLE t ADD PRIMARY KEY(id, id2, id3);+ want:+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id2` is varchar(5)+ line: 2+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id3` is varchar(5)+ line: 2+- statement: |-+ CREATE TABLE t(id INT, id2 BIGINT);+ ALTER TABLE t ADD PRIMARY KEY(id, id2);+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(id BIGINT);+ ALTER TABLE t ADD PRIMARY KEY(id);+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE t(id int);+ ALTER TABLE t MODIFY COLUMN id VARCHAR(5) PRIMARY KEY;+ want:+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id` is varchar(5)+ line: 2+- statement: |4-+ CREATE TABLE t(id int);+ ALTER TABLE t MODIFY COLUMN id INT(5) PRIMARY KEY;+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE t(id int);+ ALTER TABLE t CHANGE COLUMN id id2 VARCHAR(5) PRIMARY KEY+ want:+ - status: WARN+ code: 803+ title: index.pk-type-limit+ content: Columns in primary key must be INT/BIGINT but `t`.`id2` is varchar(5)+ line: 2+- statement: |4-+ CREATE TABLE t(id int);+ ALTER TABLE t CHANGE COLUMN id id2 INT(5) PRIMARY KEY+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/index_total_number_limit.yaml b/plugin/advisor/mysql/test/index_total_number_limit.yamlnew file mode 100644index 0000000000..c960a19a0a--- /dev/null+++ b/plugin/advisor/mysql/test/index_total_number_limit.yaml@@ -0,0 +1,55 @@+- statement: CREATE TABLE t(a int, b int, c int, unique key(a, b, c))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE INDEX idx_id_name on tech_book(id, name)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE INDEX idx_id_name_1 on tech_book(id, name);+ CREATE INDEX idx_id_name_2 on tech_book(id, name);+ CREATE INDEX idx_id_name_3 on tech_book(id, name);+ CREATE INDEX idx_id_name_4 on tech_book(id, name);+ CREATE INDEX idx_id_name_5 on tech_book(id, name);+ want:+ - status: WARN+ code: 813+ title: index.total-number-limit+ content: The count of index in table `tech_book` should be no more than 5, but found 8+ line: 5+- statement: |4-+ CREATE TABLE t(a int PRIMARY KEY, b int, c int);+ CREATE INDEX idx_a_b_1 on t(a, b);+ CREATE INDEX idx_a_b_2 on t(a, b);+ CREATE INDEX idx_a_b_3 on t(a, b);+ CREATE INDEX idx_a_b_4 on t(a, b);+ CREATE INDEX idx_a_b_5 on t(a, b);+ want:+ - status: WARN+ code: 813+ title: index.total-number-limit+ content: The count of index in table `t` should be no more than 5, but found 6+ line: 6+- statement: |4-+ CREATE TABLE t(+ a int PRIMARY KEY,+ b int,+ c int,+ INDEX idx_a_b_1 (a, b),+ INDEX idx_a_b_2 (a, b),+ INDEX idx_a_b_3 (a, b),+ INDEX idx_a_b_4 (a, b),+ INDEX idx_a_b_5 (a, b));+ want:+ - status: WARN+ code: 813+ title: index.total-number-limit+ content: The count of index in table `t` should be no more than 5, but found 6+ line: 9diff --git a/plugin/advisor/mysql/test/index_type_no_blob.yaml b/plugin/advisor/mysql/test/index_type_no_blob.yamlnew file mode 100644index 0000000000..682302a183--- /dev/null+++ b/plugin/advisor/mysql/test/index_type_no_blob.yaml@@ -0,0 +1,152 @@+- statement: CREATE TABLE t(b BLOB, PRIMARY KEY(b(10)))+ want:+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`b` is blob+ line: 1+- statement: CREATE TABLE t(b BLOB, mb MEDIUMBLOB, lb LONGBLOB, id INT, PRIMARY KEY(b(1), mb(2), lb(3), id))+ want:+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`b` is blob+ line: 1+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ line: 1+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`lb` is longblob+ line: 1+- statement: CREATE TABLE t(b BLOB, mb MEDIUMBLOB, lb LONGBLOB, id INT, UNIQUE INDEX(b(1), mb(2), lb(3), id))+ want:+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`b` is blob+ line: 1+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ line: 1+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`lb` is longblob+ line: 1+- statement: CREATE TABLE t(b BLOB, mb MEDIUMBLOB, lb LONGBLOB, id iNT, INDEX(b(1), mb(2), lb(3), id))+ want:+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`b` is blob+ line: 1+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ line: 1+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`lb` is longblob+ line: 1+- statement: CREATE TABLE t(id INT, PRIMARY KEY(id))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD COLUMN b BLOB, ADD COLUMN id INT, ADD PRIMARY KEY(b(1), id)+ want:+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`b` is blob+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD COLUMN b BLOB, ADD COLUMN mb MEDIUMBLOB, ADD COLUMN lb LONGBLOB, ADD COLUMN id INT, ADD UNIQUE INDEX(b(1), mb(2), lb(3), id)+ want:+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`b` is blob+ line: 2+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ line: 2+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`lb` is longblob+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD COLUMN b BLOB, ADD COLUMN mb MEDIUMBLOB, ADD COLUMN lb LONGBLOB, ADD COLUMN id INT, ADD INDEX(b(1), mb(2), lb(3), id)+ want:+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`b` is blob+ line: 2+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ line: 2+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`lb` is longblob+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t ADD COLUMN b BLOB, ADD COLUMN mb MEDIUMBLOB, ADD COLUMN lb LONGBLOB, ADD COLUMN id INT, ADD INDEX(id)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(b blob, mb mediumblob, lb longblob, id int);+ CREATE INDEX idx_b ON t(b(5));+ CREATE INDEX idx_mb ON t(mb(5));+ CREATE INDEX idx_lb ON t(lb(5));+ CREATE INDEX idx_id ON t(id);+ want:+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`b` is blob+ line: 2+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ line: 3+ - status: WARN+ code: 804+ title: index.type-no-blob+ content: Columns in index must not be BLOB but `t`.`lb` is longblob+ line: 4+- statement: |-+ CREATE TABLE t(b blob, mb mediumblob, lb longblob, id int);+ CREATE INDEX idx_id ON t(id);+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/naming_column.yaml b/plugin/advisor/mysql/test/naming_column.yamlnew file mode 100644index 0000000000..20f1405c65--- /dev/null+++ b/plugin/advisor/mysql/test/naming_column.yaml@@ -0,0 +1,109 @@+- statement: CREATE TABLE book(id int, creatorId int)+ want:+ - status: WARN+ code: 302+ title: naming.column+ content: '`book`.`creatorId` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 1+- statement: CREATE TABLE book(id int, gbhzmtchhsjzyrhdroxmyouwloxqezowdvhcbqalqcgqhfbjnvmhwrbggezmzeusx int)+ want:+ - status: WARN+ code: 302+ title: naming.column+ content: '`book`.`gbhzmtchhsjzyrhdroxmyouwloxqezowdvhcbqalqcgqhfbjnvmhwrbggezmzeusx` mismatches column naming convention, its length should be within 64 characters'+ line: 1+- statement: CREATE TABLE book(id int, creator_id int)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE book(id int, creator_id int);+ ALTER TABLE book RENAME COLUMN creator_id TO creatorId+ want:+ - status: WARN+ code: 302+ title: naming.column+ content: '`book`.`creatorId` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 2+- statement: ALTER TABLE tech_book RENAME COLUMN id TO creator_id;+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE book(+ id int,+ creator_id int,+ created_ts timestamp,+ updater_id int,+ updated_ts timestamp);+ ALTER TABLE book CHANGE COLUMN creator_id creatorId int;+ want:+ - status: WARN+ code: 302+ title: naming.column+ content: '`book`.`creatorId` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 7+- statement: ALTER TABLE tech_book CHANGE COLUMN id creator_id int;+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: ALTER TABLE tech_book DROP COLUMN id;+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE book(+ id int,+ creator_id int,+ created_ts timestamp,+ updated_ts timestamp);+ ALTER TABLE book ADD COLUMN contentString varchar(255);+ want:+ - status: WARN+ code: 302+ title: naming.column+ content: '`book`.`contentString` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 6+- statement: |-+ CREATE TABLE book(+ id int,+ createdTs timestamp,+ updaterId int,+ updated_ts timestamp);+ CREATE TABLE student(+ id int,+ createdTs timestamp,+ updatedTs timestamp);+ want:+ - status: WARN+ code: 302+ title: naming.column+ content: '`book`.`createdTs` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 3+ - status: WARN+ code: 302+ title: naming.column+ content: '`book`.`updaterId` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 4+ - status: WARN+ code: 302+ title: naming.column+ content: '`student`.`createdTs` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 8+ - status: WARN+ code: 302+ title: naming.column+ content: '`student`.`updatedTs` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 9diff --git a/plugin/advisor/mysql/test/naming_column_auto_increment.yaml b/plugin/advisor/mysql/test/naming_column_auto_increment.yamlnew file mode 100644index 0000000000..3ea6409ab5--- /dev/null+++ b/plugin/advisor/mysql/test/naming_column_auto_increment.yaml@@ -0,0 +1,35 @@+- statement: CREATE TABLE book(id int AUTO_INCREMENT)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE book(a int AUTO_INCREMENT)+ want:+ - status: WARN+ code: 307+ title: naming.column.auto-increment+ content: '`book`.`a` mismatches auto_increment column naming convention, naming format should be "^id$"'+ line: 1+- statement: ALTER TABLE tech_book ADD COLUMN a int AUTO_INCREMENT+ want:+ - status: WARN+ code: 307+ title: naming.column.auto-increment+ content: '`tech_book`.`a` mismatches auto_increment column naming convention, naming format should be "^id$"'+ line: 1+- statement: ALTER TABLE tech_book CHANGE COLUMN id a int AUTO_INCREMENT+ want:+ - status: WARN+ code: 307+ title: naming.column.auto-increment+ content: '`tech_book`.`a` mismatches auto_increment column naming convention, naming format should be "^id$"'+ line: 1+- statement: ALTER TABLE tech_book MODIFY COLUMN name int AUTO_INCREMENT+ want:+ - status: WARN+ code: 307+ title: naming.column.auto-increment+ content: '`tech_book`.`name` mismatches auto_increment column naming convention, naming format should be "^id$"'+ line: 1diff --git a/plugin/advisor/mysql/test/naming_index_fk.yaml b/plugin/advisor/mysql/test/naming_index_fk.yamlnew file mode 100644index 0000000000..74643398e4--- /dev/null+++ b/plugin/advisor/mysql/test/naming_index_fk.yaml@@ -0,0 +1,47 @@+- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES author (id)+ want:+ - status: WARN+ code: 305+ 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`+ line: 1+- statement: ALTER TABLE tech_book ADD CONSTRAINT rvemempmcmmhutaskvcidmwaldtfjdgmcpkhmibtadfydtkexpuzczrrneucthfwk FOREIGN KEY (author_id) REFERENCES author (id)+ want:+ - status: WARN+ code: 305+ 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 `rvemempmcmmhutaskvcidmwaldtfjdgmcpkhmibtadfydtkexpuzczrrneucthfwk`+ line: 1+ - status: WARN+ code: 305+ title: naming.index.fk+ content: Foreign key `rvemempmcmmhutaskvcidmwaldtfjdgmcpkhmibtadfydtkexpuzczrrneucthfwk` in table `tech_book` mismatches the naming convention, its length should be within 64 characters+ line: 1+- statement: CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id_author_id (author_id) REFERENCES author (id))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE book(id INT, author_id INT, FOREIGN KEY (author_id) REFERENCES author (id))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id (author_id) REFERENCES author (id))+ want:+ - 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: 1diff --git a/plugin/advisor/mysql/test/naming_index_idx.yaml b/plugin/advisor/mysql/test/naming_index_idx.yamlnew file mode 100644index 0000000000..4461459a28--- /dev/null+++ b/plugin/advisor/mysql/test/naming_index_idx.yaml@@ -0,0 +1,68 @@+- statement: CREATE INDEX idx_tech_book_id_name ON tech_book(id, name)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE INDEX tech_book_id_name ON tech_book(id, name)+ want:+ - status: WARN+ code: 303+ 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`+ line: 1+- statement: CREATE INDEX afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw ON tech_book(id, name)+ want:+ - status: WARN+ code: 303+ title: naming.index.idx+ content: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw`+ line: 1+ - status: WARN+ code: 303+ title: naming.index.idx+ content: Index `afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw` in table `tech_book` mismatches the naming convention, its length should be within 64 characters+ line: 1+- statement: ALTER TABLE tech_book RENAME INDEX old_index TO idx_tech_book_id_name+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: ALTER TABLE tech_book RENAME INDEX old_index TO idx_tech_book+ want:+ - status: WARN+ code: 303+ 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`+ line: 1+- statement: ALTER TABLE tech_book ADD INDEX idx_tech_book_id_name (id, name)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: ALTER TABLE tech_book ADD INDEX tech_book_id_name (id, name)+ want:+ - status: WARN+ code: 303+ 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`+ line: 1+- statement: CREATE TABLE tech_book_copy(id INT PRIMARY KEY, name VARCHAR(20), INDEX idx_tech_book_copy_name (name))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE tech_book_copy(id INT PRIMARY KEY, name VARCHAR(20), INDEX (name))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/naming_index_uk.yaml b/plugin/advisor/mysql/test/naming_index_uk.yamlnew file mode 100644index 0000000000..d3efefd84f--- /dev/null+++ b/plugin/advisor/mysql/test/naming_index_uk.yaml@@ -0,0 +1,75 @@+- statement: CREATE UNIQUE INDEX uk_tech_book_id_name ON tech_book(id, name)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE UNIQUE INDEX tech_book_id_name ON tech_book(id, name)+ want:+ - status: WARN+ code: 304+ 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`+ line: 1+- statement: CREATE UNIQUE INDEX qtzmquwvlnttctfluoouxelxeliltcfzzstrtyocogwwyiyrflmrkbhbfasynlacy ON tech_book(id, name)+ want:+ - status: WARN+ code: 304+ title: naming.index.uk+ content: Unique key in table `tech_book` mismatches the naming convention, expect "^$|^uk_tech_book_id_name$" but found `qtzmquwvlnttctfluoouxelxeliltcfzzstrtyocogwwyiyrflmrkbhbfasynlacy`+ line: 1+ - status: WARN+ code: 304+ title: naming.index.uk+ content: Unique key `qtzmquwvlnttctfluoouxelxeliltcfzzstrtyocogwwyiyrflmrkbhbfasynlacy` in table `tech_book` mismatches the naming convention, its length should be within 64 characters+ line: 1+- statement: ALTER TABLE tech_book ADD UNIQUE uk_tech_book_id_name (id, name)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: ALTER TABLE tech_book ADD UNIQUE tech_book_id_name (id, name)+ want:+ - status: WARN+ code: 304+ 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`+ line: 1+- statement: ALTER TABLE tech_book RENAME INDEX old_uk TO uk_tech_book_id_name+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: ALTER TABLE tech_book RENAME INDEX old_uk TO uk_tech_book+ want:+ - status: WARN+ code: 304+ 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`+ line: 1+- statement: CREATE TABLE book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE INDEX uk_book_name (name))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE KEY (name))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE INDEX (name))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/naming_table.yaml b/plugin/advisor/mysql/test/naming_table.yamlnew file mode 100644index 0000000000..4a7a95da34--- /dev/null+++ b/plugin/advisor/mysql/test/naming_table.yaml@@ -0,0 +1,61 @@+- statement: CREATE TABLE techBook(id int, name varchar(255))+ want:+ - status: WARN+ code: 301+ title: naming.table+ content: '`techBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 1+- statement: CREATE TABLE tech_book_copy(id int, name varchar(255))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE cjnubexocfhqoogdmihudyahmmghviqkzvpixnwvxtxumvuannpwdcbtsgwrvzpde(id int, name varchar(255))+ want:+ - status: WARN+ code: 301+ title: naming.table+ content: '`cjnubexocfhqoogdmihudyahmmghviqkzvpixnwvxtxumvuannpwdcbtsgwrvzpde` mismatches table naming convention, its length should be within 64 characters'+ line: 1+- statement: ALTER TABLE tech_book RENAME TO TechBook+ want:+ - status: WARN+ code: 301+ title: naming.table+ content: '`TechBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 1+- statement: ALTER TABLE tech_book RENAME TO tech_book_copy+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: RENAME TABLE tech_book TO tech_book_copy, tech_book_copy TO LiteraryBook+ want:+ - status: WARN+ code: 301+ title: naming.table+ content: '`LiteraryBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 1+- statement: CREATE TABLE literary_book(a int);RENAME TABLE tech_book TO TechBook, literary_book TO LiteraryBook+ want:+ - status: WARN+ code: 301+ title: naming.table+ content: '`TechBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 1+ - status: WARN+ code: 301+ title: naming.table+ content: '`LiteraryBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ line: 1+- statement: CREATE TABLE literary_book(a int);RENAME TABLE tech_book TO tech_book_copy, literary_book TO literary_book_copy+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/schema_backward_compatibility.yaml b/plugin/advisor/mysql/test/schema_backward_compatibility.yamlnew file mode 100644index 0000000000..5ed20c9ff5--- /dev/null+++ b/plugin/advisor/mysql/test/schema_backward_compatibility.yaml@@ -0,0 +1,35 @@+- statement: ALTER TABLE tech_book CHANGE name f2 TEXT+ want:+ - status: WARN+ code: 111+ title: schema.backward-compatibility+ content: '"ALTER TABLE tech_book CHANGE name f2 TEXT" may cause incompatibility with the existing data and code'+ line: 1+- statement: ALTER TABLE tech_book MODIFY name TEXT+ want:+ - status: WARN+ code: 111+ title: schema.backward-compatibility+ content: '"ALTER TABLE tech_book MODIFY name TEXT" may cause incompatibility with the existing data and code'+ line: 1+- statement: ALTER TABLE tech_book MODIFY name TEXT NULL+ want:+ - status: WARN+ code: 111+ title: schema.backward-compatibility+ content: '"ALTER TABLE tech_book MODIFY name TEXT NULL" may cause incompatibility with the existing data and code'+ line: 1+- statement: ALTER TABLE tech_book MODIFY name TEXT NOT NULL+ want:+ - status: WARN+ code: 111+ title: schema.backward-compatibility+ content: '"ALTER TABLE tech_book MODIFY name TEXT NOT NULL" may cause incompatibility with the existing data and code'+ line: 1+- statement: ALTER TABLE tech_book MODIFY name TEXT COMMENT 'bla'+ want:+ - status: WARN+ code: 111+ title: schema.backward-compatibility+ content: '"ALTER TABLE tech_book MODIFY name TEXT COMMENT ''bla''" may cause incompatibility with the existing data and code'+ line: 1diff --git a/plugin/advisor/mysql/test/statement_affected_row_limit.yaml b/plugin/advisor/mysql/test/statement_affected_row_limit.yamlnew file mode 100644index 0000000000..a23ef20e45--- /dev/null+++ b/plugin/advisor/mysql/test/statement_affected_row_limit.yaml@@ -0,0 +1,14 @@+- statement: DELETE FROM tech_book WHERE a > 1+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: UPDATE tech_book SET id = 1+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/statement_disallow_commit.yaml b/plugin/advisor/mysql/test/statement_disallow_commit.yamlnew file mode 100644index 0000000000..0293cbec31--- /dev/null+++ b/plugin/advisor/mysql/test/statement_disallow_commit.yaml@@ -0,0 +1,29 @@+- statement: |-+ START TRANSACTION;+ CREATE TABLE techBook(id int, name varchar(255));+ COMMIT;+ want:+ - status: WARN+ code: 206+ title: statement.disallow-commit+ content: 'Commit is not allowed, related statement: "COMMIT;"'+ line: 3+- statement: |-+ START TRANSACTION;+ CREATE TABLE techBook(id int, name varchar(255));+ COMMIT;++ START TRANSACTION;+ INSERT INTO techBook(id, name) VALUES(1, "book");+ COMMIT;+ want:+ - status: WARN+ code: 206+ title: statement.disallow-commit+ content: 'Commit is not allowed, related statement: "COMMIT;"'+ line: 3+ - status: WARN+ code: 206+ title: statement.disallow-commit+ content: 'Commit is not allowed, related statement: "COMMIT;"'+ line: 7diff --git a/plugin/advisor/mysql/test/statement_disallow_limit.yaml b/plugin/advisor/mysql/test/statement_disallow_limit.yamlnew file mode 100644index 0000000000..a1832b402c--- /dev/null+++ b/plugin/advisor/mysql/test/statement_disallow_limit.yaml@@ -0,0 +1,35 @@+- statement: ""+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: INSERT INTO tech_book SELECT * FROM tech_book LIMIT 1+ want:+ - status: WARN+ code: 1103+ title: statement.disallow-limit+ content: LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but "INSERT INTO tech_book SELECT * FROM tech_book LIMIT 1" uses+ line: 1+- statement: INSERT INTO tech_book SELECT * FROM tech_book UNION SELECT * FROM tech_book LIMIT 1+ want:+ - status: WARN+ code: 1103+ title: statement.disallow-limit+ content: LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but "INSERT INTO tech_book SELECT * FROM tech_book UNION SELECT * FROM tech_book LIMIT 1" uses+ line: 1+- statement: UPDATE tech_book SET name = 'my name' LIMIT 10+ want:+ - status: WARN+ code: 1102+ title: statement.disallow-limit+ content: LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but "UPDATE tech_book SET name = 'my name' LIMIT 10" uses+ line: 1+- statement: DELETE FROM tech_book LIMIT 10+ want:+ - status: WARN+ code: 1106+ title: statement.disallow-limit+ content: LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but "DELETE FROM tech_book LIMIT 10" uses+ line: 1diff --git a/plugin/advisor/mysql/test/statement_disallow_order_by.yaml b/plugin/advisor/mysql/test/statement_disallow_order_by.yamlnew file mode 100644index 0000000000..c0cdd5020a--- /dev/null+++ b/plugin/advisor/mysql/test/statement_disallow_order_by.yaml@@ -0,0 +1,21 @@+- statement: INSERT INTO tech_book values(1, 'a')+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: UPDATE tech_book SET name = 'my name' ORDER BY id+ want:+ - status: WARN+ code: 1104+ title: statement.disallow-order-by+ content: ORDER BY clause is forbidden in DELETE and UPDATE statements, but "UPDATE tech_book SET name = 'my name' ORDER BY id" uses+ line: 1+- statement: DELETE FROM tech_book ORDER BY id+ want:+ - status: WARN+ code: 1105+ title: statement.disallow-order-by+ content: ORDER BY clause is forbidden in DELETE and UPDATE statements, but "DELETE FROM tech_book ORDER BY id" uses+ line: 1diff --git a/plugin/advisor/mysql/test/statement_dml_dry_run.yaml b/plugin/advisor/mysql/test/statement_dml_dry_run.yamlnew file mode 100644index 0000000000..df16988259--- /dev/null+++ b/plugin/advisor/mysql/test/statement_dml_dry_run.yaml@@ -0,0 +1,14 @@+- statement: INSERT INTO tech_book values(1, 'a')+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: DELETE FROM tech_book+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/statement_insert_disallow_order_by_rand.yaml b/plugin/advisor/mysql/test/statement_insert_disallow_order_by_rand.yamlnew file mode 100644index 0000000000..9b5896577a--- /dev/null+++ b/plugin/advisor/mysql/test/statement_insert_disallow_order_by_rand.yaml@@ -0,0 +1,14 @@+- statement: INSERT INTO tech_book VALUES(1, "a")+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: INSERT INTO tech_book SELECT * FROM tech_book ORDER BY rand()+ want:+ - status: WARN+ code: 1108+ title: statement.insert.disallow-order-by-rand+ content: '"INSERT INTO tech_book SELECT * FROM tech_book ORDER BY rand()" uses ORDER BY RAND in the INSERT statement'+ line: 1diff --git a/plugin/advisor/mysql/test/statement_insert_must_specify_column.yaml b/plugin/advisor/mysql/test/statement_insert_must_specify_column.yamlnew file mode 100644index 0000000000..bcf13aec8f--- /dev/null+++ b/plugin/advisor/mysql/test/statement_insert_must_specify_column.yaml@@ -0,0 +1,14 @@+- statement: INSERT INTO tech_book(id, name) VALUES (1, '1')+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: INSERT INTO tech_book VALUES (1, '1')+ want:+ - status: WARN+ code: 1107+ title: statement.insert.must-specify-column+ content: The INSERT statement must specify columns but "INSERT INTO tech_book VALUES (1, '1')" does not+ line: 1diff --git a/plugin/advisor/mysql/test/statement_insert_row_limit.yaml b/plugin/advisor/mysql/test/statement_insert_row_limit.yamlnew file mode 100644index 0000000000..a143330655--- /dev/null+++ b/plugin/advisor/mysql/test/statement_insert_row_limit.yaml@@ -0,0 +1,21 @@+- statement: INSERT INTO tech_book values(1, 'a')+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: INSERT INTO tech_book values(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f')+ want:+ - status: WARN+ code: 1101+ title: statement.insert.row-limit+ content: '"INSERT INTO tech_book values(1, ''a''), (2, ''b''), (3, ''c''), (4, ''d''), (5, ''e''), (6, ''f'')" inserts 6 rows. The count exceeds 5.'+ line: 1+- statement: INSERT INTO tech_book SELECT * FROM tech_book+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/statement_merge_alter_table.yaml b/plugin/advisor/mysql/test/statement_merge_alter_table.yamlnew file mode 100644index 0000000000..a878c9ae74--- /dev/null+++ b/plugin/advisor/mysql/test/statement_merge_alter_table.yaml@@ -0,0 +1,48 @@+- statement: ALTER TABLE tech_book ADD COLUMN a int+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |4-+ ALTER TABLE tech_book ADD COLUMN a int;+ ALTER TABLE tech_book ADD COLUMN b int;+ want:+ - status: WARN+ code: 207+ title: statement.merge-alter-table+ content: There are 2 statements to modify table `tech_book`+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE tech_book ADD COLUMN a int;+ ALTER TABLE t ADD COLUMN b int;+ ALTER TABLE tech_book ADD COLUMN b int;+ want:+ - status: WARN+ code: 207+ title: statement.merge-alter-table+ content: There are 2 statements to modify table `t`+ line: 3+ - status: WARN+ code: 207+ title: statement.merge-alter-table+ content: There are 2 statements to modify table `tech_book`+ line: 4+- statement: |4-+ 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;+ want:+ - status: WARN+ code: 207+ title: statement.merge-alter-table+ content: There are 2 statements to modify table `tech_book`+ line: 3+ - status: WARN+ code: 207+ title: statement.merge-alter-table+ content: There are 2 statements to modify table `t`+ line: 4diff --git a/plugin/advisor/mysql/test/statement_select_no_select_all.yaml b/plugin/advisor/mysql/test/statement_select_no_select_all.yamlnew file mode 100644index 0000000000..7e2c6f4a63--- /dev/null+++ b/plugin/advisor/mysql/test/statement_select_no_select_all.yaml@@ -0,0 +1,21 @@+- statement: SELECT * FROM t+ want:+ - status: WARN+ code: 203+ title: statement.select.no-select-all+ content: '"SELECT * FROM t" uses SELECT all'+ line: 1+- statement: SELECT a, b FROM t+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: SELECT a, b FROM (SELECT * from t1 JOIN t2) t+ want:+ - status: WARN+ code: 203+ title: statement.select.no-select-all+ content: '"SELECT a, b FROM (SELECT * from t1 JOIN t2) t" uses SELECT all'+ line: 1diff --git a/plugin/advisor/mysql/test/statement_where_no_leading_wildcard_like.yaml b/plugin/advisor/mysql/test/statement_where_no_leading_wildcard_like.yamlnew file mode 100644index 0000000000..f4e3424b48--- /dev/null+++ b/plugin/advisor/mysql/test/statement_where_no_leading_wildcard_like.yaml@@ -0,0 +1,35 @@+- statement: SELECT * FROM t WHERE a LIKE 'abc%'+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: SELECT * FROM t WHERE a LIKE '%abc'+ want:+ - status: WARN+ code: 204+ title: statement.where.no-leading-wildcard-like+ content: '"SELECT * FROM t WHERE a LIKE ''%abc''" uses leading wildcard LIKE'+ line: 1+- statement: SELECT * FROM t WHERE a LIKE 'abc' OR a LIKE '%abc'+ want:+ - status: WARN+ code: 204+ title: statement.where.no-leading-wildcard-like+ content: '"SELECT * FROM t WHERE a LIKE ''abc'' OR a LIKE ''%abc''" uses leading wildcard LIKE'+ line: 1+- statement: SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc'+ want:+ - status: WARN+ code: 204+ title: statement.where.no-leading-wildcard-like+ content: '"SELECT * FROM t WHERE a LIKE ''%acc'' OR a LIKE ''%abc''" uses leading wildcard LIKE'+ line: 1+- statement: SELECT * FROM (SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc') t1+ want:+ - status: WARN+ code: 204+ 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'+ line: 1diff --git a/plugin/advisor/mysql/test/statement_where_require.yaml b/plugin/advisor/mysql/test/statement_where_require.yamlnew file mode 100644index 0000000000..e4348c306c--- /dev/null+++ b/plugin/advisor/mysql/test/statement_where_require.yaml@@ -0,0 +1,56 @@+- statement: INSERT INTO tech_book(id) values (1)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: DELETE FROM tech_book+ want:+ - status: WARN+ code: 202+ title: statement.where.require+ content: '"DELETE FROM tech_book" requires WHERE clause'+ line: 1+- statement: UPDATE tech_book SET id = 1+ want:+ - status: WARN+ code: 202+ title: statement.where.require+ content: '"UPDATE tech_book SET id = 1" requires WHERE clause'+ line: 1+- statement: DELETE FROM tech_book WHERE id > 0+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: UPDATE tech_book SET id = 1 WHERE id > 10+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: SELECT id FROM tech_book+ want:+ - status: WARN+ code: 202+ title: statement.where.require+ content: '"SELECT id FROM tech_book" requires WHERE clause'+ line: 1+- statement: SELECT id FROM tech_book WHERE id > 0+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: SELECT id FROM tech_book WHERE id > (SELECT max(id) FROM tech_book)+ want:+ - status: WARN+ code: 202+ title: statement.where.require+ content: '"SELECT id FROM tech_book WHERE id > (SELECT max(id) FROM tech_book)" requires WHERE clause'+ line: 1diff --git a/plugin/advisor/mysql/test/system_charset_allowlist.yaml b/plugin/advisor/mysql/test/system_charset_allowlist.yamlnew file mode 100644index 0000000000..9635c42a58--- /dev/null+++ b/plugin/advisor/mysql/test/system_charset_allowlist.yaml@@ -0,0 +1,78 @@+- statement: CREATE TABLE t(a int) CHARSET utf8mb4+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(a varchar(255))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(a int) CHARSET ascii+ want:+ - status: WARN+ code: 1001+ title: system.charset.allowlist+ content: '"CREATE TABLE t(a int) CHARSET ascii" used disabled charset ''ascii'''+ line: 1+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t CHARSET ascii+ want:+ - status: WARN+ code: 1001+ title: system.charset.allowlist+ content: '"ALTER TABLE t CHARSET ascii" used disabled charset ''ascii'''+ line: 2+- statement: ALTER DATABASE test CHARSET ascii+ want:+ - status: WARN+ code: 1001+ title: system.charset.allowlist+ content: '"ALTER DATABASE test CHARSET ascii" used disabled charset ''ascii'''+ line: 1+- statement: CREATE TABLE t(a varchar(255) CHARSET ascii)+ want:+ - status: WARN+ code: 1001+ title: system.charset.allowlist+ content: '"CREATE TABLE t(a varchar(255) CHARSET ascii)" used disabled charset ''ascii'''+ line: 1+- statement: |4-+ CREATE TABLE t(b int);+ ALTER TABLE t ADD COLUMN a varchar(255) CHARSET ascii+ want:+ - status: WARN+ code: 1001+ title: system.charset.allowlist+ content: '"ALTER TABLE t ADD COLUMN a varchar(255) CHARSET ascii" used disabled charset ''ascii'''+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t MODIFY COLUMN a varchar(255) CHARSET ascii+ want:+ - status: WARN+ code: 1001+ title: system.charset.allowlist+ content: '"ALTER TABLE t MODIFY COLUMN a varchar(255) CHARSET ascii" used disabled charset ''ascii'''+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t CHANGE COLUMN a a varchar(255) CHARSET ascii+ want:+ - status: WARN+ code: 1001+ title: system.charset.allowlist+ content: '"ALTER TABLE t CHANGE COLUMN a a varchar(255) CHARSET ascii" used disabled charset ''ascii'''+ line: 2+- statement: /* this is a comment */+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0diff --git a/plugin/advisor/mysql/test/system_collation_allowlist.yaml b/plugin/advisor/mysql/test/system_collation_allowlist.yamlnew file mode 100644index 0000000000..fabe7e8476--- /dev/null+++ b/plugin/advisor/mysql/test/system_collation_allowlist.yaml@@ -0,0 +1,71 @@+- statement: CREATE TABLE t(a int) COLLATE utf8mb4_polish_ci+ want:+ - status: WARN+ code: 1201+ title: system.collation.allowlist+ content: '"CREATE TABLE t(a int) COLLATE utf8mb4_polish_ci" used disabled collation ''utf8mb4_polish_ci'''+ line: 1+- statement: CREATE TABLE t(a varchar(255))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(a int) COLLATE latin1_bin+ want:+ - status: WARN+ code: 1201+ title: system.collation.allowlist+ content: '"CREATE TABLE t(a int) COLLATE latin1_bin" used disabled collation ''latin1_bin'''+ line: 1+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t COLLATE latin1_bin+ want:+ - status: WARN+ code: 1201+ title: system.collation.allowlist+ content: '"ALTER TABLE t COLLATE latin1_bin" used disabled collation ''latin1_bin'''+ line: 2+- statement: ALTER DATABASE test COLLATE latin1_bin+ want:+ - status: WARN+ code: 1201+ title: system.collation.allowlist+ content: '"ALTER DATABASE test COLLATE latin1_bin" used disabled collation ''latin1_bin'''+ line: 1+- statement: CREATE TABLE t(a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin)+ want:+ - status: WARN+ code: 1201+ title: system.collation.allowlist+ content: '"CREATE TABLE t(a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin)" used disabled collation ''latin1_bin'''+ line: 1+- statement: |4-+ CREATE TABLE t(b int);+ ALTER TABLE t ADD COLUMN a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin+ want:+ - status: WARN+ code: 1201+ title: system.collation.allowlist+ content: '"ALTER TABLE t ADD COLUMN a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin" used disabled collation ''latin1_bin'''+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t MODIFY COLUMN a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin+ want:+ - status: WARN+ code: 1201+ title: system.collation.allowlist+ content: '"ALTER TABLE t MODIFY COLUMN a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin" used disabled collation ''latin1_bin'''+ line: 2+- statement: |4-+ CREATE TABLE t(a int);+ ALTER TABLE t CHANGE COLUMN a a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin+ want:+ - status: WARN+ code: 1201+ title: system.collation.allowlist+ content: '"ALTER TABLE t CHANGE COLUMN a a varchar(255) CHARACTER SET latin1 COLLATE latin1_bin" used disabled collation ''latin1_bin'''+ line: 2diff --git a/plugin/advisor/mysql/test/table_comment.yaml b/plugin/advisor/mysql/test/table_comment.yamlnew file mode 100644index 0000000000..89aae589c4--- /dev/null+++ b/plugin/advisor/mysql/test/table_comment.yaml@@ -0,0 +1,21 @@+- statement: CREATE TABLE t(a int) COMMENT 'some comments'+ want:+ - status: WARN+ code: 606+ title: table.comment+ content: The length of table `t` comment should be within 10 characters+ line: 1+- statement: CREATE TABLE t(a int)+ want:+ - status: WARN+ code: 605+ title: table.comment+ content: Table `t` requires comments+ line: 1+- statement: CREATE TABLE t(a int) COMMENT 'sdlfkjalkseblkjduafelbnlsdfkljayue'+ want:+ - status: WARN+ code: 606+ title: table.comment+ content: The length of table `t` comment should be within 10 characters+ line: 1diff --git a/plugin/advisor/mysql/test/table_disallow_partition.yaml b/plugin/advisor/mysql/test/table_disallow_partition.yamlnew file mode 100644index 0000000000..6f3b7c019d--- /dev/null+++ b/plugin/advisor/mysql/test/table_disallow_partition.yaml@@ -0,0 +1,37 @@+- statement: CREATE TABLE t(a int)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(a int) PARTITION BY RANGE (a) (+ PARTITION p0 VALUES LESS THAN (6),+ PARTITION p1 VALUES LESS THAN (11)+ )+ want:+ - status: WARN+ code: 608+ title: table.disallow-partition+ content: |-+ Table partition is forbidden, but "CREATE TABLE t(a int) PARTITION BY RANGE (a) (+ PARTITION p0 VALUES LESS THAN (6),+ PARTITION p1 VALUES LESS THAN (11)+ )" creates+ line: 4+- statement: |-+ ALTER TABLE tech_book PARTITION BY RANGE (a) (+ PARTITION p0 VALUES LESS THAN (6),+ PARTITION p1 VALUES LESS THAN (11)+ )+ want:+ - status: WARN+ code: 608+ title: table.disallow-partition+ content: |-+ Table partition is forbidden, but "ALTER TABLE tech_book PARTITION BY RANGE (a) (+ PARTITION p0 VALUES LESS THAN (6),+ PARTITION p1 VALUES LESS THAN (11)+ )" creates+ line: 4diff --git a/plugin/advisor/mysql/test/table_drop_naming_convention.yaml b/plugin/advisor/mysql/test/table_drop_naming_convention.yamlnew file mode 100644index 0000000000..7143a405ab--- /dev/null+++ b/plugin/advisor/mysql/test/table_drop_naming_convention.yaml@@ -0,0 +1,21 @@+- statement: DROP TABLE IF EXISTS foo_delete+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: DROP TABLE IF EXISTS foo+ want:+ - status: WARN+ code: 603+ title: table.drop-naming-convention+ content: '`foo` mismatches drop table naming convention, naming format should be "_delete$"'+ line: 1+- statement: DROP TABLE IF EXISTS foo_delete, bar+ want:+ - status: WARN+ code: 603+ title: table.drop-naming-convention+ content: '`bar` mismatches drop table naming convention, naming format should be "_delete$"'+ line: 1diff --git a/plugin/advisor/mysql/test/table_no_foreign_key.yaml b/plugin/advisor/mysql/test/table_no_foreign_key.yamlnew file mode 100644index 0000000000..188ce1b7ce--- /dev/null+++ b/plugin/advisor/mysql/test/table_no_foreign_key.yaml@@ -0,0 +1,14 @@+- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id)+ want:+ - status: WARN+ code: 602+ title: table.no-foreign-key+ content: Foreign key is not allowed in the table `tech_book`+ line: 1+- statement: CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id_author_id (author_id) REFERENCES author (id))+ want:+ - status: WARN+ code: 602+ title: table.no-foreign-key+ content: Foreign key is not allowed in the table `book`+ line: 1diff --git a/plugin/advisor/mysql/test/table_require_pk.yaml b/plugin/advisor/mysql/test/table_require_pk.yamlnew file mode 100644index 0000000000..991ea6b016--- /dev/null+++ b/plugin/advisor/mysql/test/table_require_pk.yaml@@ -0,0 +1,139 @@+- statement: CREATE TABLE t(id INT PRIMARY KEY)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(id INT, PRIMARY KEY (id))+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: CREATE TABLE t(id INT)+ want:+ - status: WARN+ code: 601+ title: table.require-pk+ content: Table `t` requires PRIMARY KEY+ line: 1+- statement: |-+ CREATE TABLE t(id INT);+ DROP TABLE t+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(id INT);+ ALTER TABLE t ADD CONSTRAINT PRIMARY KEY (id)+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(id INT PRIMARY KEY);+ ALTER TABLE t DROP PRIMARY KEY+ want:+ - status: WARN+ code: 601+ title: table.require-pk+ content: Table `t` requires PRIMARY KEY+ line: 2+- statement: |-+ CREATE TABLE t(id INT PRIMARY KEY);+ ALTER TABLE t DROP INDEX `PRIMARY`+ want:+ - status: WARN+ code: 601+ title: table.require-pk+ content: Table `t` requires PRIMARY KEY+ line: 2+- statement: |-+ CREATE TABLE t(id INT);+ ALTER TABLE t ADD COLUMN name varchar(30) PRIMARY KEY+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(id INT);+ ALTER TABLE t CHANGE COLUMN id id INT PRIMARY KEY+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: ALTER TABLE tech_book CHANGE COLUMN id uid INT+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(id INT);+ ALTER TABLE t MODIFY COLUMN id INT PRIMARY KEY+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: ALTER TABLE tech_book MODIFY COLUMN id INT+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(id INT, name varchar(30), PRIMARY KEY(id, name));+ ALTER TABLE t DROP COLUMN id+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ CREATE TABLE t(id INT, name varchar(30), comment varchar(255), PRIMARY KEY(id, name));+ ALTER TABLE t DROP COLUMN id, DROP COLUMN name+ want:+ - status: WARN+ code: 601+ title: table.require-pk+ content: Table `t` requires PRIMARY KEY+ line: 2+- statement: ALTER TABLE tech_book ADD COLUMN a int, DROP COLUMN id, DROP COLUMN name+ want:+ - status: WARN+ code: 601+ title: table.require-pk+ content: Table `tech_book` requires PRIMARY KEY+ line: 1+- statement: ALTER TABLE tech_book DROP COLUMN name+ want:+ - status: SUCCESS+ code: 0+ title: OK+ content: ""+ line: 0+- statement: |-+ ALTER TABLE tech_book CHANGE COLUMN id uid int;+ ALTER TABLE tech_book ADD COLUMN a int, DROP COLUMN uid, DROP COLUMN name+ want:+ - status: WARN+ code: 601+ title: table.require-pk+ content: Table `tech_book` requires PRIMARY KEY+ line: 2diff --git a/plugin/advisor/utils_for_tests.go b/plugin/advisor/utils_for_tests.goindex 2b40cb198c..e24db351eb 100644--- a/plugin/advisor/utils_for_tests.go+++ b/plugin/advisor/utils_for_tests.go@@ -202,34 +202,6 @@ func RunSQLReviewRuleTest(t *testing.T, rule SQLReviewRuleType, dbType db.Type,}}-// RunSQLReviewRuleTests helps to test the SQL review rule.-func RunSQLReviewRuleTests(- t *testing.T,- tests []TestCase,- adv Advisor,- rule *SQLReviewRule,- database *catalog.Database,-) {- ctx := Context{- Charset: "",- Collation: "",- Rule: rule,- Driver: nil,- Context: context.Background(),- }- for _, tc := range tests {- finder := catalog.NewFinder(database, &catalog.FinderContext{CheckIntegrity: true})- if database.DbType == db.MySQL || database.DbType == db.TiDB {- err := finder.WalkThrough(tc.Statement)- require.NoError(t, err, tc.Statement)- }- ctx.Catalog = finder- adviceList, err := adv.Check(ctx, tc.Statement)- require.NoError(t, err)- require.Equal(t, tc.Want, adviceList, tc.Statement)- }-}-// RandomString returns random string with specific length.func RandomString(length int) string {var letters = []rune("abcdefghijklmnopqrstuvwxyz")