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: remove WalkThroughError.Payload field and centralize error codes (#18104)
Danny Xu8cd29a8d90fa
diff --git a/backend/api/v1/release_service_check.go b/backend/api/v1/release_service_check.goindex 33aa75cba4..dc941c663a 100644--- a/backend/api/v1/release_service_check.go+++ b/backend/api/v1/release_service_check.go@@ -13,6 +13,7 @@ import (v1pb "github.com/bytebase/bytebase/backend/generated-go/v1""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"advisorpg "github.com/bytebase/bytebase/backend/plugin/advisor/pg""github.com/bytebase/bytebase/backend/plugin/db""github.com/bytebase/bytebase/backend/plugin/parser/pg"@@ -220,7 +221,7 @@ loop:Advices: []*v1pb.Advice{{Status: v1pb.Advice_WARNING,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Applied file has been modified",Content: fmt.Sprintf("The file %q with version %q has already been applied to the database, but its content has been modified. Applied SHA256: %s, Release SHA256: %s", file.Path, file.Version, appliedRevision.Payload.SheetSha256, file.SheetSha256),},@@ -328,7 +329,7 @@ loop:Advices: []*v1pb.Advice{{Status: v1pb.Advice_ERROR,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Failed to check",Content: err.Error(),},@@ -409,7 +410,7 @@ func (s *ReleaseService) checkReleaseDeclarative(ctx context.Context, files []*vAdvices: []*v1pb.Advice{{Status: v1pb.Advice_WARNING,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Applied file has been modified",Content: fmt.Sprintf("The file %q has version %q, but there is an equal or higher version %q applied", file.Path, file.Version, revisions[0].Version),},@@ -438,7 +439,7 @@ func (s *ReleaseService) checkReleaseDeclarative(ctx context.Context, files []*v// Continue with other checks even if style check failssdlStyleAdvices[filePath] = []*storepb.Advice{{Status: storepb.Advice_ERROR,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Failed to check SDL style",Content: err.Error(),}}@@ -501,7 +502,7 @@ func (s *ReleaseService) checkReleaseDeclarative(ctx context.Context, files []*vif err != nil {checkResult.Advices = append(checkResult.Advices, &v1pb.Advice{Status: v1pb.Advice_ERROR,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Failed to parse statement types",Content: err.Error(),})@@ -512,7 +513,7 @@ func (s *ReleaseService) checkReleaseDeclarative(ctx context.Context, files []*v// Create a separate advice for each disallowed statement with positionadvice := &v1pb.Advice{Status: v1pb.Advice_ERROR,- Code: advisor.StatementDisallowedInSDL.Int32(),+ Code: code.StatementDisallowedInSDL.Int32(),Title: "Disallowed statement in SDL file",Content: fmt.Sprintf("Statement type '%s' is not allowed in SDL files.\n\n"+diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.goindex 4c874db5f7..7053048ff0 100644--- a/backend/api/v1/sql_service.go+++ b/backend/api/v1/sql_service.go@@ -29,7 +29,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store"v1pb "github.com/bytebase/bytebase/backend/generated-go/v1""github.com/bytebase/bytebase/backend/generated-go/v1/v1connect"- "github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/db"parserbase "github.com/bytebase/bytebase/backend/plugin/parser/base""github.com/bytebase/bytebase/backend/plugin/schema"@@ -1560,7 +1560,7 @@ func validateQueryRequest(instance *store.InstanceMessage, statement string) errif syntaxErr, ok := err.(*parserbase.SyntaxError); ok {err := connect.NewError(connect.CodeInvalidArgument, syntaxErr)if detail, detailErr := connect.NewErrorDetail(&v1pb.PlanCheckRun_Result{- Code: int32(advisor.StatementSyntaxError),+ Code: int32(code.StatementSyntaxError),Content: syntaxErr.Message,Title: "Syntax error",Status: v1pb.Advice_ERROR,diff --git a/backend/plugin/advisor/catalog/state.go b/backend/plugin/advisor/catalog/state.goindex f0faff6fc0..4dceb56043 100644--- a/backend/plugin/advisor/catalog/state.go+++ b/backend/plugin/advisor/catalog/state.go@@ -9,6 +9,7 @@ import ("strings"storepb "github.com/bytebase/bytebase/backend/generated-go/store"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")// NewDatabaseState creates a new database state from schema metadata and context.@@ -622,7 +623,7 @@ func (d *DatabaseState) GetSchema(schemaName string) (*SchemaState, *WalkThrough}if schemaName != publicSchemaName {return nil, &WalkThroughError{- Type: ErrorTypeSchemaNotExists,+ Code: code.SchemaNotExists,Content: fmt.Sprintf("The schema %q doesn't exist", schemaName),}}@@ -634,7 +635,7 @@ func (d *DatabaseState) DropSchema(schemaName string) *WalkThroughError {schema, exists := d.schemaSet[schemaName]if !exists {return &WalkThroughError{- Type: ErrorTypeSchemaNotExists,+ Code: code.SchemaNotExists,Content: fmt.Sprintf("Schema %q does not exist", schemaName),}}@@ -686,7 +687,7 @@ func (s *SchemaState) GetTable(tableName string) (*TableState, *WalkThroughErrortable, exists := s.tableSet[tableName]if !exists {return nil, &WalkThroughError{- Type: ErrorTypeTableNotExists,+ Code: code.TableNotExists,Content: fmt.Sprintf("The table %q does not exist in schema %q", tableName, s.name),}}@@ -708,9 +709,8 @@ func (s *SchemaState) DropTable(tableName string, checkViewDependency func(*Tabl}if len(viewList) > 0 {return &WalkThroughError{- Type: ErrorTypeTableIsReferencedByView,+ Code: code.TableIsReferencedByView,Content: fmt.Sprintf("Cannot drop table %q.%q, it's referenced by view: %s", s.name, table.name, strings.Join(viewList, ", ")),- Payload: viewList,}}}@@ -767,7 +767,7 @@ func (s *SchemaState) RenameTable(oldName string, newName string) *WalkThroughErfunc (t *TableState) CreateColumn(columnName string, columnType *string, nullable *bool, defaultValue *string, position *int, characterSet *string, collation *string, comment *string) *WalkThroughError {if _, exists := t.columnSet[strings.ToLower(columnName)]; exists {return &WalkThroughError{- Type: ErrorTypeColumnExists,+ Code: code.ColumnExists,Content: fmt.Sprintf("Column `%s` already exists in table `%s`", columnName, t.name),}}@@ -815,7 +815,7 @@ func (t *TableState) DropColumn(columnName string, checkViewDependency func(*Col// Cannot drop all columns in a table using ALTER TABLE DROP COLUMN.if len(t.columnSet) == 1 {return &WalkThroughError{- Type: ErrorTypeDropAllColumns,+ Code: code.DropAllColumns,Content: fmt.Sprintf("Can't delete all columns with ALTER TABLE; use DROP TABLE %s instead", t.name),}}@@ -828,9 +828,8 @@ func (t *TableState) DropColumn(columnName string, checkViewDependency func(*Col}if len(viewList) > 0 {return &WalkThroughError{- Type: ErrorTypeColumnIsReferencedByView,+ Code: code.ColumnIsReferencedByView,Content: fmt.Sprintf("Cannot drop column %q in table %q, it's referenced by view: %s", column.name, t.name, strings.Join(viewList, ", ")),- Payload: viewList,}}}@@ -878,7 +877,7 @@ func (t *TableState) RenameColumn(oldName string, newName string) *WalkThroughErif _, exists := t.columnSet[strings.ToLower(newName)]; exists {return &WalkThroughError{- Type: ErrorTypeColumnExists,+ Code: code.ColumnExists,Content: fmt.Sprintf("Column `%s` already exists in table `%s`", newName, t.name),}}@@ -906,7 +905,7 @@ func (t *TableState) RenameColumn(oldName string, newName string) *WalkThroughErfunc (t *TableState) CreateIndex(indexName string, expressionList []string, unique bool, indexType string, primary bool, visible *bool, comment *string, isConstraint bool, identifierMap identifierMap) *WalkThroughError {if len(expressionList) == 0 {return &WalkThroughError{- Type: ErrorTypeIndexEmptyKeys,+ Code: code.IndexEmptyKeys,Content: fmt.Sprintf("Index `%s` in table `%s` has empty key", indexName, t.name),}}@@ -974,7 +973,7 @@ func (t *TableState) CreatePrimaryKey(keyList []string, indexType string, identiif _, exists := t.indexSet[strings.ToLower(pkName)]; exists {return &WalkThroughError{- Type: ErrorTypePrimaryKeyExists,+ Code: code.PrimaryKeyExists,Content: fmt.Sprintf("Primary key exists in table `%s`", t.name),}}@@ -1022,7 +1021,7 @@ func (t *TableState) DropIndex(indexName string, identifierMap identifierMap) *Wif _, exists := t.indexSet[strings.ToLower(indexName)]; !exists {if strings.EqualFold(indexName, PrimaryKeyName) {return &WalkThroughError{- Type: ErrorTypePrimaryKeyNotExists,+ Code: code.PrimaryKeyNotExists,Content: fmt.Sprintf("Primary key does not exist in table `%s`", t.name),}}@@ -1049,7 +1048,7 @@ func (t *TableState) RenameIndex(oldName string, newName string, identifierMap iincorrectName = newName}return &WalkThroughError{- Type: ErrorTypeIncorrectIndexName,+ Code: code.IncorrectIndexName,Content: fmt.Sprintf("Incorrect index name `%s`", incorrectName),}}diff --git a/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml b/backend/plugin/advisor/catalog/test/mysql_walk_through.yamlindex 7cfecfe1d2..d7d04ea91a 100644--- a/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml+++ b/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml@@ -1,995 +1,419 @@-- statement: |-- CREATE TABLE `test`.`t1` (a INT);+- statement: 'CREATE TABLE `test`.`t1` (a INT);+CREATE TABLE `other`.`t1` (a INT);- RENAME TABLE `other`.`t1` TO `other`.`t2`;++ RENAME TABLE `other`.`t1` TO `other`.`t2`;'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 201+ code: 702content: Database `other` is not the current database `test`line: 2- payload: null-- statement: |-- CREATE TABLE `test`.`t1` (a INT);- RENAME TABLE `test`.`t1` TO `other`.`t1`;+- statement: 'CREATE TABLE `test`.`t1` (a INT);++ RENAME TABLE `test`.`t1` TO `other`.`t1`;'ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {}- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {}\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(a INT);+- statement: 'CREATE TABLE t1(a INT);+CREATE TABLE t2(a INT);- RENAME TABLE t2 TO t1;++ RENAME TABLE t2 TO t1;'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 301+ code: 607content: Table `t1` already existsline: 3- payload: null-- statement: |-- CREATE TABLE t1(a INT);- RENAME TABLE t2 TO t3;+- statement: 'CREATE TABLE t1(a INT);++ RENAME TABLE t2 TO t3;'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 302+ code: 604content: Table `t2` does not existline: 2- payload: null-- statement: |-- CREATE TABLE t1 (a INT);- RENAME TABLE t1 TO t2;+- statement: 'CREATE TABLE t1 (a INT);++ RENAME TABLE t1 TO t2;'ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t2",- "columns": [- {- "name": "a",- "position": 1,- "nullable": true,- "type": "int"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t2\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"nullable\": true,\n \"type\": \"int\"\n }\n\+ \ ]\n }\n ]\n }\n ]\n}"err: null- statement: CREATE DATABASE another;ignore_case_sensitive: false- want: ""+ want: ''err:- type: 201+ code: 702content: Database `another` is not the current database `test`line: 1- payload: null-- statement: |-- -- this is comment+- statement: '-- this is comment+DROP DATABASE test;- CREATE TABLE t(a int);++ CREATE TABLE t(a int);'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 202+ code: 703content: Database `test` is deletedline: 1- payload: null-- statement: |-- ALTER DATABASE CHARACTER SET = utf8mb4;- ALTER DATABASE test COLLATE utf8mb4_polish_ci;+- statement: 'ALTER DATABASE CHARACTER SET = utf8mb4;++ ALTER DATABASE test COLLATE utf8mb4_polish_ci;'ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {}- ],- "characterSet": "utf8mb4",- "collation": "utf8mb4_polish_ci"- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {}\n ],\n \"characterSet\"\+ : \"utf8mb4\",\n \"collation\": \"utf8mb4_polish_ci\"\n}"err: null-- statement: |-- CREATE TABLE t1(- a INT PRIMARY KEY,- c VARCHAR(255) NOT NULL- );- ALTER TABLE t1 ADD INDEX idx1 (c);- CREATE FULLTEXT INDEX ftk1 ON t1 (c);- DROP INDEX `PRIMARY` ON t1;- DROP INDEX idx1 ON t1;- DROP INDEX ftk1 ON t1;+- statement: "CREATE TABLE t1(\n a INT PRIMARY KEY,\n c VARCHAR(255) NOT NULL\n\+ );\nALTER TABLE t1 ADD INDEX idx1 (c);\nCREATE FULLTEXT INDEX ftk1 ON t1 (c);\n\+ DROP INDEX `PRIMARY` ON t1;\nDROP INDEX idx1 ON t1;\nDROP INDEX ftk1 ON t1;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "type": "int"- },- {- "name": "c",- "position": 2,- "type": "varchar"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"type\": \"int\"\n },\n {\n \"name\"\+ : \"c\",\n \"position\": 2,\n \"type\": \"varchar\"\n\+ \ }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(- a INT,- b INT,- c VARCHAR(255) NOT NULL,- d GEOMETRY NOT NULL- );- CREATE INDEX idx1 ON t1 (a) INVISIBLE;- CREATE UNIQUE INDEX uk1 ON t1 (b);- CREATE FULLTEXT INDEX ftk1 ON t1 (c);- CREATE SPATIAL INDEX sk1 ON t1 (d);+- statement: "CREATE TABLE t1(\n a INT,\n b INT,\n c VARCHAR(255) NOT NULL,\n \+ \ d GEOMETRY NOT NULL\n);\nCREATE INDEX idx1 ON t1 (a) INVISIBLE;\nCREATE UNIQUE\+ \ INDEX uk1 ON t1 (b);\nCREATE FULLTEXT INDEX ftk1 ON t1 (c);\nCREATE SPATIAL\+ \ INDEX sk1 ON t1 (d);"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "nullable": true,- "type": "int"- },- {- "name": "b",- "position": 2,- "nullable": true,- "type": "int"- },- {- "name": "c",- "position": 3,- "type": "varchar"- },- {- "name": "d",- "position": 4,- "type": "geometry"- }- ],- "indexes": [- {- "name": "ftk1",- "expressions": [- "c"- ],- "type": "FULLTEXT",- "visible": true- },- {- "name": "idx1",- "expressions": [- "a"- ],- "type": "BTREE"- },- {- "name": "sk1",- "expressions": [- "d"- ],- "type": "SPATIAL",- "visible": true- },- {- "name": "uk1",- "expressions": [- "b"- ],- "type": "BTREE",- "unique": true,- "visible": true- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"nullable\": true,\n \"type\": \"int\"\n },\n\+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\+ \ \"nullable\": true,\n \"type\": \"int\"\n \+ \ },\n {\n \"name\": \"c\",\n \"position\"\+ : 3,\n \"type\": \"varchar\"\n },\n {\n \+ \ \"name\": \"d\",\n \"position\": 4,\n \"\+ type\": \"geometry\"\n }\n ],\n \"indexes\": [\n\+ \ {\n \"name\": \"ftk1\",\n \"expressions\"\+ : [\n \"c\"\n ],\n \"type\": \"FULLTEXT\"\+ ,\n \"visible\": true\n },\n {\n \+ \ \"name\": \"idx1\",\n \"expressions\": [\n \"\+ a\"\n ],\n \"type\": \"BTREE\"\n },\n \+ \ {\n \"name\": \"sk1\",\n \"expressions\":\+ \ [\n \"d\"\n ],\n \"type\": \"SPATIAL\"\+ ,\n \"visible\": true\n },\n {\n \+ \ \"name\": \"uk1\",\n \"expressions\": [\n \"\+ b\"\n ],\n \"type\": \"BTREE\",\n \"unique\"\+ : true,\n \"visible\": true\n }\n ]\n \+ \ }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(a GEOMETRY);- CREATE SPATIAL INDEX sk1 ON t1 (a);+- statement: 'CREATE TABLE t1(a GEOMETRY);++ CREATE SPATIAL INDEX sk1 ON t1 (a);'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 507+ code: 811content: All parts of a SPATIAL index must be NOT NULL, but `a` is nullableline: 2- payload: null-- statement: |-- CREATE TABLE t1(- a INT PRIMARY KEY,- b INT,- UNIQUE uk1 (b)- );- ALTER TABLE t1 ENGINE = MyISAM;- ALTER TABLE t1 COMMENT = 't1 table';- ALTER TABLE t1 COLLATE utf8mb4_unicode_ci;+- statement: "CREATE TABLE t1(\n a INT PRIMARY KEY,\n b INT,\n UNIQUE uk1 (b)\n\+ );\nALTER TABLE t1 ENGINE = MyISAM;\nALTER TABLE t1 COMMENT = 't1 table';\nALTER\+ \ TABLE t1 COLLATE utf8mb4_unicode_ci;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "type": "int"- },- {- "name": "b",- "position": 2,- "nullable": true,- "type": "int"- }- ],- "indexes": [- {- "name": "PRIMARY",- "expressions": [- "a"- ],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true- },- {- "name": "uk1",- "expressions": [- "b"- ],- "type": "BTREE",- "unique": true,- "visible": true- }- ],- "engine": "MyISAM",- "collation": "utf8mb4_unicode_ci",- "comment": "t1 table"- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"type\": \"int\"\n },\n {\n \"name\"\+ : \"b\",\n \"position\": 2,\n \"nullable\": true,\n\+ \ \"type\": \"int\"\n }\n ],\n \"indexes\"\+ : [\n {\n \"name\": \"PRIMARY\",\n \"expressions\"\+ : [\n \"a\"\n ],\n \"type\": \"BTREE\"\+ ,\n \"unique\": true,\n \"primary\": true,\n \+ \ \"visible\": true\n },\n {\n \"name\"\+ : \"uk1\",\n \"expressions\": [\n \"b\"\n \+ \ ],\n \"type\": \"BTREE\",\n \"unique\": true,\n\+ \ \"visible\": true\n }\n ],\n \"engine\"\+ : \"MyISAM\",\n \"collation\": \"utf8mb4_unicode_ci\",\n \"\+ comment\": \"t1 table\"\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(- a INT PRIMARY KEY,- b INT,- UNIQUE uk1 (b)- );- ALTER TABLE t1 DROP PRIMARY KEY;- ALTER TABLE t1 DROP INDEX uk1;+- statement: "CREATE TABLE t1(\n a INT PRIMARY KEY,\n b INT,\n UNIQUE uk1 (b)\n\+ );\nALTER TABLE t1 DROP PRIMARY KEY;\nALTER TABLE t1 DROP INDEX uk1;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "type": "int"- },- {- "name": "b",- "position": 2,- "nullable": true,- "type": "int"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"type\": \"int\"\n },\n {\n \"name\"\+ : \"b\",\n \"position\": 2,\n \"nullable\": true,\n\+ \ \"type\": \"int\"\n }\n ]\n }\n \+ \ ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(- a INT,- b INT,- UNIQUE uk1 (b)- );- ALTER TABLE t1 RENAME INDEX uk1 TO uk_b;- ALTER TABLE t1 ADD INDEX idx1 (b);- ALTER TABLE t1 RENAME INDEX idx1 TO idx2;- ALTER TABLE t1 ALTER INDEX idx2 INVISIBLE;- ALTER TABLE t1 RENAME TO t2;+- statement: "CREATE TABLE t1(\n a INT,\n b INT,\n UNIQUE uk1 (b)\n);\nALTER TABLE\+ \ t1 RENAME INDEX uk1 TO uk_b;\nALTER TABLE t1 ADD INDEX idx1 (b);\nALTER TABLE\+ \ t1 RENAME INDEX idx1 TO idx2;\nALTER TABLE t1 ALTER INDEX idx2 INVISIBLE;\n\+ ALTER TABLE t1 RENAME TO t2;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t2",- "columns": [- {- "name": "a",- "position": 1,- "nullable": true,- "type": "int"- },- {- "name": "b",- "position": 2,- "nullable": true,- "type": "int"- }- ],- "indexes": [- {- "name": "idx2",- "expressions": [- "b"- ],- "type": "BTREE"- },- {- "name": "uk_b",- "expressions": [- "b"- ],- "type": "BTREE",- "unique": true,- "visible": true- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t2\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"nullable\": true,\n \"type\": \"int\"\n },\n\+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\+ \ \"nullable\": true,\n \"type\": \"int\"\n \+ \ }\n ],\n \"indexes\": [\n {\n \"\+ name\": \"idx2\",\n \"expressions\": [\n \"b\"\n \+ \ ],\n \"type\": \"BTREE\"\n },\n \+ \ {\n \"name\": \"uk_b\",\n \"expressions\": [\n\+ \ \"b\"\n ],\n \"type\": \"BTREE\",\n\+ \ \"unique\": true,\n \"visible\": true\n \+ \ }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(a INT NOT NULL);- ALTER TABLE t1 ALTER COLUMN a SET DEFAULT NULL;+- statement: 'CREATE TABLE t1(a INT NOT NULL);++ ALTER TABLE t1 ALTER COLUMN a SET DEFAULT NULL;'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 406+ code: 428content: Invalid default value for column `a`line: 2- payload: null-- statement: |-- CREATE TABLE t1(a INT);+- statement: 'CREATE TABLE t1(a INT);+ALTER TABLE t1 CHANGE COLUMN a a BLOB;- ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 'default value';++ ALTER TABLE t1 ALTER COLUMN a SET DEFAULT ''default value'';'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 407+ code: 423content: BLOB, TEXT, GEOMETRY or JSON column `a` can't have a default valueline: 3- payload: null-- statement: |-- CREATE TABLE t1(a INT);+- statement: 'CREATE TABLE t1(a INT);+ALTER TABLE t1 CHANGE COLUMN a a BLOB;- ALTER TABLE t1 ALTER COLUMN a SET DEFAULT NULL;++ ALTER TABLE t1 ALTER COLUMN a SET DEFAULT NULL;'ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "nullable": true,- "type": "blob"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"nullable\": true,\n \"type\": \"blob\"\n }\n\+ \ ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(- a INT- );- ALTER TABLE t1 ADD COLUMN b INT AFTER a;- ALTER TABLE t1 ADD COLUMN c INT NOT NULL DEFAULT 1 AFTER a;- ALTER TABLE t1 CHANGE COLUMN b d TEXT AFTER a;- ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 1;- ALTER TABLE t1 ALTER COLUMN a SET INVISIBLE;- ALTER TABLE t1 ALTER COLUMN c DROP DEFAULT;+- statement: "CREATE TABLE t1(\n a INT\n);\nALTER TABLE t1 ADD COLUMN b INT AFTER\+ \ a;\nALTER TABLE t1 ADD COLUMN c INT NOT NULL DEFAULT 1 AFTER a;\nALTER TABLE\+ \ t1 CHANGE COLUMN b d TEXT AFTER a;\nALTER TABLE t1 ALTER COLUMN a SET DEFAULT\+ \ 1;\nALTER TABLE t1 ALTER COLUMN a SET INVISIBLE;\nALTER TABLE t1 ALTER COLUMN\+ \ c DROP DEFAULT;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "default": "1",- "nullable": true,- "type": "int"- },- {- "name": "d",- "position": 2,- "nullable": true,- "type": "text"- },- {- "name": "c",- "position": 3,- "type": "int"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"default\": \"1\",\n \"nullable\": true,\n \+ \ \"type\": \"int\"\n },\n {\n \"name\": \"\+ d\",\n \"position\": 2,\n \"nullable\": true,\n \+ \ \"type\": \"text\"\n },\n {\n \"\+ name\": \"c\",\n \"position\": 3,\n \"type\": \"int\"\+ \n }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(- a INT- );- ALTER TABLE t1 ADD COLUMN b VARCHAR(255) FIRST;- ALTER TABLE t1 ADD COLUMN (c INT, d BLOB);- ALTER TABLE t1 MODIFY COLUMN b INT AFTER a;- ALTER TABLE t1 RENAME COLUMN b TO e;- ALTER TABLE t1 CHANGE COLUMN d f TEXT AFTER e;- ALTER TABLE t1 DROP COLUMN a;+- statement: "CREATE TABLE t1(\n a INT\n);\nALTER TABLE t1 ADD COLUMN b VARCHAR(255)\+ \ FIRST;\nALTER TABLE t1 ADD COLUMN (c INT, d BLOB);\nALTER TABLE t1 MODIFY COLUMN\+ \ b INT AFTER a;\nALTER TABLE t1 RENAME COLUMN b TO e;\nALTER TABLE t1 CHANGE\+ \ COLUMN d f TEXT AFTER e;\nALTER TABLE t1 DROP COLUMN a;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "e",- "position": 1,- "nullable": true,- "type": "int"- },- {- "name": "f",- "position": 2,- "nullable": true,- "type": "text"- },- {- "name": "c",- "position": 3,- "nullable": true,- "type": "int"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"e\",\n \"position\": 1,\n \+ \ \"nullable\": true,\n \"type\": \"int\"\n },\n\+ \ {\n \"name\": \"f\",\n \"position\": 2,\n\+ \ \"nullable\": true,\n \"type\": \"text\"\n \+ \ },\n {\n \"name\": \"c\",\n \"position\"\+ : 3,\n \"nullable\": true,\n \"type\": \"int\"\n \+ \ }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(a INT);+- statement: 'CREATE TABLE t1(a INT);+CREATE TABLE t2(a INT);+DROP TABLE t1, t2;- CREATE TABLE t3(a INT);++ CREATE TABLE t3(a INT);'ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t3",- "columns": [- {- "name": "a",- "position": 1,- "nullable": true,- "type": "int"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t3\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"nullable\": true,\n \"type\": \"int\"\n }\n\+ \ ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(- a INT AUTO_INCREMENT,- b INT AUTO_INCREMENT- );+- statement: "CREATE TABLE t1(\n a INT AUTO_INCREMENT,\n b INT AUTO_INCREMENT\n\+ );"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 404+ code: 426content: There can be only one auto column for table `t1`line: 1- payload: null-- statement: CREATE TABLE tvx SELECT (x,z) FROM (VALUES ROW(1,3,5), ROW(2,4,6)) AS v(x,y,z);+- statement: CREATE TABLE tvx SELECT (x,z) FROM (VALUES ROW(1,3,5), ROW(2,4,6)) AS+ v(x,y,z);ignore_case_sensitive: false- want: ""+ want: ''err:- type: 303- content: Disallow the CREATE TABLE AS statement but "CREATE TABLE tvx SELECT (x,z) FROM (VALUES ROW(1,3,5), ROW(2,4,6)) AS v(x,y,z);" uses+ code: 205+ content: Disallow the CREATE TABLE AS statement but "CREATE TABLE tvx SELECT (x,z)+ FROM (VALUES ROW(1,3,5), ROW(2,4,6)) AS v(x,y,z);" usesline: 1- payload: null-- statement: |-- CREATE TABLE t1(a int);- CREATE TABLE t2 (b INT) SELECT a FROM t1;+- statement: 'CREATE TABLE t1(a int);++ CREATE TABLE t2 (b INT) SELECT a FROM t1;'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 303- content: Disallow the CREATE TABLE AS statement but "CREATE TABLE t2 (b INT) SELECT a FROM t1;" uses+ code: 205+ content: Disallow the CREATE TABLE AS statement but "CREATE TABLE t2 (b INT) SELECT+ a FROM t1;" usesline: 2- payload: null-- statement: |-- CREATE TABLE t1(- a int- );- CREATE TABLE t2 LIKE t1;+- statement: "CREATE TABLE t1(\n a int\n);\nCREATE TABLE t2 LIKE t1;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "nullable": true,- "type": "int"- }- ]- },- {- "name": "t2",- "columns": [- {- "name": "a",- "position": 1,- "nullable": true,- "type": "int"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"nullable\": true,\n \"type\": \"int\"\n }\n\+ \ ]\n },\n {\n \"name\": \"t2\",\n \"\+ columns\": [\n {\n \"name\": \"a\",\n \"\+ position\": 1,\n \"nullable\": true,\n \"type\": \"\+ int\"\n }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(- a INT PRIMARY KEY,- b INT NOT NULL DEFAULT 1,- c INT,- d VARCHAR(255) NOT NULL,- e VARCHAR(255),- UNIQUE KEY uk1 (b, c),- KEY idx1 (c),- FULLTEXT(d, e) WITH PARSER ngram INVISIBLE- );+- statement: "CREATE TABLE t1(\n a INT PRIMARY KEY,\n b INT NOT NULL DEFAULT 1,\n\+ \ c INT,\n d VARCHAR(255) NOT NULL,\n e VARCHAR(255),\n UNIQUE KEY uk1 (b,\+ \ c),\n KEY idx1 (c),\n FULLTEXT(d, e) WITH PARSER ngram INVISIBLE\n);"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "type": "int"- },- {- "name": "b",- "position": 2,- "default": "1",- "type": "int"- },- {- "name": "c",- "position": 3,- "nullable": true,- "type": "int"- },- {- "name": "d",- "position": 4,- "type": "varchar"- },- {- "name": "e",- "position": 5,- "nullable": true,- "type": "varchar"- }- ],- "indexes": [- {- "name": "PRIMARY",- "expressions": [- "a"- ],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true- },- {- "name": "d",- "expressions": [- "d",- "e"- ],- "type": "FULLTEXT"- },- {- "name": "idx1",- "expressions": [- "c"- ],- "type": "BTREE",- "visible": true- },- {- "name": "uk1",- "expressions": [- "b",- "c"- ],- "type": "BTREE",- "unique": true,- "visible": true- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"type\": \"int\"\n },\n {\n \"name\"\+ : \"b\",\n \"position\": 2,\n \"default\": \"1\",\n\+ \ \"type\": \"int\"\n },\n {\n \+ \ \"name\": \"c\",\n \"position\": 3,\n \"nullable\"\+ : true,\n \"type\": \"int\"\n },\n {\n \+ \ \"name\": \"d\",\n \"position\": 4,\n \"\+ type\": \"varchar\"\n },\n {\n \"name\": \"\+ e\",\n \"position\": 5,\n \"nullable\": true,\n \+ \ \"type\": \"varchar\"\n }\n ],\n \"indexes\"\+ : [\n {\n \"name\": \"PRIMARY\",\n \"expressions\"\+ : [\n \"a\"\n ],\n \"type\": \"BTREE\"\+ ,\n \"unique\": true,\n \"primary\": true,\n \+ \ \"visible\": true\n },\n {\n \"name\"\+ : \"d\",\n \"expressions\": [\n \"d\",\n \+ \ \"e\"\n ],\n \"type\": \"FULLTEXT\"\n \+ \ },\n {\n \"name\": \"idx1\",\n \"\+ expressions\": [\n \"c\"\n ],\n \"type\"\+ : \"BTREE\",\n \"visible\": true\n },\n {\n\+ \ \"name\": \"uk1\",\n \"expressions\": [\n \+ \ \"b\",\n \"c\"\n ],\n \"type\"\+ : \"BTREE\",\n \"unique\": true,\n \"visible\": true\n\+ \ }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(- a INT NOT NULL DEFAULT NULL- );+- statement: "CREATE TABLE t1(\n a INT NOT NULL DEFAULT NULL\n);"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 406+ code: 428content: Invalid default value for column `a`line: 2- payload: null-- statement: |-- CREATE TABLE t1(- a BLOB DEFAULT 'this is a default value'- );+- statement: "CREATE TABLE t1(\n a BLOB DEFAULT 'this is a default value'\n);"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 407+ code: 423content: BLOB, TEXT, GEOMETRY or JSON column `a` can't have a default valueline: 2- payload: null-- statement: |-- CREATE TABLE t1(- a INT ON UPDATE NOW()- );+- statement: "CREATE TABLE t1(\n a INT ON UPDATE NOW()\n);"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 405+ code: 427content: Column `a` use ON UPDATE but is not DATETIME or TIMESTAMPline: 2- payload: null-- statement: |-- CREATE TABLE t1(- a INT NOT NULL DEFAULT 1 PRIMARY KEY,- b INT UNIQUE,- c VARCHAR(255) NOT NULL DEFAULT 'NULL' COMMENT 'column c',- e INT NULL DEFAULT NULL,- f VARCHAR(10) NOT NULL COLLATE utf8mb4_polish_ci,- g VARCHAR(200) CHARACTER SET utf8mb4 NOT NULL- );+- statement: "CREATE TABLE t1(\n a INT NOT NULL DEFAULT 1 PRIMARY KEY,\n b INT UNIQUE,\n\+ \ c VARCHAR(255) NOT NULL DEFAULT 'NULL' COMMENT 'column c',\n e INT NULL DEFAULT\+ \ NULL,\n f VARCHAR(10) NOT NULL COLLATE utf8mb4_polish_ci,\n g VARCHAR(200)\+ \ CHARACTER SET utf8mb4 NOT NULL\n);"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "default": "1",- "type": "int"- },- {- "name": "b",- "position": 2,- "nullable": true,- "type": "int"- },- {- "name": "c",- "position": 3,- "default": "NULL",- "type": "varchar",- "comment": "column c"- },- {- "name": "e",- "position": 4,- "nullable": true,- "type": "int"- },- {- "name": "f",- "position": 5,- "type": "varchar",- "collation": "utf8mb4_polish_ci"- },- {- "name": "g",- "position": 6,- "type": "varchar",- "characterSet": "utf8mb4"- }- ],- "indexes": [- {- "name": "PRIMARY",- "expressions": [- "a"- ],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true- },- {- "name": "b",- "expressions": [- "b"- ],- "type": "BTREE",- "unique": true,- "visible": true- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"default\": \"1\",\n \"type\": \"int\"\n },\n\+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\+ \ \"nullable\": true,\n \"type\": \"int\"\n \+ \ },\n {\n \"name\": \"c\",\n \"position\"\+ : 3,\n \"default\": \"NULL\",\n \"type\": \"varchar\"\+ ,\n \"comment\": \"column c\"\n },\n {\n \+ \ \"name\": \"e\",\n \"position\": 4,\n \"\+ nullable\": true,\n \"type\": \"int\"\n },\n \+ \ {\n \"name\": \"f\",\n \"position\": 5,\n \+ \ \"type\": \"varchar\",\n \"collation\": \"utf8mb4_polish_ci\"\+ \n },\n {\n \"name\": \"g\",\n \+ \ \"position\": 6,\n \"type\": \"varchar\",\n \"characterSet\"\+ : \"utf8mb4\"\n }\n ],\n \"indexes\": [\n \+ \ {\n \"name\": \"PRIMARY\",\n \"expressions\":\+ \ [\n \"a\"\n ],\n \"type\": \"BTREE\"\+ ,\n \"unique\": true,\n \"primary\": true,\n \+ \ \"visible\": true\n },\n {\n \"name\"\+ : \"b\",\n \"expressions\": [\n \"b\"\n \+ \ ],\n \"type\": \"BTREE\",\n \"unique\": true,\n\+ \ \"visible\": true\n }\n ]\n }\n \+ \ ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(- id int,- name varchar(255),- key idx_name(name)- );- create table t2 (- id int,- t1_name varchar(255),- constraint fk_t1_name foreign key (t1_name) references t1 (name)- );- alter table t2 drop foreign key fk_t1_name;+- statement: "CREATE TABLE t1(\n id int,\n name varchar(255),\n key idx_name(name)\n\+ );\ncreate table t2 (\n id int,\n t1_name varchar(255),\n constraint fk_t1_name\+ \ foreign key (t1_name) references t1 (name)\n);\nalter table t2 drop foreign\+ \ key fk_t1_name;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "id",- "position": 1,- "nullable": true,- "type": "int"- },- {- "name": "name",- "position": 2,- "nullable": true,- "type": "varchar"- }- ],- "indexes": [- {- "name": "idx_name",- "expressions": [- "name"- ],- "type": "BTREE",- "visible": true- }- ]- },- {- "name": "t2",- "columns": [- {- "name": "id",- "position": 1,- "nullable": true,- "type": "int"- },- {- "name": "t1_name",- "position": 2,- "nullable": true,- "type": "varchar"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"id\",\n \"position\": 1,\n \+ \ \"nullable\": true,\n \"type\": \"int\"\n },\n\+ \ {\n \"name\": \"name\",\n \"position\"\+ : 2,\n \"nullable\": true,\n \"type\": \"varchar\"\n\+ \ }\n ],\n \"indexes\": [\n {\n \+ \ \"name\": \"idx_name\",\n \"expressions\": [\n \+ \ \"name\"\n ],\n \"type\": \"BTREE\",\n \+ \ \"visible\": true\n }\n ]\n },\n {\n\+ \ \"name\": \"t2\",\n \"columns\": [\n {\n \+ \ \"name\": \"id\",\n \"position\": 1,\n \"nullable\"\+ : true,\n \"type\": \"int\"\n },\n {\n \+ \ \"name\": \"t1_name\",\n \"position\": 2,\n \+ \ \"nullable\": true,\n \"type\": \"varchar\"\n }\n\+ \ ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- create table all_types(- c1 tinyblob not null,- c2 blob not null,- c3 mediumblob not null,- c4 longblob not null,- c5 tinytext not null,- c6 text not null,- c7 mediumtext not null,- c8 longtext not null,- c9 json not null,- c10 serial not null,- c11 long varbinary not null,- c12 long varchar not null- );+- statement: "create table all_types(\n c1 tinyblob not null,\n c2 blob not null,\n\+ \ c3 mediumblob not null,\n c4 longblob not null,\n c5 tinytext not null,\n\+ \ c6 text not null,\n c7 mediumtext not null,\n c8 longtext not null,\n c9\+ \ json not null,\n c10 serial not null,\n c11 long varbinary not null,\n c12\+ \ long varchar not null \n);"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "all_types",- "columns": [- {- "name": "c1",- "position": 1,- "type": "tinyblob"- },- {- "name": "c2",- "position": 2,- "type": "blob"- },- {- "name": "c3",- "position": 3,- "type": "mediumblob"- },- {- "name": "c4",- "position": 4,- "type": "longblob"- },- {- "name": "c5",- "position": 5,- "type": "tinytext"- },- {- "name": "c6",- "position": 6,- "type": "text"- },- {- "name": "c7",- "position": 7,- "type": "mediumtext"- },- {- "name": "c8",- "position": 8,- "type": "longtext"- },- {- "name": "c9",- "position": 9,- "type": "json"- },- {- "name": "c10",- "position": 10,- "type": "serial"- },- {- "name": "c11",- "position": 11,- "type": "long"- },- {- "name": "c12",- "position": 12,- "type": "long"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"all_types\",\n \"columns\": [\n \+ \ {\n \"name\": \"c1\",\n \"position\": 1,\n\+ \ \"type\": \"tinyblob\"\n },\n {\n \+ \ \"name\": \"c2\",\n \"position\": 2,\n \"type\"\+ : \"blob\"\n },\n {\n \"name\": \"c3\",\n \+ \ \"position\": 3,\n \"type\": \"mediumblob\"\n \+ \ },\n {\n \"name\": \"c4\",\n \"position\"\+ : 4,\n \"type\": \"longblob\"\n },\n {\n \+ \ \"name\": \"c5\",\n \"position\": 5,\n \+ \ \"type\": \"tinytext\"\n },\n {\n \"name\"\+ : \"c6\",\n \"position\": 6,\n \"type\": \"text\"\n\+ \ },\n {\n \"name\": \"c7\",\n \+ \ \"position\": 7,\n \"type\": \"mediumtext\"\n },\n\+ \ {\n \"name\": \"c8\",\n \"position\": 8,\n\+ \ \"type\": \"longtext\"\n },\n {\n \+ \ \"name\": \"c9\",\n \"position\": 9,\n \"type\"\+ : \"json\"\n },\n {\n \"name\": \"c10\",\n\+ \ \"position\": 10,\n \"type\": \"serial\"\n \+ \ },\n {\n \"name\": \"c11\",\n \"position\"\+ : 11,\n \"type\": \"long\"\n },\n {\n \+ \ \"name\": \"c12\",\n \"position\": 12,\n \"\+ type\": \"long\"\n }\n ]\n }\n ]\n }\n ]\n\+ }"err: nulldiff --git a/backend/plugin/advisor/catalog/test/pg_walk_through.yaml b/backend/plugin/advisor/catalog/test/pg_walk_through.yamlindex c222b9090f..f619922b92 100644--- a/backend/plugin/advisor/catalog/test/pg_walk_through.yaml+++ b/backend/plugin/advisor/catalog/test/pg_walk_through.yaml@@ -1,639 +1,238 @@- statement: CREATE TABLE t(a int, b int);ignore_case_sensitive: false- want: |-- {- "name": "postgres",- "schemas": [- {- "name": "public",- "tables": [- {- "name": "t",- "columns": [- {- "name": "a",- "position": 1,- "nullable": true,- "type": "integer"- },- {- "name": "b",- "position": 2,- "nullable": true,- "type": "integer"- }- ]- },- {- "name": "test",- "columns": [- {- "name": "id",- "position": 1,- "type": "int"- },- {- "name": "name",- "position": 2,- "nullable": true,- "type": "varchar(20)"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"postgres\",\n \"schemas\": [\n {\n \"name\": \"\+ public\",\n \"tables\": [\n {\n \"name\": \"t\",\n \+ \ \"columns\": [\n {\n \"name\": \"a\",\n \+ \ \"position\": 1,\n \"nullable\": true,\n \"type\"\+ : \"integer\"\n },\n {\n \"name\": \"b\",\n\+ \ \"position\": 2,\n \"nullable\": true,\n \+ \ \"type\": \"integer\"\n }\n ]\n },\n {\n\+ \ \"name\": \"test\",\n \"columns\": [\n {\n \+ \ \"name\": \"id\",\n \"position\": 1,\n \"\+ type\": \"int\"\n },\n {\n \"name\": \"name\"\+ ,\n \"position\": 2,\n \"nullable\": true,\n \+ \ \"type\": \"varchar(20)\"\n }\n ]\n }\n \+ \ ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE public.t(a int, "B" int);+- statement: 'CREATE TABLE public.t(a int, "B" int);+CREATE INDEX ON t(a, "B");+CREATE UNIQUE INDEX ON t(a, "B");- DROP INDEX IF EXISTS t_a_B_idx_11111;++ DROP INDEX IF EXISTS t_a_B_idx_11111;'ignore_case_sensitive: false- want: |-- {- "name": "postgres",- "schemas": [- {- "name": "public",- "tables": [- {- "name": "t",- "columns": [- {- "name": "a",- "position": 1,- "nullable": true,- "type": "integer"- },- {- "name": "B",- "position": 2,- "nullable": true,- "type": "integer"- }- ],- "indexes": [- {- "name": "t_a_B_idx",- "expressions": [- "a",- "B"- ],- "type": "btree"- },- {- "name": "t_a_B_idx1",- "expressions": [- "a",- "B"- ],- "type": "btree",- "unique": true- }- ]- },- {- "name": "test",- "columns": [- {- "name": "id",- "position": 1,- "type": "int"- },- {- "name": "name",- "position": 2,- "nullable": true,- "type": "varchar(20)"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"postgres\",\n \"schemas\": [\n {\n \"name\": \"\+ public\",\n \"tables\": [\n {\n \"name\": \"t\",\n \+ \ \"columns\": [\n {\n \"name\": \"a\",\n \+ \ \"position\": 1,\n \"nullable\": true,\n \"type\"\+ : \"integer\"\n },\n {\n \"name\": \"B\",\n\+ \ \"position\": 2,\n \"nullable\": true,\n \+ \ \"type\": \"integer\"\n }\n ],\n \"indexes\"\+ : [\n {\n \"name\": \"t_a_B_idx\",\n \"expressions\"\+ : [\n \"a\",\n \"B\"\n ],\n \+ \ \"type\": \"btree\"\n },\n {\n \"name\"\+ : \"t_a_B_idx1\",\n \"expressions\": [\n \"a\",\n\+ \ \"B\"\n ],\n \"type\": \"btree\",\n\+ \ \"unique\": true\n }\n ]\n },\n \+ \ {\n \"name\": \"test\",\n \"columns\": [\n {\n\+ \ \"name\": \"id\",\n \"position\": 1,\n \+ \ \"type\": \"int\"\n },\n {\n \"name\":\+ \ \"name\",\n \"position\": 2,\n \"nullable\": true,\n\+ \ \"type\": \"varchar(20)\"\n }\n ]\n \+ \ }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE public.t(- a int primary key,- b int NOT NULL DEFAULT 1,- c int UNIQUE,- UNIQUE (a, b, c),- CONSTRAINT uk_a_b UNIQUE (a, b)- )+- statement: "CREATE TABLE public.t(\n a int primary key,\n b int NOT NULL DEFAULT\+ \ 1,\n c int UNIQUE,\n UNIQUE (a, b, c),\n CONSTRAINT uk_a_b UNIQUE (a, b)\n\+ )"ignore_case_sensitive: false- want: |-- {- "name": "postgres",- "schemas": [- {- "name": "public",- "tables": [- {- "name": "t",- "columns": [- {- "name": "a",- "position": 1,- "type": "integer"- },- {- "name": "b",- "position": 2,- "default": "1",- "type": "integer"- },- {- "name": "c",- "position": 3,- "nullable": true,- "type": "integer"- }- ],- "indexes": [- {- "name": "t_a_b_c_idx",- "expressions": [- "a",- "b",- "c"- ],- "type": "btree",- "unique": true- },- {- "name": "t_c_idx",- "expressions": [- "c"- ],- "type": "btree",- "unique": true- },- {- "name": "t_pkey",- "expressions": [- "a"- ],- "type": "btree",- "unique": true,- "primary": true- },- {- "name": "uk_a_b",- "expressions": [- "a",- "b"- ],- "type": "btree",- "unique": true- }- ]- },- {- "name": "test",- "columns": [- {- "name": "id",- "position": 1,- "type": "int"- },- {- "name": "name",- "position": 2,- "nullable": true,- "type": "varchar(20)"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"postgres\",\n \"schemas\": [\n {\n \"name\": \"\+ public\",\n \"tables\": [\n {\n \"name\": \"t\",\n \+ \ \"columns\": [\n {\n \"name\": \"a\",\n \+ \ \"position\": 1,\n \"type\": \"integer\"\n },\n\+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\+ \ \"default\": \"1\",\n \"type\": \"integer\"\n \+ \ },\n {\n \"name\": \"c\",\n \"position\"\+ : 3,\n \"nullable\": true,\n \"type\": \"integer\"\n\+ \ }\n ],\n \"indexes\": [\n {\n \+ \ \"name\": \"t_a_b_c_idx\",\n \"expressions\": [\n \+ \ \"a\",\n \"b\",\n \"c\"\n \+ \ ],\n \"type\": \"btree\",\n \"unique\": true\n \+ \ },\n {\n \"name\": \"t_c_idx\",\n \+ \ \"expressions\": [\n \"c\"\n ],\n \+ \ \"type\": \"btree\",\n \"unique\": true\n },\n \+ \ {\n \"name\": \"t_pkey\",\n \"expressions\"\+ : [\n \"a\"\n ],\n \"type\": \"btree\"\+ ,\n \"unique\": true,\n \"primary\": true\n \+ \ },\n {\n \"name\": \"uk_a_b\",\n \"\+ expressions\": [\n \"a\",\n \"b\"\n \+ \ ],\n \"type\": \"btree\",\n \"unique\": true\n \+ \ }\n ]\n },\n {\n \"name\": \"test\"\+ ,\n \"columns\": [\n {\n \"name\": \"id\",\n\+ \ \"position\": 1,\n \"type\": \"int\"\n \+ \ },\n {\n \"name\": \"name\",\n \"position\"\+ : 2,\n \"nullable\": true,\n \"type\": \"varchar(20)\"\+ \n }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE public.t(- a int primary key,- b int NOT NULL DEFAULT 1,- c int UNIQUE,- UNIQUE (a, b, c),- CONSTRAINT uk_a_b UNIQUE (a, b)- );- ALTER TABLE t rename to t1;- ALTER TABLE t1 rename column a to a1;- alter table t1 rename constraint uk_a_b to ukk_a_b;- alter table t1 add column d int;- alter table t1 drop column c;- alter table t1 alter column b set data type bigint;- alter table t1 alter column a1 set default 1;- alter table t1 alter column b drop default;- alter table t1 alter column d set not null;- alter table t1 add constraint uk_d unique (d);- alter table t1 add constraint ukk_d unique (d);- alter table t1 drop constraint ukk_d;+- statement: "CREATE TABLE public.t(\n a int primary key,\n b int NOT NULL DEFAULT\+ \ 1,\n c int UNIQUE,\n UNIQUE (a, b, c),\n CONSTRAINT uk_a_b UNIQUE (a, b)\n\+ );\nALTER TABLE t rename to t1;\nALTER TABLE t1 rename column a to a1;\nalter\+ \ table t1 rename constraint uk_a_b to ukk_a_b;\nalter table t1 add column d int;\n\+ alter table t1 drop column c;\nalter table t1 alter column b set data type bigint;\n\+ alter table t1 alter column a1 set default 1;\nalter table t1 alter column b drop\+ \ default;\nalter table t1 alter column d set not null;\nalter table t1 add constraint\+ \ uk_d unique (d);\nalter table t1 add constraint ukk_d unique (d);\nalter table\+ \ t1 drop constraint ukk_d;"ignore_case_sensitive: false- want: |-- {- "name": "postgres",- "schemas": [- {- "name": "public",- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a1",- "position": 1,- "default": "1",- "type": "integer"- },- {- "name": "b",- "position": 2,- "type": "bigint"- },- {- "name": "d",- "position": 4,- "type": "integer"- }- ],- "indexes": [- {- "name": "t_pkey",- "expressions": [- "a1"- ],- "type": "btree",- "unique": true,- "primary": true- },- {- "name": "uk_d",- "expressions": [- "d"- ],- "type": "btree",- "unique": true- },- {- "name": "ukk_a_b",- "expressions": [- "a1",- "b"- ],- "type": "btree",- "unique": true- }- ]- },- {- "name": "test",- "columns": [- {- "name": "id",- "position": 1,- "type": "int"- },- {- "name": "name",- "position": 2,- "nullable": true,- "type": "varchar(20)"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"postgres\",\n \"schemas\": [\n {\n \"name\": \"\+ public\",\n \"tables\": [\n {\n \"name\": \"t1\",\n \+ \ \"columns\": [\n {\n \"name\": \"a1\",\n \+ \ \"position\": 1,\n \"default\": \"1\",\n \"\+ type\": \"integer\"\n },\n {\n \"name\": \"\+ b\",\n \"position\": 2,\n \"type\": \"bigint\"\n \+ \ },\n {\n \"name\": \"d\",\n \"\+ position\": 4,\n \"type\": \"integer\"\n }\n \+ \ ],\n \"indexes\": [\n {\n \"name\": \"t_pkey\"\+ ,\n \"expressions\": [\n \"a1\"\n ],\n\+ \ \"type\": \"btree\",\n \"unique\": true,\n \+ \ \"primary\": true\n },\n {\n \"name\"\+ : \"uk_d\",\n \"expressions\": [\n \"d\"\n \+ \ ],\n \"type\": \"btree\",\n \"unique\": true\n\+ \ },\n {\n \"name\": \"ukk_a_b\",\n \+ \ \"expressions\": [\n \"a1\",\n \"b\"\n \+ \ ],\n \"type\": \"btree\",\n \"unique\"\+ : true\n }\n ]\n },\n {\n \"name\"\+ : \"test\",\n \"columns\": [\n {\n \"name\":\+ \ \"id\",\n \"position\": 1,\n \"type\": \"int\"\n \+ \ },\n {\n \"name\": \"name\",\n \+ \ \"position\": 2,\n \"nullable\": true,\n \"type\"\+ : \"varchar(20)\"\n }\n ]\n }\n ]\n }\n ]\n\+ }"err: null-- statement: |-- CREATE TABLE public.t(- a int primary key,- b int NOT NULL DEFAULT 1,- c int UNIQUE,- UNIQUE (a, b, c),- CONSTRAINT uk_a_b UNIQUE (a, b)- );- alter index uk_a_b rename to ukk_a_b;+- statement: "CREATE TABLE public.t(\n a int primary key,\n b int NOT NULL DEFAULT\+ \ 1,\n c int UNIQUE,\n UNIQUE (a, b, c),\n CONSTRAINT uk_a_b UNIQUE (a, b)\n\+ );\nalter index uk_a_b rename to ukk_a_b;"ignore_case_sensitive: false- want: |-- {- "name": "postgres",- "schemas": [- {- "name": "public",- "tables": [- {- "name": "t",- "columns": [- {- "name": "a",- "position": 1,- "type": "integer"- },- {- "name": "b",- "position": 2,- "default": "1",- "type": "integer"- },- {- "name": "c",- "position": 3,- "nullable": true,- "type": "integer"- }- ],- "indexes": [- {- "name": "t_a_b_c_idx",- "expressions": [- "a",- "b",- "c"- ],- "type": "btree",- "unique": true- },- {- "name": "t_c_idx",- "expressions": [- "c"- ],- "type": "btree",- "unique": true- },- {- "name": "t_pkey",- "expressions": [- "a"- ],- "type": "btree",- "unique": true,- "primary": true- },- {- "name": "ukk_a_b",- "expressions": [- "a",- "b"- ],- "type": "btree",- "unique": true- }- ]- },- {- "name": "test",- "columns": [- {- "name": "id",- "position": 1,- "type": "int"- },- {- "name": "name",- "position": 2,- "nullable": true,- "type": "varchar(20)"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"postgres\",\n \"schemas\": [\n {\n \"name\": \"\+ public\",\n \"tables\": [\n {\n \"name\": \"t\",\n \+ \ \"columns\": [\n {\n \"name\": \"a\",\n \+ \ \"position\": 1,\n \"type\": \"integer\"\n },\n\+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\+ \ \"default\": \"1\",\n \"type\": \"integer\"\n \+ \ },\n {\n \"name\": \"c\",\n \"position\"\+ : 3,\n \"nullable\": true,\n \"type\": \"integer\"\n\+ \ }\n ],\n \"indexes\": [\n {\n \+ \ \"name\": \"t_a_b_c_idx\",\n \"expressions\": [\n \+ \ \"a\",\n \"b\",\n \"c\"\n \+ \ ],\n \"type\": \"btree\",\n \"unique\": true\n \+ \ },\n {\n \"name\": \"t_c_idx\",\n \+ \ \"expressions\": [\n \"c\"\n ],\n \+ \ \"type\": \"btree\",\n \"unique\": true\n },\n \+ \ {\n \"name\": \"t_pkey\",\n \"expressions\"\+ : [\n \"a\"\n ],\n \"type\": \"btree\"\+ ,\n \"unique\": true,\n \"primary\": true\n \+ \ },\n {\n \"name\": \"ukk_a_b\",\n \"\+ expressions\": [\n \"a\",\n \"b\"\n \+ \ ],\n \"type\": \"btree\",\n \"unique\": true\n \+ \ }\n ]\n },\n {\n \"name\": \"test\"\+ ,\n \"columns\": [\n {\n \"name\": \"id\",\n\+ \ \"position\": 1,\n \"type\": \"int\"\n \+ \ },\n {\n \"name\": \"name\",\n \"position\"\+ : 2,\n \"nullable\": true,\n \"type\": \"varchar(20)\"\+ \n }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE public.t(- a int primary key,- b int NOT NULL DEFAULT 1,- c int UNIQUE,- UNIQUE (a, b, c),- CONSTRAINT uk_a_b UNIQUE (a, b)- );- drop index uk_a_b;+- statement: "CREATE TABLE public.t(\n a int primary key,\n b int NOT NULL DEFAULT\+ \ 1,\n c int UNIQUE,\n UNIQUE (a, b, c),\n CONSTRAINT uk_a_b UNIQUE (a, b)\n\+ );\ndrop index uk_a_b;"ignore_case_sensitive: false- want: |-- {- "name": "postgres",- "schemas": [- {- "name": "public",- "tables": [- {- "name": "t",- "columns": [- {- "name": "a",- "position": 1,- "type": "integer"- },- {- "name": "b",- "position": 2,- "default": "1",- "type": "integer"- },- {- "name": "c",- "position": 3,- "nullable": true,- "type": "integer"- }- ],- "indexes": [- {- "name": "t_a_b_c_idx",- "expressions": [- "a",- "b",- "c"- ],- "type": "btree",- "unique": true- },- {- "name": "t_c_idx",- "expressions": [- "c"- ],- "type": "btree",- "unique": true- },- {- "name": "t_pkey",- "expressions": [- "a"- ],- "type": "btree",- "unique": true,- "primary": true- }- ]- },- {- "name": "test",- "columns": [- {- "name": "id",- "position": 1,- "type": "int"- },- {- "name": "name",- "position": 2,- "nullable": true,- "type": "varchar(20)"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"postgres\",\n \"schemas\": [\n {\n \"name\": \"\+ public\",\n \"tables\": [\n {\n \"name\": \"t\",\n \+ \ \"columns\": [\n {\n \"name\": \"a\",\n \+ \ \"position\": 1,\n \"type\": \"integer\"\n },\n\+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\+ \ \"default\": \"1\",\n \"type\": \"integer\"\n \+ \ },\n {\n \"name\": \"c\",\n \"position\"\+ : 3,\n \"nullable\": true,\n \"type\": \"integer\"\n\+ \ }\n ],\n \"indexes\": [\n {\n \+ \ \"name\": \"t_a_b_c_idx\",\n \"expressions\": [\n \+ \ \"a\",\n \"b\",\n \"c\"\n \+ \ ],\n \"type\": \"btree\",\n \"unique\": true\n \+ \ },\n {\n \"name\": \"t_c_idx\",\n \+ \ \"expressions\": [\n \"c\"\n ],\n \+ \ \"type\": \"btree\",\n \"unique\": true\n },\n \+ \ {\n \"name\": \"t_pkey\",\n \"expressions\"\+ : [\n \"a\"\n ],\n \"type\": \"btree\"\+ ,\n \"unique\": true,\n \"primary\": true\n \+ \ }\n ]\n },\n {\n \"name\": \"test\",\n \+ \ \"columns\": [\n {\n \"name\": \"id\",\n \+ \ \"position\": 1,\n \"type\": \"int\"\n },\n\+ \ {\n \"name\": \"name\",\n \"position\"\+ : 2,\n \"nullable\": true,\n \"type\": \"varchar(20)\"\+ \n }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE public.t(- a int primary key,- b int NOT NULL DEFAULT 1,- c int UNIQUE,- UNIQUE (a, b, c),- CONSTRAINT uk_a_b UNIQUE (a, b)- );- drop table t;+- statement: "CREATE TABLE public.t(\n a int primary key,\n b int NOT NULL DEFAULT\+ \ 1,\n c int UNIQUE,\n UNIQUE (a, b, c),\n CONSTRAINT uk_a_b UNIQUE (a, b)\n\+ );\ndrop table t;"ignore_case_sensitive: false- want: |-- {- "name": "postgres",- "schemas": [- {- "name": "public",- "tables": [- {- "name": "test",- "columns": [- {- "name": "id",- "position": 1,- "type": "int"- },- {- "name": "name",- "position": 2,- "nullable": true,- "type": "varchar(20)"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"postgres\",\n \"schemas\": [\n {\n \"name\": \"\+ public\",\n \"tables\": [\n {\n \"name\": \"test\",\n \+ \ \"columns\": [\n {\n \"name\": \"id\",\n \+ \ \"position\": 1,\n \"type\": \"int\"\n },\n\+ \ {\n \"name\": \"name\",\n \"position\"\+ : 2,\n \"nullable\": true,\n \"type\": \"varchar(20)\"\+ \n }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE public.t(- a int primary key,- b int NOT NULL DEFAULT 1,- c int UNIQUE,- UNIQUE (a, b, c),- CONSTRAINT uk_a_b UNIQUE (a, b)- );- drop schema public;+- statement: "CREATE TABLE public.t(\n a int primary key,\n b int NOT NULL DEFAULT\+ \ 1,\n c int UNIQUE,\n UNIQUE (a, b, c),\n CONSTRAINT uk_a_b UNIQUE (a, b)\n\+ );\ndrop schema public;"ignore_case_sensitive: false- want: |-- {- "name": "postgres"- }+ want: "{\n \"name\": \"postgres\"\n}"err: null- statement: ALTER TABLE test DROP COLUMN id;ignore_case_sensitive: false- want: ""+ want: ''err:- type: 408- content: 'Cannot drop column "id" in table "public"."test", it''s referenced by view: "public"."v1"'+ code: 421+ content: 'Cannot drop column "id" in table "public"."test", it''s referenced by+ view: "public"."v1"'line: 1- payload:- - '"public"."v1"'- statement: ALTER TABLE test ALTER COLUMN id TYPE varchar(20);ignore_case_sensitive: false- want: ""+ want: ''err:- type: 408- content: 'Cannot alter type of column "id" in table "public"."test", it''s referenced by view: "public"."v1"'+ code: 421+ content: 'Cannot alter type of column "id" in table "public"."test", it''s referenced+ by view: "public"."v1"'line: 1- payload:- - '"public"."v1"'- statement: DROP TABLE test;ignore_case_sensitive: false- want: ""+ want: ''err:- type: 304+ code: 609content: 'Cannot drop table "public"."test", it''s referenced by view: "public"."v1"'line: 1- payload:- - '"public"."v1"'-- statement: |-- DROP VIEW v1;- ALTER TABLE test DROP COLUMN id;+- statement: 'DROP VIEW v1;++ ALTER TABLE test DROP COLUMN id;'ignore_case_sensitive: false- want: |-- {- "name": "postgres",- "schemas": [- {- "name": "public",- "tables": [- {- "name": "test",- "columns": [- {- "name": "name",- "position": 2,- "nullable": true,- "type": "varchar(20)"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"postgres\",\n \"schemas\": [\n {\n \"name\": \"\+ public\",\n \"tables\": [\n {\n \"name\": \"test\",\n \+ \ \"columns\": [\n {\n \"name\": \"name\",\n \+ \ \"position\": 2,\n \"nullable\": true,\n \+ \ \"type\": \"varchar(20)\"\n }\n ]\n }\n ]\n\+ \ }\n ]\n}"err: null-- statement: |-- create view v1 as select * from t;+- statement: 'create view v1 as select * from t;+alter view v1 rename to this_is_view_del;- drop view this_is_view_del;++ drop view this_is_view_del;'ignore_case_sensitive: false- want: |-- {- "name": "postgres",- "schemas": [- {- "name": "public",- "tables": [- {- "name": "test",- "columns": [- {- "name": "id",- "position": 1,- "type": "int"- },- {- "name": "name",- "position": 2,- "nullable": true,- "type": "varchar(20)"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"postgres\",\n \"schemas\": [\n {\n \"name\": \"\+ public\",\n \"tables\": [\n {\n \"name\": \"test\",\n \+ \ \"columns\": [\n {\n \"name\": \"id\",\n \+ \ \"position\": 1,\n \"type\": \"int\"\n },\n\+ \ {\n \"name\": \"name\",\n \"position\"\+ : 2,\n \"nullable\": true,\n \"type\": \"varchar(20)\"\+ \n }\n ]\n }\n ]\n }\n ]\n}"err: nulldiff --git a/backend/plugin/advisor/catalog/test/tidb_walk_through.yaml b/backend/plugin/advisor/catalog/test/tidb_walk_through.yamlindex 691a04403f..53d2662a34 100644--- a/backend/plugin/advisor/catalog/test/tidb_walk_through.yaml+++ b/backend/plugin/advisor/catalog/test/tidb_walk_through.yaml@@ -1,843 +1,386 @@- statement: CREATE TABLE t(a date default '');ignore_case_sensitive: false- want: ""+ want: ''err:- type: 407+ code: 423content: '[types:1292]Incorrect datetime value: '''''line: 1- payload: null-- statement: |-- CREATE TABLE t(a TEXT);- ALTER TABLE T ALTER COLUMN a SET DEFAULT '1';+- statement: 'CREATE TABLE t(a TEXT);++ ALTER TABLE T ALTER COLUMN a SET DEFAULT ''1'';'ignore_case_sensitive: true- want: ""+ want: ''err:- type: 407+ code: 423content: BLOB, TEXT, GEOMETRY or JSON column `a` can't have a default valueline: 2- payload: null- statement: ' CREATE TABLE t(a TEXT DEFAULT ''1'')'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 407+ code: 423content: BLOB, TEXT, GEOMETRY or JSON column `a` can't have a default valueline: 1- payload: null-- statement: |-- CREATE TABLE t(a INT NOT NULL);- ALTER TABLE t ALTER COLUMN a SET DEFAULT NULL;+- statement: 'CREATE TABLE t(a INT NOT NULL);++ ALTER TABLE t ALTER COLUMN a SET DEFAULT NULL;'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 406+ code: 428content: Invalid default value for column `a`line: 2- payload: null- statement: ' CREATE TABLE t(a INT NOT NULL DEFAULT NULL)'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 406+ code: 428content: Invalid default value for column `a`line: 1- payload: null- statement: ' CREATE TABLE t(a int ON UPDATE NOW())'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 405+ code: 427content: Column `a` use ON UPDATE but is not DATETIME or TIMESTAMPline: 1- payload: null- statement: ' CREATE TABLE t(a int auto_increment, b int auto_increment);'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 404+ code: 426content: There can be only one auto column for table `t`line: 1- payload: null- statement: ' CREATE TABLE t as select * from t1;'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 303- content: Disallow the CREATE TABLE AS statement but "CREATE TABLE t as select * from t1;" uses+ code: 205+ content: Disallow the CREATE TABLE AS statement but "CREATE TABLE t as select+ * from t1;" usesline: 1- payload: null-- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tCREATE INDEX idx_c on t(c);\n\t\t\t"+- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tCREATE INDEX idx_c\+ \ on t(c);\n\t\t\t"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 402+ code: 405content: Column `c` does not exist in table `t`line: 3- payload: null-- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t MODIFY COLUMN c int;\n\t\t\t"+- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t MODIFY\+ \ COLUMN c int;\n\t\t\t"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 402+ code: 405content: Column `c` does not exist in table `t`line: 3- payload: null-- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t CHANGE COLUMN c aa int;\n\t\t\t"+- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t CHANGE\+ \ COLUMN c aa int;\n\t\t\t"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 402+ code: 405content: Column `c` does not exist in table `t`line: 3- payload: null-- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t DROP COLUMN c;\n\t\t\t"+- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t DROP\+ \ COLUMN c;\n\t\t\t"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 402+ code: 405content: Column `c` does not exist in table `t`line: 3- payload: null-- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t RENAME COLUMN c TO cc;\n\t\t\t"+- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t RENAME\+ \ COLUMN c TO cc;\n\t\t\t"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 402+ code: 405content: Column `c` does not exist in table `t`line: 3- payload: null-- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t RENAME COLUMN c TO cc;\n\t\t\t"+- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t RENAME\+ \ COLUMN c TO cc;\n\t\t\t"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 402+ code: 405content: Column `c` does not exist in table `t`line: 3- payload: null-- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t ALTER COLUMN c DROP DEFAULT;\n\t\t\t"+- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t ALTER\+ \ COLUMN c DROP DEFAULT;\n\t\t\t"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 402+ code: 405content: Column `c` does not exist in table `t`line: 3- payload: null-- statement: |-- ALTER DATABASE CHARACTER SET = utf8mb4;- ALTER DATABASE test COLLATE utf8mb4_polish_ci;+- statement: 'ALTER DATABASE CHARACTER SET = utf8mb4;++ ALTER DATABASE test COLLATE utf8mb4_polish_ci;'ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {}- ],- "characterSet": "utf8mb4",- "collation": "utf8mb4_polish_ci"- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {}\n ],\n \"characterSet\"\+ : \"utf8mb4\",\n \"collation\": \"utf8mb4_polish_ci\"\n}"err: null-- statement: |-- CREATE TABLE t(- a int PRIMARY KEY DEFAULT 1,- b varchar(200) CHARACTER SET utf8mb4 NOT NULL UNIQUE,- c int auto_increment NULL COMMENT 'This is a comment' DEFAULT NULL,- d varchar(10) COLLATE utf8mb4_polish_ci,- KEY idx_a (a),- INDEX (b, a),- UNIQUE (b, c, d),- FULLTEXT (b, d) WITH PARSER ngram INVISIBLE- );- CREATE TABLE t_copy like t;+- statement: "CREATE TABLE t(\n a int PRIMARY KEY DEFAULT 1,\n b varchar(200) CHARACTER\+ \ SET utf8mb4 NOT NULL UNIQUE,\n c int auto_increment NULL COMMENT 'This is a\+ \ comment' DEFAULT NULL,\n d varchar(10) COLLATE utf8mb4_polish_ci,\n KEY idx_a\+ \ (a),\n INDEX (b, a),\n UNIQUE (b, c, d),\n FULLTEXT (b, d) WITH PARSER ngram\+ \ INVISIBLE\n);\nCREATE TABLE t_copy like t;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t",- "columns": [- {- "name": "a",- "position": 1,- "default": "1",- "type": "int(11)"- },- {- "name": "b",- "position": 2,- "type": "varchar(200)",- "characterSet": "utf8mb4"- },- {- "name": "c",- "position": 3,- "nullable": true,- "type": "int(11)",- "comment": "This is a comment"- },- {- "name": "d",- "position": 4,- "nullable": true,- "type": "varchar(10)",- "collation": "utf8mb4_polish_ci"- }- ],- "indexes": [- {- "name": "PRIMARY",- "expressions": [- "a"- ],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true- },- {- "name": "b",- "expressions": [- "b"- ],- "type": "BTREE",- "unique": true,- "visible": true- },- {- "name": "b_2",- "expressions": [- "b",- "a"- ],- "type": "BTREE",- "visible": true- },- {- "name": "b_3",- "expressions": [- "b",- "c",- "d"- ],- "type": "BTREE",- "unique": true,- "visible": true- },- {- "name": "b_4",- "expressions": [- "b",- "d"- ],- "type": "FULLTEXT"- },- {- "name": "idx_a",- "expressions": [- "a"- ],- "type": "BTREE",- "visible": true- }- ]- },- {- "name": "t_copy",- "columns": [- {- "name": "a",- "position": 1,- "default": "1",- "type": "int(11)"- },- {- "name": "b",- "position": 2,- "type": "varchar(200)",- "characterSet": "utf8mb4"- },- {- "name": "c",- "position": 3,- "nullable": true,- "type": "int(11)",- "comment": "This is a comment"- },- {- "name": "d",- "position": 4,- "nullable": true,- "type": "varchar(10)",- "collation": "utf8mb4_polish_ci"- }- ],- "indexes": [- {- "name": "PRIMARY",- "expressions": [- "a"- ],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true- },- {- "name": "b",- "expressions": [- "b"- ],- "type": "BTREE",- "unique": true,- "visible": true- },- {- "name": "b_2",- "expressions": [- "b",- "a"- ],- "type": "BTREE",- "visible": true- },- {- "name": "b_3",- "expressions": [- "b",- "c",- "d"- ],- "type": "BTREE",- "unique": true,- "visible": true- },- {- "name": "b_4",- "expressions": [- "b",- "d"- ],- "type": "FULLTEXT"- },- {- "name": "idx_a",- "expressions": [- "a"- ],- "type": "BTREE",- "visible": true- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"default\": \"1\",\n \"type\": \"int(11)\"\n },\n\+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\+ \ \"type\": \"varchar(200)\",\n \"characterSet\": \"\+ utf8mb4\"\n },\n {\n \"name\": \"c\",\n \+ \ \"position\": 3,\n \"nullable\": true,\n \+ \ \"type\": \"int(11)\",\n \"comment\": \"This is a comment\"\n\+ \ },\n {\n \"name\": \"d\",\n \+ \ \"position\": 4,\n \"nullable\": true,\n \"type\"\+ : \"varchar(10)\",\n \"collation\": \"utf8mb4_polish_ci\"\n \+ \ }\n ],\n \"indexes\": [\n {\n \+ \ \"name\": \"PRIMARY\",\n \"expressions\": [\n \+ \ \"a\"\n ],\n \"type\": \"BTREE\",\n \"\+ unique\": true,\n \"primary\": true,\n \"visible\":\+ \ true\n },\n {\n \"name\": \"b\",\n \+ \ \"expressions\": [\n \"b\"\n ],\n \+ \ \"type\": \"BTREE\",\n \"unique\": true,\n \"\+ visible\": true\n },\n {\n \"name\": \"b_2\"\+ ,\n \"expressions\": [\n \"b\",\n \"\+ a\"\n ],\n \"type\": \"BTREE\",\n \"visible\"\+ : true\n },\n {\n \"name\": \"b_3\",\n \+ \ \"expressions\": [\n \"b\",\n \"c\",\n\+ \ \"d\"\n ],\n \"type\": \"BTREE\",\n\+ \ \"unique\": true,\n \"visible\": true\n \+ \ },\n {\n \"name\": \"b_4\",\n \"expressions\"\+ : [\n \"b\",\n \"d\"\n ],\n \+ \ \"type\": \"FULLTEXT\"\n },\n {\n \"\+ name\": \"idx_a\",\n \"expressions\": [\n \"a\"\n\+ \ ],\n \"type\": \"BTREE\",\n \"visible\"\+ : true\n }\n ]\n },\n {\n \"name\"\+ : \"t_copy\",\n \"columns\": [\n {\n \"name\"\+ : \"a\",\n \"position\": 1,\n \"default\": \"1\",\n\+ \ \"type\": \"int(11)\"\n },\n {\n \+ \ \"name\": \"b\",\n \"position\": 2,\n \"type\"\+ : \"varchar(200)\",\n \"characterSet\": \"utf8mb4\"\n \+ \ },\n {\n \"name\": \"c\",\n \"position\"\+ : 3,\n \"nullable\": true,\n \"type\": \"int(11)\",\n\+ \ \"comment\": \"This is a comment\"\n },\n \+ \ {\n \"name\": \"d\",\n \"position\": 4,\n \+ \ \"nullable\": true,\n \"type\": \"varchar(10)\",\n \+ \ \"collation\": \"utf8mb4_polish_ci\"\n }\n ],\n \+ \ \"indexes\": [\n {\n \"name\": \"PRIMARY\",\n\+ \ \"expressions\": [\n \"a\"\n ],\n \+ \ \"type\": \"BTREE\",\n \"unique\": true,\n \+ \ \"primary\": true,\n \"visible\": true\n },\n \+ \ {\n \"name\": \"b\",\n \"expressions\":\+ \ [\n \"b\"\n ],\n \"type\": \"BTREE\"\+ ,\n \"unique\": true,\n \"visible\": true\n \+ \ },\n {\n \"name\": \"b_2\",\n \"expressions\"\+ : [\n \"b\",\n \"a\"\n ],\n \+ \ \"type\": \"BTREE\",\n \"visible\": true\n },\n\+ \ {\n \"name\": \"b_3\",\n \"expressions\"\+ : [\n \"b\",\n \"c\",\n \"d\"\n \+ \ ],\n \"type\": \"BTREE\",\n \"unique\"\+ : true,\n \"visible\": true\n },\n {\n \+ \ \"name\": \"b_4\",\n \"expressions\": [\n \+ \ \"b\",\n \"d\"\n ],\n \"type\":\+ \ \"FULLTEXT\"\n },\n {\n \"name\": \"idx_a\"\+ ,\n \"expressions\": [\n \"a\"\n ],\n\+ \ \"type\": \"BTREE\",\n \"visible\": true\n \+ \ }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t(- a int PRIMARY KEY DEFAULT 1,- b varchar(200) CHARACTER SET utf8mb4 NOT NULL UNIQUE,- c int auto_increment NULL COMMENT 'This is a comment',- d varchar(10) COLLATE utf8mb4_polish_ci,- KEY idx_a (a),- INDEX (b, a),- UNIQUE (b, c, d),- FULLTEXT (b, d) WITH PARSER ngram INVISIBLE- )+- statement: "CREATE TABLE t(\n a int PRIMARY KEY DEFAULT 1,\n b varchar(200) CHARACTER\+ \ SET utf8mb4 NOT NULL UNIQUE,\n c int auto_increment NULL COMMENT 'This is a\+ \ comment',\n d varchar(10) COLLATE utf8mb4_polish_ci,\n KEY idx_a (a),\n INDEX\+ \ (b, a),\n UNIQUE (b, c, d),\n FULLTEXT (b, d) WITH PARSER ngram INVISIBLE\n\+ )"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t",- "columns": [- {- "name": "a",- "position": 1,- "default": "1",- "type": "int(11)"- },- {- "name": "b",- "position": 2,- "type": "varchar(200)",- "characterSet": "utf8mb4"- },- {- "name": "c",- "position": 3,- "nullable": true,- "type": "int(11)",- "comment": "This is a comment"- },- {- "name": "d",- "position": 4,- "nullable": true,- "type": "varchar(10)",- "collation": "utf8mb4_polish_ci"- }- ],- "indexes": [- {- "name": "PRIMARY",- "expressions": [- "a"- ],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true- },- {- "name": "b",- "expressions": [- "b"- ],- "type": "BTREE",- "unique": true,- "visible": true- },- {- "name": "b_2",- "expressions": [- "b",- "a"- ],- "type": "BTREE",- "visible": true- },- {- "name": "b_3",- "expressions": [- "b",- "c",- "d"- ],- "type": "BTREE",- "unique": true,- "visible": true- },- {- "name": "b_4",- "expressions": [- "b",- "d"- ],- "type": "FULLTEXT"- },- {- "name": "idx_a",- "expressions": [- "a"- ],- "type": "BTREE",- "visible": true- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"default\": \"1\",\n \"type\": \"int(11)\"\n },\n\+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\+ \ \"type\": \"varchar(200)\",\n \"characterSet\": \"\+ utf8mb4\"\n },\n {\n \"name\": \"c\",\n \+ \ \"position\": 3,\n \"nullable\": true,\n \+ \ \"type\": \"int(11)\",\n \"comment\": \"This is a comment\"\n\+ \ },\n {\n \"name\": \"d\",\n \+ \ \"position\": 4,\n \"nullable\": true,\n \"type\"\+ : \"varchar(10)\",\n \"collation\": \"utf8mb4_polish_ci\"\n \+ \ }\n ],\n \"indexes\": [\n {\n \+ \ \"name\": \"PRIMARY\",\n \"expressions\": [\n \+ \ \"a\"\n ],\n \"type\": \"BTREE\",\n \"\+ unique\": true,\n \"primary\": true,\n \"visible\":\+ \ true\n },\n {\n \"name\": \"b\",\n \+ \ \"expressions\": [\n \"b\"\n ],\n \+ \ \"type\": \"BTREE\",\n \"unique\": true,\n \"\+ visible\": true\n },\n {\n \"name\": \"b_2\"\+ ,\n \"expressions\": [\n \"b\",\n \"\+ a\"\n ],\n \"type\": \"BTREE\",\n \"visible\"\+ : true\n },\n {\n \"name\": \"b_3\",\n \+ \ \"expressions\": [\n \"b\",\n \"c\",\n\+ \ \"d\"\n ],\n \"type\": \"BTREE\",\n\+ \ \"unique\": true,\n \"visible\": true\n \+ \ },\n {\n \"name\": \"b_4\",\n \"expressions\"\+ : [\n \"b\",\n \"d\"\n ],\n \+ \ \"type\": \"FULLTEXT\"\n },\n {\n \"\+ name\": \"idx_a\",\n \"expressions\": [\n \"a\"\n\+ \ ],\n \"type\": \"BTREE\",\n \"visible\"\+ : true\n }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t(- a int,- b int,- PRIMARY KEY (a, b)- )+- statement: "CREATE TABLE t(\n a int,\n b int,\n PRIMARY KEY (a, b)\n)"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t",- "columns": [- {- "name": "a",- "position": 1,- "type": "int(11)"- },- {- "name": "b",- "position": 2,- "type": "int(11)"- }- ],- "indexes": [- {- "name": "PRIMARY",- "expressions": [- "a",- "b"- ],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"type\": \"int(11)\"\n },\n {\n \"\+ name\": \"b\",\n \"position\": 2,\n \"type\": \"int(11)\"\+ \n }\n ],\n \"indexes\": [\n {\n \+ \ \"name\": \"PRIMARY\",\n \"expressions\": [\n \+ \ \"a\",\n \"b\"\n ],\n \"type\"\+ : \"BTREE\",\n \"unique\": true,\n \"primary\": true,\n\+ \ \"visible\": true\n }\n ]\n }\n \+ \ ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t1(a int, b int, c int);+- statement: 'CREATE TABLE t1(a int, b int, c int);+CREATE TABLE t2(a int);- DROP TABLE t1, t2++ DROP TABLE t1, t2'ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {}- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {}\n ]\n}"err: null- statement: ' DROP TABLE t1, t2'ignore_case_sensitive: false- want: ""+ want: ''err:- type: 302+ code: 604content: Table `t1` does not existline: 1- payload: null-- statement: |-- CREATE TABLE t(a int);- RENAME TABLE t to other_db.t1+- statement: 'CREATE TABLE t(a int);++ RENAME TABLE t to other_db.t1'ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {}- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {}\n ]\n}"err: null-- statement: |-- CREATE TABLE t(a int);- RENAME TABLE t to test.t1+- statement: 'CREATE TABLE t(a int);++ RENAME TABLE t to test.t1'ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "nullable": true,- "type": "int(11)"- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t1\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"nullable\": true,\n \"type\": \"int(11)\"\n \+ \ }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- -- this is comment- DROP DATABASE test;- CREATE TABLE t(a int);+- statement: "-- this is comment\n DROP DATABASE test;\n CREATE TABLE\+ \ t(a int);"ignore_case_sensitive: false- want: ""+ want: ''err:- type: 202+ code: 703content: Database `test` is deletedline: 3- payload: null-- statement: |-- CREATE TABLE t(- a int PRIMARY KEY DEFAULT 1,- b varchar(200) CHARACTER SET utf8mb4 NOT NULL UNIQUE,- c int auto_increment NULL COMMENT 'This is a comment',- d varchar(10) COLLATE utf8mb4_polish_ci,- e int,- KEY idx_a (a),- INDEX (b, a),- UNIQUE (b, c, d),- FULLTEXT (b, d) WITH PARSER ngram INVISIBLE- );- ALTER TABLE t COLLATE utf8mb4_0900_ai_ci, ENGINE = INNODB, COMMENT 'This is a table comment';- ALTER TABLE t ADD COLUMN a1 int AFTER a;- ALTER TABLE t ADD INDEX idx_a_b (a, b);- ALTER TABLE t DROP COLUMN c;- ALTER TABLE t DROP PRIMARY KEY;- ALTER TABLE t DROP INDEX b_2;- ALTER TABLE t MODIFY COLUMN b varchar(20) FIRST;- ALTER TABLE t CHANGE COLUMN d d_copy varchar(10) COLLATE utf8mb4_polish_ci;- ALTER TABLE t RENAME COLUMN a to a_copy;- ALTER TABLE t RENAME TO t_copy;- ALTER TABLE t_copy ALTER COLUMN a_copy DROP DEFAULT;- ALTER TABLE t_copy RENAME INDEX b TO idx_b;- ALTER TABLE t_copy ALTER INDEX b_3 INVISIBLE;+- statement: "CREATE TABLE t(\n a int PRIMARY KEY DEFAULT 1,\n b varchar(200) CHARACTER\+ \ SET utf8mb4 NOT NULL UNIQUE,\n c int auto_increment NULL COMMENT 'This is a\+ \ comment',\n d varchar(10) COLLATE utf8mb4_polish_ci,\n e int,\n KEY idx_a\+ \ (a),\n INDEX (b, a),\n UNIQUE (b, c, d),\n FULLTEXT (b, d) WITH PARSER ngram\+ \ INVISIBLE\n);\nALTER TABLE t COLLATE utf8mb4_0900_ai_ci, ENGINE = INNODB, COMMENT\+ \ 'This is a table comment';\nALTER TABLE t ADD COLUMN a1 int AFTER a;\nALTER\+ \ TABLE t ADD INDEX idx_a_b (a, b);\nALTER TABLE t DROP COLUMN c;\nALTER TABLE\+ \ t DROP PRIMARY KEY;\nALTER TABLE t DROP INDEX b_2;\nALTER TABLE t MODIFY COLUMN\+ \ b varchar(20) FIRST;\nALTER TABLE t CHANGE COLUMN d d_copy varchar(10) COLLATE\+ \ utf8mb4_polish_ci;\nALTER TABLE t RENAME COLUMN a to a_copy;\nALTER TABLE t\+ \ RENAME TO t_copy;\nALTER TABLE t_copy ALTER COLUMN a_copy DROP DEFAULT;\nALTER\+ \ TABLE t_copy RENAME INDEX b TO idx_b;\nALTER TABLE t_copy ALTER INDEX b_3 INVISIBLE;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t_copy",- "columns": [- {- "name": "b",- "position": 1,- "nullable": true,- "type": "varchar(20)"- },- {- "name": "a_copy",- "position": 2,- "type": "int(11)"- },- {- "name": "a1",- "position": 3,- "nullable": true,- "type": "int(11)"- },- {- "name": "d_copy",- "position": 4,- "nullable": true,- "type": "varchar(10)",- "collation": "utf8mb4_polish_ci"- },- {- "name": "e",- "position": 5,- "nullable": true,- "type": "int(11)"- }- ],- "indexes": [- {- "name": "b_3",- "expressions": [- "b",- "d_copy"- ],- "type": "BTREE",- "unique": true- },- {- "name": "b_4",- "expressions": [- "b",- "d_copy"- ],- "type": "FULLTEXT"- },- {- "name": "idx_a",- "expressions": [- "a_copy"- ],- "type": "BTREE",- "visible": true- },- {- "name": "idx_a_b",- "expressions": [- "a_copy",- "b"- ],- "type": "BTREE",- "visible": true- },- {- "name": "idx_b",- "expressions": [- "b"- ],- "type": "BTREE",- "unique": true,- "visible": true- }- ],- "engine": "INNODB",- "collation": "utf8mb4_0900_ai_ci",- "comment": "This is a table comment"- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t_copy\",\n \"columns\": [\n \+ \ {\n \"name\": \"b\",\n \"position\": 1,\n \+ \ \"nullable\": true,\n \"type\": \"varchar(20)\"\n \+ \ },\n {\n \"name\": \"a_copy\",\n \+ \ \"position\": 2,\n \"type\": \"int(11)\"\n },\n \+ \ {\n \"name\": \"a1\",\n \"position\": 3,\n\+ \ \"nullable\": true,\n \"type\": \"int(11)\"\n \+ \ },\n {\n \"name\": \"d_copy\",\n \+ \ \"position\": 4,\n \"nullable\": true,\n \"type\"\+ : \"varchar(10)\",\n \"collation\": \"utf8mb4_polish_ci\"\n \+ \ },\n {\n \"name\": \"e\",\n \"position\"\+ : 5,\n \"nullable\": true,\n \"type\": \"int(11)\"\n\+ \ }\n ],\n \"indexes\": [\n {\n \+ \ \"name\": \"b_3\",\n \"expressions\": [\n \+ \ \"b\",\n \"d_copy\"\n ],\n \"type\"\+ : \"BTREE\",\n \"unique\": true\n },\n {\n\+ \ \"name\": \"b_4\",\n \"expressions\": [\n \+ \ \"b\",\n \"d_copy\"\n ],\n \"\+ type\": \"FULLTEXT\"\n },\n {\n \"name\": \"\+ idx_a\",\n \"expressions\": [\n \"a_copy\"\n \+ \ ],\n \"type\": \"BTREE\",\n \"visible\": true\n\+ \ },\n {\n \"name\": \"idx_a_b\",\n \+ \ \"expressions\": [\n \"a_copy\",\n \"b\"\+ \n ],\n \"type\": \"BTREE\",\n \"visible\"\+ : true\n },\n {\n \"name\": \"idx_b\",\n \+ \ \"expressions\": [\n \"b\"\n ],\n \+ \ \"type\": \"BTREE\",\n \"unique\": true,\n \+ \ \"visible\": true\n }\n ],\n \"engine\": \"\+ INNODB\",\n \"collation\": \"utf8mb4_0900_ai_ci\",\n \"comment\"\+ : \"This is a table comment\"\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t(- a int PRIMARY KEY DEFAULT 1,- b varchar(200) CHARACTER SET utf8mb4 NOT NULL UNIQUE,- c int auto_increment NULL COMMENT 'This is a comment',- d varchar(10) COLLATE utf8mb4_polish_ci- );- CREATE INDEX idx_a on t(a);- CREATE INDEX b_2 on t(b, a);- CREATE UNIQUE INDEX b_3 on t(b, c, d);- CREATE FULLTEXT INDEX b_4 on t(b, d) WITH PARSER ngram INVISIBLE;+- statement: "CREATE TABLE t(\n a int PRIMARY KEY DEFAULT 1,\n b varchar(200) CHARACTER\+ \ SET utf8mb4 NOT NULL UNIQUE,\n c int auto_increment NULL COMMENT 'This is a\+ \ comment',\n d varchar(10) COLLATE utf8mb4_polish_ci\n);\nCREATE INDEX idx_a\+ \ on t(a);\nCREATE INDEX b_2 on t(b, a);\nCREATE UNIQUE INDEX b_3 on t(b, c, d);\n\+ CREATE FULLTEXT INDEX b_4 on t(b, d) WITH PARSER ngram INVISIBLE;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t",- "columns": [- {- "name": "a",- "position": 1,- "default": "1",- "type": "int(11)"- },- {- "name": "b",- "position": 2,- "type": "varchar(200)",- "characterSet": "utf8mb4"- },- {- "name": "c",- "position": 3,- "nullable": true,- "type": "int(11)",- "comment": "This is a comment"- },- {- "name": "d",- "position": 4,- "nullable": true,- "type": "varchar(10)",- "collation": "utf8mb4_polish_ci"- }- ],- "indexes": [- {- "name": "PRIMARY",- "expressions": [- "a"- ],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true- },- {- "name": "b",- "expressions": [- "b"- ],- "type": "BTREE",- "unique": true,- "visible": true- },- {- "name": "b_2",- "expressions": [- "b",- "a"- ],- "type": "BTREE",- "visible": true- },- {- "name": "b_3",- "expressions": [- "b",- "c",- "d"- ],- "type": "BTREE",- "unique": true,- "visible": true- },- {- "name": "b_4",- "expressions": [- "b",- "d"- ],- "type": "FULLTEXT"- },- {- "name": "idx_a",- "expressions": [- "a"- ],- "type": "BTREE",- "visible": true- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"default\": \"1\",\n \"type\": \"int(11)\"\n },\n\+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\+ \ \"type\": \"varchar(200)\",\n \"characterSet\": \"\+ utf8mb4\"\n },\n {\n \"name\": \"c\",\n \+ \ \"position\": 3,\n \"nullable\": true,\n \+ \ \"type\": \"int(11)\",\n \"comment\": \"This is a comment\"\n\+ \ },\n {\n \"name\": \"d\",\n \+ \ \"position\": 4,\n \"nullable\": true,\n \"type\"\+ : \"varchar(10)\",\n \"collation\": \"utf8mb4_polish_ci\"\n \+ \ }\n ],\n \"indexes\": [\n {\n \+ \ \"name\": \"PRIMARY\",\n \"expressions\": [\n \+ \ \"a\"\n ],\n \"type\": \"BTREE\",\n \"\+ unique\": true,\n \"primary\": true,\n \"visible\":\+ \ true\n },\n {\n \"name\": \"b\",\n \+ \ \"expressions\": [\n \"b\"\n ],\n \+ \ \"type\": \"BTREE\",\n \"unique\": true,\n \"\+ visible\": true\n },\n {\n \"name\": \"b_2\"\+ ,\n \"expressions\": [\n \"b\",\n \"\+ a\"\n ],\n \"type\": \"BTREE\",\n \"visible\"\+ : true\n },\n {\n \"name\": \"b_3\",\n \+ \ \"expressions\": [\n \"b\",\n \"c\",\n\+ \ \"d\"\n ],\n \"type\": \"BTREE\",\n\+ \ \"unique\": true,\n \"visible\": true\n \+ \ },\n {\n \"name\": \"b_4\",\n \"expressions\"\+ : [\n \"b\",\n \"d\"\n ],\n \+ \ \"type\": \"FULLTEXT\"\n },\n {\n \"\+ name\": \"idx_a\",\n \"expressions\": [\n \"a\"\n\+ \ ],\n \"type\": \"BTREE\",\n \"visible\"\+ : true\n }\n ]\n }\n ]\n }\n ]\n}"err: null-- statement: |-- CREATE TABLE t(- a int PRIMARY KEY DEFAULT 1,- b varchar(200) CHARACTER SET utf8mb4 NOT NULL UNIQUE- );- DROP INDEX b on t;+- statement: "CREATE TABLE t(\n a int PRIMARY KEY DEFAULT 1,\n b varchar(200) CHARACTER\+ \ SET utf8mb4 NOT NULL UNIQUE\n);\nDROP INDEX b on t;"ignore_case_sensitive: false- want: |-- {- "name": "test",- "schemas": [- {- "tables": [- {- "name": "t",- "columns": [- {- "name": "a",- "position": 1,- "default": "1",- "type": "int(11)"- },- {- "name": "b",- "position": 2,- "type": "varchar(200)",- "characterSet": "utf8mb4"- }- ],- "indexes": [- {- "name": "PRIMARY",- "expressions": [- "a"- ],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true- }- ]- }- ]- }- ]- }+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\+ \ {\n \"name\": \"t\",\n \"columns\": [\n \+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \+ \ \"default\": \"1\",\n \"type\": \"int(11)\"\n },\n\+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\+ \ \"type\": \"varchar(200)\",\n \"characterSet\": \"\+ utf8mb4\"\n }\n ],\n \"indexes\": [\n \+ \ {\n \"name\": \"PRIMARY\",\n \"expressions\": [\n\+ \ \"a\"\n ],\n \"type\": \"BTREE\",\n\+ \ \"unique\": true,\n \"primary\": true,\n \+ \ \"visible\": true\n }\n ]\n }\n ]\n }\n\+ \ ]\n}"err: nulldiff --git a/backend/plugin/advisor/catalog/walk_through.go b/backend/plugin/advisor/catalog/walk_through.goindex 4904bba91d..4932a87b33 100644--- a/backend/plugin/advisor/catalog/walk_through.go+++ b/backend/plugin/advisor/catalog/walk_through.go@@ -8,11 +8,9 @@ import ("github.com/pkg/errors"storepb "github.com/bytebase/bytebase/backend/generated-go/store"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")-// WalkThroughErrorType is the type of WalkThroughError.-type WalkThroughErrorType int-const (// PrimaryKeyName is the string for PK.PrimaryKeyName string = "PRIMARY"@@ -22,153 +20,69 @@ const (SpatialName string = "SPATIAL"publicSchemaName = "public"-- // ErrorTypeUnsupported is the error for unsupported cases.- ErrorTypeUnsupported WalkThroughErrorType = 1- // ErrorTypeInternal is the error for internal errors.- ErrorTypeInternal WalkThroughErrorType = 2-- // 101 parse error type.-- // ErrorTypeParseError is the error in parsing.- ErrorTypeParseError WalkThroughErrorType = 101- // ErrorTypeDeparseError is the error in deparsing.- ErrorTypeDeparseError WalkThroughErrorType = 102-- // 201 ~ 299 database error type.-- // ErrorTypeAccessOtherDatabase is the error that try to access other database.- ErrorTypeAccessOtherDatabase = 201- // ErrorTypeDatabaseIsDeleted is the error that try to access the deleted database.- ErrorTypeDatabaseIsDeleted = 202- // ErrorTypeReferenceOtherDatabase is the error that try to reference other database.- ErrorTypeReferenceOtherDatabase = 203-- // 301 ~ 399 table error type.-- // ErrorTypeTableExists is the error that table exists.- ErrorTypeTableExists = 301- // ErrorTypeTableNotExists is the error that table not exists.- ErrorTypeTableNotExists = 302- // ErrorTypeUseCreateTableAs is the error that using CREATE TABLE AS statements.- ErrorTypeUseCreateTableAs = 303- // ErrorTypeTableIsReferencedByView is the error that table is referenced by view.- ErrorTypeTableIsReferencedByView = 304-- // 401 ~ 499 column error type.-- // ErrorTypeColumnExists is the error that column exists.- ErrorTypeColumnExists = 401- // ErrorTypeColumnNotExists is the error that column not exists.- ErrorTypeColumnNotExists = 402- // ErrorTypeDropAllColumns is the error that dropping all columns in a table.- ErrorTypeDropAllColumns = 403- // ErrorTypeAutoIncrementExists is the error that auto_increment exists.- ErrorTypeAutoIncrementExists = 404- // ErrorTypeOnUpdateColumnNotDatetimeOrTimestamp is the error that the ON UPDATE column is not datetime or timestamp.- ErrorTypeOnUpdateColumnNotDatetimeOrTimestamp = 405- // ErrorTypeSetNullDefaultForNotNullColumn is the error that setting NULL default value for the NOT NULL column.- ErrorTypeSetNullDefaultForNotNullColumn = 406- // ErrorTypeInvalidColumnTypeForDefaultValue is the error that invalid column type for default value.- ErrorTypeInvalidColumnTypeForDefaultValue = 407- // ErrorTypeColumnIsReferencedByView is the error that column is referenced by view.- ErrorTypeColumnIsReferencedByView = 408-- // 501 ~ 599 index error type.-- // ErrorTypePrimaryKeyExists is the error that PK exists.- ErrorTypePrimaryKeyExists = 501- // ErrorTypeIndexExists is the error that index exists.- ErrorTypeIndexExists = 502- // ErrorTypeIndexEmptyKeys is the error that index has empty keys.- ErrorTypeIndexEmptyKeys = 503- // ErrorTypePrimaryKeyNotExists is the error that PK does not exist.- ErrorTypePrimaryKeyNotExists = 504- // ErrorTypeIndexNotExists is the error that index does not exist.- ErrorTypeIndexNotExists = 505- // ErrorTypeIncorrectIndexName is the incorrect index name error.- ErrorTypeIncorrectIndexName = 506- // ErrorTypeSpatialIndexKeyNullable is the error that keys in spatial index are nullable.- ErrorTypeSpatialIndexKeyNullable = 507-- // 701 ~ 799 schema error type.-- // ErrorTypeSchemaNotExists is the error that schema does not exist.- ErrorTypeSchemaNotExists = 701-- // 801 ~ 899 relation error type.-- // ErrorTypeRelationExists is the error that relation already exists.- ErrorTypeRelationExists = 801-- // 901 ~ 999 constraint error type.-- // ErrorTypeConstraintNotExists is the error that constraint doesn't exist.- ErrorTypeConstraintNotExists = 901)// WalkThroughError is the error for walking-through.+// It represents SQL review errors that should be converted to advisor codes.type WalkThroughError struct {- Type WalkThroughErrorType+ Code code.CodeContent string// TODO(zp): positionLine int-- Payload any}-// NewRelationExistsError returns a new ErrorTypeRelationExists.+// NewRelationExistsError returns a new RelationExists error.func NewRelationExistsError(relationName string, schemaName string) *WalkThroughError {return &WalkThroughError{- Type: ErrorTypeRelationExists,+ Code: code.RelationExists,Content: fmt.Sprintf("Relation %q already exists in schema %q", relationName, schemaName),}}-// NewColumnNotExistsError returns a new ErrorTypeColumnNotExists.+// NewColumnNotExistsError returns a new ColumnNotExists error.func NewColumnNotExistsError(tableName string, columnName string) *WalkThroughError {return &WalkThroughError{- Type: ErrorTypeColumnNotExists,+ Code: code.ColumnNotExists,Content: fmt.Sprintf("Column `%s` does not exist in table `%s`", columnName, tableName),}}-// NewIndexNotExistsError returns a new ErrorTypeIndexNotExists.+// NewIndexNotExistsError returns a new IndexNotExists error.func NewIndexNotExistsError(tableName string, indexName string) *WalkThroughError {return &WalkThroughError{- Type: ErrorTypeIndexNotExists,+ Code: code.IndexNotExists,Content: fmt.Sprintf("Index `%s` does not exist in table `%s`", indexName, tableName),}}-// NewIndexExistsError returns a new ErrorTypeIndexExists.+// NewIndexExistsError returns a new IndexExists error.func NewIndexExistsError(tableName string, indexName string) *WalkThroughError {return &WalkThroughError{- Type: ErrorTypeIndexExists,+ Code: code.IndexExists,Content: fmt.Sprintf("Index `%s` already exists in table `%s`", indexName, tableName),}}-// NewAccessOtherDatabaseError returns a new ErrorTypeAccessOtherDatabase.+// NewAccessOtherDatabaseError returns a new NotCurrentDatabase error.func NewAccessOtherDatabaseError(current string, target string) *WalkThroughError {return &WalkThroughError{- Type: ErrorTypeAccessOtherDatabase,+ Code: code.NotCurrentDatabase,Content: fmt.Sprintf("Database `%s` is not the current database `%s`", target, current),}}-// NewTableNotExistsError returns a new ErrorTypeTableNotExists.+// NewTableNotExistsError returns a new TableNotExists error.func NewTableNotExistsError(tableName string) *WalkThroughError {return &WalkThroughError{- Type: ErrorTypeTableNotExists,+ Code: code.TableNotExists,Content: fmt.Sprintf("Table `%s` does not exist", tableName),}}-// NewTableExistsError returns a new ErrorTypeTableExists.+// NewTableExistsError returns a new TableExists error.func NewTableExistsError(tableName string) *WalkThroughError {return &WalkThroughError{- Type: ErrorTypeTableExists,+ Code: code.TableExists,Content: fmt.Sprintf("Table `%s` already exists", tableName),}}@@ -188,10 +102,7 @@ func WalkThrough(d *DatabaseState, ast any) error {case storepb.Engine_POSTGRES:return PgWalkThrough(d, ast)default:- return &WalkThroughError{- Type: ErrorTypeUnsupported,- Content: fmt.Sprintf("Walk-through doesn't support engine type: %s", d.dbType),- }+ return errors.Errorf("Walk-through doesn't support engine type: %s", d.dbType)}}@@ -231,14 +142,14 @@ func (s *SchemaState) renameTable(oldName string, newName string) *WalkThroughErtable, exists := s.getTable(oldName)if !exists {return &WalkThroughError{- Type: ErrorTypeTableNotExists,+ Code: code.TableNotExists,Content: fmt.Sprintf("Table `%s` does not exist", oldName),}}if _, exists := s.getTable(newName); exists {return &WalkThroughError{- Type: ErrorTypeTableExists,+ Code: code.TableExists,Content: fmt.Sprintf("Table `%s` already exists", newName),}}@@ -277,15 +188,12 @@ func parseViewName(viewName string) (string, string, error) {return match[1], match[2], nil}-func (d *DatabaseState) existedViewList(viewMap map[string]bool) ([]string, *WalkThroughError) {+func (d *DatabaseState) existedViewList(viewMap map[string]bool) ([]string, error) {var result []stringfor viewName := range viewMap {schemaName, viewName, err := parseViewName(viewName)if err != nil {- return nil, &WalkThroughError{- Type: ErrorTypeInternal,- Content: fmt.Sprintf("failed to check view dependency: %s", err.Error()),- }+ return nil, errors.Wrapf(err, "failed to check view dependency")}schemaMeta, exists := d.schemaSet[schemaName]if !exists {@@ -323,7 +231,7 @@ func (d *DatabaseState) getSchema(schemaName string) (*SchemaState, *WalkThroughif !exists {if schemaName != publicSchemaName {return nil, &WalkThroughError{- Type: ErrorTypeSchemaNotExists,+ Code: code.SchemaNotExists,Content: fmt.Sprintf("The schema %q doesn't exist", schemaName),}}@@ -344,7 +252,7 @@ func (t *TableState) getColumn(columnName string) (*ColumnState, *WalkThroughErrcolumn, exists := t.columnSet[columnName]if !exists {return nil, &WalkThroughError{- Type: ErrorTypeColumnNotExists,+ Code: code.ColumnNotExists,Content: fmt.Sprintf("The column %q does not exist in the table %q", columnName, t.name),}}@@ -355,7 +263,7 @@ func (s *SchemaState) pgGetTable(tableName string) (*TableState, *WalkThroughErrtable, exists := s.tableSet[tableName]if !exists {return nil, &WalkThroughError{- Type: ErrorTypeTableNotExists,+ Code: code.TableNotExists,Content: fmt.Sprintf("The table %q does not exist in schema %q", tableName, s.name),}}@@ -370,7 +278,7 @@ func (s *SchemaState) getIndex(indexName string) (*TableState, *IndexState, *Wal}return nil, nil, &WalkThroughError{- Type: ErrorTypeIndexNotExists,+ Code: code.IndexNotExists,Content: fmt.Sprintf("Index %q does not exists in schema %q", indexName, s.name),}}diff --git a/backend/plugin/advisor/catalog/walk_through_for_mysql.go b/backend/plugin/advisor/catalog/walk_through_for_mysql.goindex 9e13d629df..789300a03d 100644--- a/backend/plugin/advisor/catalog/walk_through_for_mysql.go+++ b/backend/plugin/advisor/catalog/walk_through_for_mysql.go@@ -9,6 +9,7 @@ import (tidbast "github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql""github.com/bytebase/bytebase/backend/plugin/parser/tidb")@@ -60,7 +61,7 @@ func (d *DatabaseState) mysqlChangeState(in *mysqlparser.ParseResult) (err *Walkif d.IsDeleted() {return &WalkThroughError{- Type: ErrorTypeDatabaseIsDeleted,+ Code: code.DatabaseIsDeleted,Content: fmt.Sprintf("Database `%s` is deleted", d.name),}}@@ -90,7 +91,7 @@ func (l *mysqlListener) EnterCreateTable(ctx *mysql.CreateTableContext) {databaseName, tableName := mysqlparser.NormalizeMySQLTableName(ctx.TableName())if databaseName != "" && !l.databaseState.isCurrentDatabase(databaseName) {l.err = &WalkThroughError{- Type: ErrorTypeAccessOtherDatabase,+ Code: code.NotCurrentDatabase,Content: fmt.Sprintf("Database `%s` is not the current database `%s`", databaseName, l.databaseState.name),}return@@ -102,7 +103,7 @@ func (l *mysqlListener) EnterCreateTable(ctx *mysql.CreateTableContext) {return}l.err = &WalkThroughError{- Type: ErrorTypeTableExists,+ Code: code.TableExists,Content: fmt.Sprintf("Table `%s` already exists", tableName),}return@@ -110,7 +111,7 @@ func (l *mysqlListener) EnterCreateTable(ctx *mysql.CreateTableContext) {if ctx.DuplicateAsQueryExpression() != nil {l.err = &WalkThroughError{- Type: ErrorTypeUseCreateTableAs,+ Code: code.StatementCreateTableAs,Content: fmt.Sprintf("Disallow the CREATE TABLE AS statement but \"%s\" uses", l.text),}return@@ -143,7 +144,7 @@ func (l *mysqlListener) EnterCreateTable(ctx *mysql.CreateTableContext) {if mysqlparser.IsAutoIncrement(tableElement.ColumnDefinition().FieldDefinition()) {if hasAutoIncrement {l.err = &WalkThroughError{- Type: ErrorTypeAutoIncrementExists,+ Code: code.AutoIncrementExists,// The content comes from MySQL error content.Content: fmt.Sprintf("There can be only one auto column for table `%s`", table.name),}@@ -181,7 +182,7 @@ func (l *mysqlListener) EnterDropTable(ctx *mysql.DropTableContext) {databaseName, tableName := mysqlparser.NormalizeMySQLTableRef(tableRef)if databaseName != "" && !l.databaseState.isCurrentDatabase(databaseName) {l.err = &WalkThroughError{- Type: ErrorTypeAccessOtherDatabase,+ Code: code.NotCurrentDatabase,Content: fmt.Sprintf("Database `%s` is not the current database `%s`", databaseName, tableName),}}@@ -194,7 +195,7 @@ func (l *mysqlListener) EnterDropTable(ctx *mysql.DropTableContext) {return}l.err = &WalkThroughError{- Type: ErrorTypeTableNotExists,+ Code: code.TableNotExists,Content: fmt.Sprintf("Table `%s` does not exist", tableName),}return@@ -681,7 +682,7 @@ func (t *TableState) mysqlAlterColumn(itemDef mysql.IAlterListItemContext) *Walk"json","geometry":return &WalkThroughError{- Type: ErrorTypeInvalidColumnTypeForDefaultValue,+ Code: code.InvalidColumnDefault,// Content comes from MySQL Error content.Content: fmt.Sprintf("BLOB, TEXT, GEOMETRY or JSON column `%s` can't have a default value", columnName),}@@ -704,7 +705,7 @@ func (t *TableState) mysqlAlterColumn(itemDef mysql.IAlterListItemContext) *Walk} else {if colState.nullable != nil && !*colState.nullable {return &WalkThroughError{- Type: ErrorTypeSetNullDefaultForNotNullColumn,+ Code: code.SetNullDefaultForNotNullColumn,// Content comes from MySQL Error content.Content: fmt.Sprintf("Invalid default value for column `%s`", columnName),}@@ -949,7 +950,7 @@ func (t *TableState) mysqlValidateColumnList(columnList []string, primary bool,}if isSpatial && column.nullable != nil && *column.nullable {return &WalkThroughError{- Type: ErrorTypeSpatialIndexKeyNullable,+ Code: code.SpatialIndexKeyNullable,// The error content comes from MySQL.Content: fmt.Sprintf("All parts of a SPATIAL index must be NOT NULL, but `%s` is nullable", column.name),}@@ -973,7 +974,7 @@ func (t *TableState) mysqlValidateExpressionList(expressionList []string, primar}if isSpatial && column.nullable != nil && *column.nullable {return &WalkThroughError{- Type: ErrorTypeSpatialIndexKeyNullable,+ Code: code.SpatialIndexKeyNullable,// The error content comes from MySQL.Content: fmt.Sprintf("All parts of a SPATIAL index must be NOT NULL, but `%s` is nullable", column.name),}@@ -1023,7 +1024,7 @@ func mysqlGetIndexType(tableConstraint mysql.ITableConstraintDefContext) stringfunc (t *TableState) mysqlCreateColumn(columnName string, fieldDef mysql.IFieldDefinitionContext, position *mysqlColumnPosition) *WalkThroughError {if _, exists := t.columnSet[strings.ToLower(columnName)]; exists {return &WalkThroughError{- Type: ErrorTypeColumnExists,+ Code: code.ColumnExists,Content: fmt.Sprintf("Column `%s` already exists in table `%s`", columnName, t.name),}}@@ -1104,7 +1105,7 @@ func (t *TableState) mysqlCreateColumn(columnName string, fieldDef mysql.IFieldD}if !mysqlparser.IsTimeType(fieldDef.DataType()) {return &WalkThroughError{- Type: ErrorTypeOnUpdateColumnNotDatetimeOrTimestamp,+ Code: code.OnUpdateColumnNotDatetimeOrTimestamp,Content: fmt.Sprintf("Column `%s` use ON UPDATE but is not DATETIME or TIMESTAMP", col.name),}}@@ -1139,7 +1140,7 @@ func (t *TableState) mysqlCreateColumn(columnName string, fieldDef mysql.IFieldDif col.nullable != nil && !*col.nullable && setNullDefault {return &WalkThroughError{- Type: ErrorTypeSetNullDefaultForNotNullColumn,+ Code: code.SetNullDefaultForNotNullColumn,// Content comes from MySQL Error content.Content: fmt.Sprintf("Invalid default value for column `%s`", col.name),}@@ -1173,7 +1174,7 @@ func (t *TableState) mysqlReorderColumn(position *mysqlColumnPosition) (int, *Wareturn *column.position + 1, nildefault:return 0, &WalkThroughError{- Type: ErrorTypeUnsupported,+ Code: code.Unsupported,Content: fmt.Sprintf("Unsupported column position type: %d", position.tp),}}@@ -1182,7 +1183,7 @@ func (t *TableState) mysqlReorderColumn(position *mysqlColumnPosition) (int, *Wafunc (t *TableState) mysqlCreateIndex(name string, keyList []string, unique bool, tp string, tableConstraint mysql.ITableConstraintDefContext, createIndexDef mysql.ICreateIndexContext) *WalkThroughError {if len(keyList) == 0 {return &WalkThroughError{- Type: ErrorTypeIndexEmptyKeys,+ Code: code.IndexEmptyKeys,Content: fmt.Sprintf("Index `%s` in table `%s` has empty key", name, t.name),}}@@ -1291,7 +1292,7 @@ func (t *TableState) mysqlCreateIndex(name string, keyList []string, unique boolfunc (t *TableState) mysqlCreatePrimaryKey(keys []string, tp string) *WalkThroughError {if _, exists := t.indexSet[strings.ToLower(PrimaryKeyName)]; exists {return &WalkThroughError{- Type: ErrorTypePrimaryKeyExists,+ Code: code.PrimaryKeyExists,Content: fmt.Sprintf("Primary key exists in table `%s`", t.name),}}@@ -1335,7 +1336,7 @@ func mysqlCheckDefault(columnName string, fieldDefinition mysql.IFieldDefinitionmysql.MySQLParserPOLYGON_SYMBOL,mysql.MySQLParserMULTIPOLYGON_SYMBOL:return &WalkThroughError{- Type: ErrorTypeInvalidColumnTypeForDefaultValue,+ Code: code.InvalidColumnDefault,// Content comes from MySQL Error content.Content: fmt.Sprintf("BLOB, TEXT, GEOMETRY or JSON column `%s` can't have a default value", columnName),}diff --git a/backend/plugin/advisor/catalog/walk_through_for_pg.go b/backend/plugin/advisor/catalog/walk_through_for_pg.goindex 1a4f3fad4d..be7fd61d3f 100644--- a/backend/plugin/advisor/catalog/walk_through_for_pg.go+++ b/backend/plugin/advisor/catalog/walk_through_for_pg.go@@ -9,6 +9,7 @@ import (parser "github.com/bytebase/parser/postgresql"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -17,10 +18,7 @@ func PgWalkThrough(d *DatabaseState, ast any) error {// ANTLR-based walkthroughparseResult, ok := ast.(*pgparser.ParseResult)if !ok {- return &WalkThroughError{- Type: ErrorTypeUnsupported,- Content: fmt.Sprintf("PostgreSQL walk-through expects *pgparser.ParseResult, got %T", ast),- }+ return errors.Errorf("PostgreSQL walk-through expects *pgparser.ParseResult, got %T", ast)}root, ok := parseResult.Tree.(parser.IRootContext)@@ -94,7 +92,7 @@ func (l *pgCatalogListener) EnterCreatestmt(ctx *parser.CreatestmtContext) {databaseName := extractDatabaseName(qualifiedNames[0])if databaseName != "" && l.databaseState.name != databaseName {l.setError(&WalkThroughError{- Type: ErrorTypeAccessOtherDatabase,+ Code: code.NotCurrentDatabase,Content: fmt.Sprintf("Database %q is not the current database %q", databaseName, l.databaseState.name),})return@@ -115,7 +113,7 @@ func (l *pgCatalogListener) EnterCreatestmt(ctx *parser.CreatestmtContext) {return}l.setError(&WalkThroughError{- Type: ErrorTypeTableExists,+ Code: code.TableExists,Content: fmt.Sprintf(`The table %q already exists in the schema %q`, tableName, schema.name),})return@@ -169,7 +167,7 @@ func createColumn(schema *SchemaState, table *TableState, columnDef parser.IColu// Check if column already existsif _, exists := table.columnSet[columnName]; exists {return &WalkThroughError{- Type: ErrorTypeColumnExists,+ Code: code.ColumnExists,Content: fmt.Sprintf("The column %q already exists in table %q", columnName, table.name),}}@@ -438,7 +436,7 @@ func (l *pgCatalogListener) EnterIndexstmt(ctx *parser.IndexstmtContext) {if len(columnList) == 0 {l.setError(&WalkThroughError{- Type: ErrorTypeIndexEmptyKeys,+ Code: code.IndexEmptyKeys,Content: fmt.Sprintf("Index %q in table %q has empty key", indexName, tableName),})return@@ -540,7 +538,7 @@ func (l *pgCatalogListener) EnterAltertablestmt(ctx *parser.AltertablestmtContex// Check database accessif databaseName != "" && l.databaseState.name != databaseName {l.setError(&WalkThroughError{- Type: ErrorTypeAccessOtherDatabase,+ Code: code.NotCurrentDatabase,Content: fmt.Sprintf("Database %q is not the current database %q", databaseName, l.databaseState.name),})return@@ -665,14 +663,16 @@ func (l *pgCatalogListener) alterTableDropColumn(schema *SchemaState, table *Tab// Check if column is referenced by any viewsviewList, err := l.databaseState.existedViewList(column.dependencyView)if err != nil {- l.setError(err)+ l.setError(&WalkThroughError{+ Code: code.Internal,+ Content: fmt.Sprintf("Failed to check view dependency: %v", err),+ })return}if len(viewList) > 0 {l.setError(&WalkThroughError{- Type: ErrorTypeColumnIsReferencedByView,+ Code: code.ColumnIsReferencedByView,Content: fmt.Sprintf("Cannot drop column %q in table %q.%q, it's referenced by view: %s", column.name, schema.name, table.name, strings.Join(viewList, ", ")),- Payload: viewList,})return}@@ -712,14 +712,16 @@ func (l *pgCatalogListener) alterTableAlterColumnType(schema *SchemaState, table// Check if column is referenced by any viewsviewList, viewErr := l.databaseState.existedViewList(column.dependencyView)if viewErr != nil {- l.setError(viewErr)+ l.setError(&WalkThroughError{+ Code: code.Internal,+ Content: fmt.Sprintf("Failed to check view dependency: %v", viewErr),+ })return}if len(viewList) > 0 {l.setError(&WalkThroughError{- Type: ErrorTypeColumnIsReferencedByView,+ Code: code.ColumnIsReferencedByView,Content: fmt.Sprintf("Cannot alter type of column %q in table %q.%q, it's referenced by view: %s", column.name, schema.name, table.name, strings.Join(viewList, ", ")),- Payload: viewList,})return}@@ -742,7 +744,7 @@ func (l *pgCatalogListener) alterTableAddColumn(schema *SchemaState, table *Tablreturn}l.setError(&WalkThroughError{- Type: ErrorTypeColumnExists,+ Code: code.ColumnExists,Content: fmt.Sprintf("The column %q already exists in table %q", columnName, table.name),})return@@ -870,7 +872,7 @@ func (l *pgCatalogListener) alterTableDropConstraint(schema *SchemaState, tableif !ifExists {l.setError(&WalkThroughError{- Type: ErrorTypeConstraintNotExists,+ Code: code.ConstraintNotExists,Content: fmt.Sprintf("Constraint %q for table %q does not exist", constraintName, table.name),})}@@ -944,7 +946,7 @@ func (*pgCatalogListener) renameColumn(table *TableState, oldName string, newNam// Check if new name already existsif _, exists := table.columnSet[newName]; exists {return &WalkThroughError{- Type: ErrorTypeColumnExists,+ Code: code.ColumnExists,Content: fmt.Sprintf("The column %q already exists in table %q", newName, table.name),}}@@ -1081,7 +1083,7 @@ func (l *pgCatalogListener) EnterDropdbstmt(ctx *parser.DropdbstmtContext) {// This matches the real PostgreSQL behavior: "ERROR: cannot drop the currently open database"if l.databaseState.isCurrentDatabase(databaseName) {l.setError(&WalkThroughError{- Type: ErrorTypeAccessOtherDatabase,+ Code: code.NotCurrentDatabase,Content: fmt.Sprintf("Cannot drop the currently open database %q", databaseName),})return@@ -1123,15 +1125,17 @@ func (l *pgCatalogListener) dropTable(anyName parser.IAny_nameContext, ifExists}// Check for view dependencies- viewList, err := l.databaseState.existedViewList(table.dependencyView)- if err != nil {- return err+ viewList, viewErr := l.databaseState.existedViewList(table.dependencyView)+ if viewErr != nil {+ return &WalkThroughError{+ Code: code.Internal,+ Content: fmt.Sprintf("Failed to check view dependency: %v", viewErr),+ }}if len(viewList) > 0 {return &WalkThroughError{- Type: ErrorTypeTableIsReferencedByView,+ Code: code.TableIsReferencedByView,Content: fmt.Sprintf("Cannot drop table %q.%q, it's referenced by view: %s", schema.name, table.name, strings.Join(viewList, ", ")),- Payload: viewList,}}@@ -1218,7 +1222,7 @@ func (l *pgCatalogListener) dropSchema(schemaNameCtx parser.INameContext, ifExisreturn nil}return &WalkThroughError{- Type: ErrorTypeSchemaNotExists,+ Code: code.SchemaNotExists,Content: fmt.Sprintf("Schema %q does not exist", schemaName),}}@@ -1414,7 +1418,7 @@ func (l *pgCatalogListener) EnterViewstmt(ctx *parser.ViewstmtContext) {// Check if accessing other databaseif databaseName != "" && l.databaseState.name != databaseName {l.setError(&WalkThroughError{- Type: ErrorTypeAccessOtherDatabase,+ Code: code.NotCurrentDatabase,Content: fmt.Sprintf("Database %q is not the current database %q", databaseName, l.databaseState.name),})returndiff --git a/backend/plugin/advisor/catalog/walk_through_for_tidb.go b/backend/plugin/advisor/catalog/walk_through_for_tidb.goindex 54dfe714aa..bfd06a5f90 100644--- a/backend/plugin/advisor/catalog/walk_through_for_tidb.go+++ b/backend/plugin/advisor/catalog/walk_through_for_tidb.go@@ -9,6 +9,8 @@ import ("github.com/pingcap/tidb/pkg/parser/mysql""github.com/pingcap/tidb/pkg/types""github.com/pkg/errors"++ "github.com/bytebase/bytebase/backend/plugin/advisor/code")// TiDBWalkThrough walks through TiDB AST and updates the database state.@@ -43,7 +45,7 @@ func (d *DatabaseState) changeState(in tidbast.StmtNode) (err *WalkThroughError)}()if d.IsDeleted() {return &WalkThroughError{- Type: ErrorTypeDatabaseIsDeleted,+ Code: code.DatabaseIsDeleted,Content: fmt.Sprintf("Database `%s` is deleted", d.name),}}@@ -340,7 +342,7 @@ func (t *TableState) changeColumnDefault(column *tidbast.ColumnDef) *WalkThrough"json","geometry":return &WalkThroughError{- Type: ErrorTypeInvalidColumnTypeForDefaultValue,+ Code: code.InvalidColumnDefault,// Content comes from MySQL Error content.Content: fmt.Sprintf("BLOB, TEXT, GEOMETRY or JSON column `%s` can't have a default value", columnName),}@@ -351,13 +353,16 @@ func (t *TableState) changeColumnDefault(column *tidbast.ColumnDef) *WalkThroughdefaultValue, err := restoreNode(column.Options[0].Expr, format.RestoreStringWithoutCharset)if err != nil {- return err+ return &WalkThroughError{+ Code: code.Internal,+ Content: fmt.Sprintf("Failed to deparse default value: %v", err),+ }}colState.defaultValue = &defaultValue} else {if colState.nullable != nil && !*colState.nullable {return &WalkThroughError{- Type: ErrorTypeSetNullDefaultForNotNullColumn,+ Code: code.SetNullDefaultForNotNullColumn,// Content comes from MySQL Error content.Content: fmt.Sprintf("Invalid default value for column `%s`", columnName),}@@ -468,7 +473,7 @@ func (t *TableState) reorderColumn(position *tidbast.ColumnPosition) (int, *Walkreturn *column.position + 1, nildefault:return 0, &WalkThroughError{- Type: ErrorTypeUnsupported,+ Code: code.Unsupported,Content: fmt.Sprintf("Unsupported column position type: %d", position.Tp),}}@@ -480,7 +485,7 @@ func (d *DatabaseState) dropTable(node *tidbast.DropTableStmt) *WalkThroughErrorfor _, name := range node.Tables {if name.Schema.O != "" && !d.isCurrentDatabase(name.Schema.O) {return &WalkThroughError{- Type: ErrorTypeAccessOtherDatabase,+ Code: code.NotCurrentDatabase,Content: fmt.Sprintf("Database `%s` is not the current database `%s`", name.Schema.O, d.name),}}@@ -496,7 +501,7 @@ func (d *DatabaseState) dropTable(node *tidbast.DropTableStmt) *WalkThroughErrorreturn nil}return &WalkThroughError{- Type: ErrorTypeTableNotExists,+ Code: code.TableNotExists,Content: fmt.Sprintf("Table `%s` does not exist", name.Name.O),}}@@ -510,9 +515,9 @@ func (d *DatabaseState) dropTable(node *tidbast.DropTableStmt) *WalkThroughErrorfunc (d *DatabaseState) copyTable(node *tidbast.CreateTableStmt) *WalkThroughError {targetTable, err := d.findTableState(node.ReferTable)if err != nil {- if err.Type == ErrorTypeAccessOtherDatabase {+ if err.Code == code.NotCurrentDatabase {return &WalkThroughError{- Type: ErrorTypeReferenceOtherDatabase,+ Code: code.ReferenceOtherDatabase,Content: fmt.Sprintf("Reference table `%s` in other database `%s`, skip walkthrough", node.ReferTable.Name.O, node.ReferTable.Schema.O),}}@@ -528,7 +533,7 @@ func (d *DatabaseState) copyTable(node *tidbast.CreateTableStmt) *WalkThroughErrfunc (d *DatabaseState) createTable(node *tidbast.CreateTableStmt) *WalkThroughError {if node.Table.Schema.O != "" && !d.isCurrentDatabase(node.Table.Schema.O) {return &WalkThroughError{- Type: ErrorTypeAccessOtherDatabase,+ Code: code.NotCurrentDatabase,Content: fmt.Sprintf("Database `%s` is not the current database `%s`", node.Table.Schema.O, d.name),}}@@ -543,14 +548,14 @@ func (d *DatabaseState) createTable(node *tidbast.CreateTableStmt) *WalkThroughEreturn nil}return &WalkThroughError{- Type: ErrorTypeTableExists,+ Code: code.TableExists,Content: fmt.Sprintf("Table `%s` already exists", node.Table.Name.O),}}if node.Select != nil {return &WalkThroughError{- Type: ErrorTypeUseCreateTableAs,+ Code: code.StatementCreateTableAs,Content: fmt.Sprintf("Disallow the CREATE TABLE AS statement but \"%s\" uses", node.Text()),}}@@ -574,7 +579,7 @@ func (d *DatabaseState) createTable(node *tidbast.CreateTableStmt) *WalkThroughEif isAutoIncrement(column) {if hasAutoIncrement {return &WalkThroughError{- Type: ErrorTypeAutoIncrementExists,+ Code: code.AutoIncrementExists,// The content comes from MySQL error content.Content: fmt.Sprintf("There can be only one auto column for table `%s`", table.name),}@@ -648,7 +653,10 @@ func (t *TableState) validateAndGetKeyStringList(keyList []*tidbast.IndexPartSpeif key.Expr != nil {str, err := restoreNode(key, format.DefaultRestoreFlags)if err != nil {- return nil, err+ return nil, &WalkThroughError{+ Code: code.Internal,+ Content: fmt.Sprintf("Failed to deparse index key: %v", err),+ }}res = append(res, str)} else {@@ -662,7 +670,7 @@ func (t *TableState) validateAndGetKeyStringList(keyList []*tidbast.IndexPartSpe}if isSpatial && column.nullable != nil && *column.nullable {return nil, &WalkThroughError{- Type: ErrorTypeSpatialIndexKeyNullable,+ Code: code.SpatialIndexKeyNullable,// The error content comes from MySQL.Content: fmt.Sprintf("All parts of a SPATIAL index must be NOT NULL, but `%s` is nullable", column.name),}@@ -688,7 +696,7 @@ func checkDefault(columnName string, columnType *types.FieldType, value tidbast.switch columnType.GetType() {case mysql.TypeBlob, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeJSON, mysql.TypeGeometry:return &WalkThroughError{- Type: ErrorTypeInvalidColumnTypeForDefaultValue,+ Code: code.InvalidColumnDefault,// Content comes from MySQL Error content.Content: fmt.Sprintf("BLOB, TEXT, GEOMETRY or JSON column `%s` can't have a default value", columnName),}@@ -701,7 +709,7 @@ func checkDefault(columnName string, columnType *types.FieldType, value tidbast.datum := types.NewDatum(valueExpr.GetValue())if _, err := datum.ConvertTo(types.Context{}, columnType); err != nil {return &WalkThroughError{- Type: ErrorTypeInvalidColumnTypeForDefaultValue,+ Code: code.InvalidColumnDefault,Content: err.Error(),}}@@ -713,7 +721,7 @@ func checkDefault(columnName string, columnType *types.FieldType, value tidbast.func (t *TableState) createColumn(column *tidbast.ColumnDef, position *tidbast.ColumnPosition) *WalkThroughError {if _, exists := t.columnSet[column.Name.Name.L]; exists {return &WalkThroughError{- Type: ErrorTypeColumnExists,+ Code: code.ColumnExists,Content: fmt.Sprintf("Column `%s` already exists in table `%s`", column.Name.Name.O, t.name),}}@@ -758,7 +766,10 @@ func (t *TableState) createColumn(column *tidbast.ColumnDef, position *tidbast.Cif option.Expr.GetType().GetType() != mysql.TypeNull {defaultValue, err := restoreNode(option.Expr, format.RestoreStringWithoutCharset)if err != nil {- return err+ return &WalkThroughError{+ Code: code.Internal,+ Content: fmt.Sprintf("Failed to deparse default value: %v", err),+ }}col.defaultValue = &defaultValue} else {@@ -774,14 +785,17 @@ func (t *TableState) createColumn(column *tidbast.ColumnDef, position *tidbast.C// we do not deal with ON UPDATEif column.Tp.GetType() != mysql.TypeDatetime && column.Tp.GetType() != mysql.TypeTimestamp {return &WalkThroughError{- Type: ErrorTypeOnUpdateColumnNotDatetimeOrTimestamp,+ Code: code.OnUpdateColumnNotDatetimeOrTimestamp,Content: fmt.Sprintf("Column `%s` use ON UPDATE but is not DATETIME or TIMESTAMP", col.name),}}case tidbast.ColumnOptionComment:comment, err := restoreNode(option.Expr, format.RestoreStringWithoutCharset)if err != nil {- return err+ return &WalkThroughError{+ Code: code.Internal,+ Content: fmt.Sprintf("Failed to deparse comment: %v", err),+ }}col.comment = &commentcase tidbast.ColumnOptionGenerated:@@ -806,7 +820,7 @@ func (t *TableState) createColumn(column *tidbast.ColumnDef, position *tidbast.Cif col.nullable != nil && !*col.nullable && setNullDefault {return &WalkThroughError{- Type: ErrorTypeSetNullDefaultForNotNullColumn,+ Code: code.SetNullDefaultForNotNullColumn,// Content comes from MySQL Error content.Content: fmt.Sprintf("Invalid default value for column `%s`", col.name),}@@ -820,7 +834,7 @@ func (t *TableState) createColumn(column *tidbast.ColumnDef, position *tidbast.Cfunc (t *TableState) createIndex(name string, keyList []string, unique bool, tp string, option *tidbast.IndexOption) *WalkThroughError {if len(keyList) == 0 {return &WalkThroughError{- Type: ErrorTypeIndexEmptyKeys,+ Code: code.IndexEmptyKeys,Content: fmt.Sprintf("Index `%s` in table `%s` has empty key", name, t.name),}}@@ -864,7 +878,7 @@ func (t *TableState) createIndex(name string, keyList []string, unique bool, tpfunc (t *TableState) createPrimaryKey(keys []string, tp string) *WalkThroughError {if _, exists := t.indexSet[strings.ToLower(PrimaryKeyName)]; exists {return &WalkThroughError{- Type: ErrorTypePrimaryKeyExists,+ Code: code.PrimaryKeyExists,Content: fmt.Sprintf("Primary key exists in table `%s`", t.name),}}@@ -882,14 +896,11 @@ func (t *TableState) createPrimaryKey(keys []string, tp string) *WalkThroughErroreturn nil}-func restoreNode(node tidbast.Node, flag format.RestoreFlags) (string, *WalkThroughError) {+func restoreNode(node tidbast.Node, flag format.RestoreFlags) (string, error) {var buffer strings.Builderctx := format.NewRestoreCtx(flag, &buffer)if err := node.Restore(ctx); err != nil {- return "", &WalkThroughError{- Type: ErrorTypeDeparseError,- Content: err.Error(),- }+ return "", errors.Wrapf(err, "failed to deparse node")}return buffer.String(), nil}diff --git a/backend/plugin/advisor/catalog/walk_through_test.go b/backend/plugin/advisor/catalog/walk_through_test.goindex 5ded0dfa75..03be480b68 100644--- a/backend/plugin/advisor/catalog/walk_through_test.go+++ b/backend/plugin/advisor/catalog/walk_through_test.go@@ -162,14 +162,6 @@ func TestPostgreSQLANTLRWalkThrough(t *testing.T) {}}-func convertInterfaceSliceToStringSlice(slice []any) []string {- var res []string- for _, item := range slice {- res = append(res, item.(string))- }- return res-}-func runWalkThroughTest(t *testing.T, file string, engineType storepb.Engine, originDatabase *storepb.DatabaseSchemaMetadata) {tests := []testData{}filepath := filepath.Join("test", file+".yaml")@@ -196,17 +188,7 @@ func runWalkThroughTest(t *testing.T, file string, engineType storepb.Engine, orif err != nil {err, yes := err.(*WalkThroughError)require.True(t, yes)- if err.Payload != nil {- actualPayloadText, yes := err.Payload.([]string)- require.True(t, yes)- expectedPayloadText := convertInterfaceSliceToStringSlice(test.Err.Payload.([]any))- err.Payload = nil- test.Err.Payload = nil- require.Equal(t, test.Err, err)- require.Equal(t, expectedPayloadText, actualPayloadText)- } else {- require.Equal(t, test.Err, err)- }+ require.Equal(t, test.Err, err)continue}require.NoError(t, err, test.Statement)@@ -251,17 +233,7 @@ func runANTLRWalkThroughTest(t *testing.T, file string, engineType storepb.Enginif err != nil {err, yes := err.(*WalkThroughError)require.True(t, yes)- if err.Payload != nil {- actualPayloadText, yes := err.Payload.([]string)- require.True(t, yes)- expectedPayloadText := convertInterfaceSliceToStringSlice(test.Err.Payload.([]any))- err.Payload = nil- test.Err.Payload = nil- require.Equal(t, test.Err, err)- require.Equal(t, expectedPayloadText, actualPayloadText)- } else {- require.Equal(t, test.Err, err)- }+ require.Equal(t, test.Err, err)continue}require.NoError(t, err, test.Statement)diff --git a/backend/plugin/advisor/code.go b/backend/plugin/advisor/code/code.gosimilarity index 97%rename from backend/plugin/advisor/code.gorename to backend/plugin/advisor/code/code.goindex 6ce40cc60a..17777fdba9 100644--- a/backend/plugin/advisor/code.go+++ b/backend/plugin/advisor/code/code.go@@ -1,4 +1,4 @@-package advisor+package code// Code is the error code.type Code int@@ -126,6 +126,9 @@ const (InvalidColumnDefault Code = 423DropIndexColumn Code = 424DropColumn Code = 425+ AutoIncrementExists Code = 426+ OnUpdateColumnNotDatetimeOrTimestamp Code = 427+ SetNullDefaultForNotNullColumn Code = 428// 501 engine error code.NotInnoDBEngine Code = 501@@ -218,9 +221,13 @@ const (// 1901 ~ 1999 schema error code.SchemaNotExists Code = 1901+ RelationExists Code = 1902// 2001 ~ 2099 builtin error code.BuiltinPriorBackupCheck Code = 2001++ // 2101 ~ 2199 constraint error code.+ ConstraintNotExists Code = 2101)// Int returns the int type of code.diff --git a/backend/plugin/advisor/mssql/rule_builtin_prior_backup_check.go b/backend/plugin/advisor/mssql/rule_builtin_prior_backup_check.goindex ebc0762fbc..2e71e9d658 100644--- a/backend/plugin/advisor/mssql/rule_builtin_prior_backup_check.go+++ b/backend/plugin/advisor/mssql/rule_builtin_prior_backup_check.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql")@@ -54,7 +55,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: fmt.Sprintf("The size of statements in the sheet exceeds the limit of %d", common.MaxSheetCheckSize),- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: common.ConvertANTLRLineToPosition(1),})}@@ -65,7 +66,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: fmt.Sprintf("Need database %q to do prior backup but it does not exist", databaseName),- Code: advisor.DatabaseNotExists.Int32(),+ Code: code.DatabaseNotExists.Int32(),StartPosition: common.ConvertANTLRLineToPosition(1),})return adviceList, nil@@ -81,7 +82,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: "Prior backup cannot deal with mixed DDL and DML statements",- Code: int32(advisor.BuiltinPriorBackupCheck),+ Code: int32(code.BuiltinPriorBackupCheck),StartPosition: common.ConvertANTLRLineToPosition(1),})}@@ -109,7 +110,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: fmt.Sprintf("The statement type is not the same for all statements on the same table %q", key),- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: common.ConvertANTLRLineToPosition(1),})breakdiff --git a/backend/plugin/advisor/mssql/rule_column_maximum_varchar_length.go b/backend/plugin/advisor/mssql/rule_column_maximum_varchar_length.goindex 1b63a16379..62693698ef 100644--- a/backend/plugin/advisor/mssql/rule_column_maximum_varchar_length.go+++ b/backend/plugin/advisor/mssql/rule_column_maximum_varchar_length.go@@ -7,6 +7,8 @@ import ("math""strconv"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/tsql""github.com/pkg/errors"@@ -133,7 +135,7 @@ func (r *ColumnMaximumVarcharLengthRule) enterDataType(ctx *parser.Data_typeContif currentLength > r.maximum {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.VarcharLengthExceedsLimit.Int32(),+ Code: code.VarcharLengthExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The maximum varchar length is %d.", r.maximum),StartPosition: common.ConvertANTLRLineToPosition(line),diff --git a/backend/plugin/advisor/mssql/rule_column_no_null.go b/backend/plugin/advisor/mssql/rule_column_no_null.goindex 17c569dd63..cec549d8e8 100644--- a/backend/plugin/advisor/mssql/rule_column_no_null.go+++ b/backend/plugin/advisor/mssql/rule_column_no_null.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql")@@ -123,7 +124,7 @@ func (r *ColumnNoNullRule) exitCreateTable(_ *parser.Create_tableContext) {}r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.ColumnCannotNull.Int32(),+ Code: code.ColumnCannotNull.Int32(),Title: r.title,Content: fmt.Sprintf("Column [%s] is nullable, which is not allowed.", columnName),StartPosition: common.ConvertANTLRLineToPosition(r.currentTableColumnIsNullableLine[columnName]),@@ -195,7 +196,7 @@ func (r *ColumnNoNullRule) exitAlterTable(_ *parser.Alter_tableContext) {}r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.ColumnCannotNull.Int32(),+ Code: code.ColumnCannotNull.Int32(),Title: r.title,Content: fmt.Sprintf("Column [%s] is nullable, which is not allowed.", columnName),StartPosition: common.ConvertANTLRLineToPosition(r.currentTableColumnIsNullableLine[columnName]),diff --git a/backend/plugin/advisor/mssql/rule_column_require.go b/backend/plugin/advisor/mssql/rule_column_require.goindex 13ad25ee56..9b138a3311 100644--- a/backend/plugin/advisor/mssql/rule_column_require.go+++ b/backend/plugin/advisor/mssql/rule_column_require.go@@ -5,6 +5,8 @@ import ("fmt""slices"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/tsql""github.com/pkg/errors"@@ -152,7 +154,7 @@ func (r *ColumnRequireRule) exitCreateTable(ctx *parser.Create_tableContext) {for _, column := range missingColumns {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoRequiredColumn.Int32(),+ Code: code.NoRequiredColumn.Int32(),Title: r.title,Content: fmt.Sprintf("Table %s missing required column \"%s\"", r.currentOriginalTableName, column),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -173,7 +175,7 @@ func (r *ColumnRequireRule) enterAlterTable(ctx *parser.Alter_tableContext) {if _, ok := r.requireColumns[normalizedColumnName]; ok {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoRequiredColumn.Int32(),+ Code: code.NoRequiredColumn.Int32(),Title: r.title,Content: fmt.Sprintf("Table %s missing required column \"%s\"", tableName, normalizedColumnName),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_column_type_disallow_list.go b/backend/plugin/advisor/mssql/rule_column_type_disallow_list.goindex 6c8fdb04fa..acafaf0ee4 100644--- a/backend/plugin/advisor/mssql/rule_column_type_disallow_list.go+++ b/backend/plugin/advisor/mssql/rule_column_type_disallow_list.go@@ -5,6 +5,8 @@ import ("slices""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/tsql""github.com/pkg/errors"@@ -98,7 +100,7 @@ func (r *ColumnTypeDisallowListRule) enterDataType(ctx *parser.Data_typeContext)if slices.Contains(r.disallowTypes, formatedDataType) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisabledColumnType.Int32(),+ Code: code.DisabledColumnType.Int32(),Title: r.title,Content: "Column type " + formatedDataType + " is disallowed",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_function_disallow_create_or_alter.go b/backend/plugin/advisor/mssql/rule_function_disallow_create_or_alter.goindex 1ece1c40a5..1e9e8ebf8f 100644--- a/backend/plugin/advisor/mssql/rule_function_disallow_create_or_alter.go+++ b/backend/plugin/advisor/mssql/rule_function_disallow_create_or_alter.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")func init() {@@ -78,7 +79,7 @@ func (*FunctionDisallowCreateOrAlterRule) OnExit(_ antlr.ParserRuleContext, _ stfunc (r *FunctionDisallowCreateOrAlterRule) enterCreateOrAlterFunction(ctx *parser.Create_or_alter_functionContext) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisallowCreateFunction.Int32(),+ Code: code.DisallowCreateFunction.Int32(),Title: r.title,Content: "Creating or altering functions is prohibited",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_index_not_redundant.go b/backend/plugin/advisor/mssql/rule_index_not_redundant.goindex 84962b9c38..87b73372fe 100644--- a/backend/plugin/advisor/mssql/rule_index_not_redundant.go+++ b/backend/plugin/advisor/mssql/rule_index_not_redundant.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/tsql""github.com/pkg/errors"@@ -126,7 +128,7 @@ func (r *IndexNotRedundantRule) enterCreateIndex(ctx *parser.Create_indexContextr.AddAdvice(&storepb.Advice{Status: r.level,Title: r.title,- Code: advisor.RedundantIndex.Int32(),+ Code: code.RedundantIndex.Int32(),Content: fmt.Sprintf("Redundant indexes with the same prefix ('%s' and '%s') in '%s.%s' is not allowed",metaIdxName, statIdxName, findIdxKey.schemaName, findIdxKey.tblName),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_migration_compatibility.go b/backend/plugin/advisor/mssql/rule_migration_compatibility.goindex 796b3fc8b0..1742d59d1f 100644--- a/backend/plugin/advisor/mssql/rule_migration_compatibility.go+++ b/backend/plugin/advisor/mssql/rule_migration_compatibility.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code"tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql")@@ -150,7 +151,7 @@ func (r *MigrationCompatibilityRule) enterDropTable(ctx *parser.Drop_tableContexif _, ok := r.normalizedNewCreateTableNameMap[normalizedTableName]; !ok {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityDropSchema.Int32(),+ Code: advisorcode.CompatibilityDropSchema.Int32(),Title: r.title,Content: fmt.Sprintf("Drop table %s may cause incompatibility with the existing data and code", normalizedTableName),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -167,7 +168,7 @@ func (r *MigrationCompatibilityRule) enterDropSchema(ctx *parser.Drop_schemaContif _, ok := r.normalizedNewCreateSchemaNameMap[normalizedSchemaName]; !ok {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityDropSchema.Int32(),+ Code: advisorcode.CompatibilityDropSchema.Int32(),Title: r.title,Content: fmt.Sprintf("Drop schema %s may cause incompatibility with the existing data and code", normalizedSchemaName),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -182,7 +183,7 @@ func (r *MigrationCompatibilityRule) enterDropDatabase(ctx *parser.Drop_databaseif _, ok := r.normalizedNewCreateDatabaseNameMap[normalizedDatabaseName]; !ok {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityDropSchema.Int32(),+ Code: advisorcode.CompatibilityDropSchema.Int32(),Title: r.title,Content: fmt.Sprintf("Drop database %s may cause incompatibility with the existing data and code", normalizedDatabaseName),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -208,7 +209,7 @@ func (r *MigrationCompatibilityRule) enterAlterTable(ctx *parser.Alter_tableContplaceholder := strings.Join(allNormalizedDropColumnNames, ", ")r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityDropSchema.Int32(),+ Code: advisorcode.CompatibilityDropSchema.Int32(),Title: r.title,Content: fmt.Sprintf("Drop column %s may cause incompatibility with the existing data and code", placeholder),StartPosition: common.ConvertANTLRLineToPosition(ctx.COLUMN().GetSymbol().GetLine()),@@ -225,7 +226,7 @@ func (r *MigrationCompatibilityRule) enterAlterTable(ctx *parser.Alter_tableContr.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityAlterColumn.Int32(),+ Code: advisorcode.CompatibilityAlterColumn.Int32(),Title: r.title,Content: fmt.Sprintf("Alter COLUMN %s may cause incompatibility with the existing data and code", normalizedColumnName),StartPosition: common.ConvertANTLRLineToPosition(ctx.COLUMN().GetSymbol().GetLine()),@@ -235,22 +236,22 @@ func (r *MigrationCompatibilityRule) enterAlterTable(ctx *parser.Alter_tableContif v := ctx.Column_def_table_constraints(); v != nil {allColumnDefTableConstraints := v.AllColumn_def_table_constraint()for _, columnDefTableConstraint := range allColumnDefTableConstraints {- code := advisor.Ok+ code := advisorcode.Okoperation := ""tableConstraint := columnDefTableConstraint.Table_constraint()if tableConstraint == nil {continue}if tableConstraint.PRIMARY() != nil {- code = advisor.CompatibilityAddPrimaryKey+ code = advisorcode.CompatibilityAddPrimaryKeyoperation = "Add PRIMARY KEY"}if tableConstraint.UNIQUE() != nil {- code = advisor.CompatibilityAddUniqueKey+ code = advisorcode.CompatibilityAddUniqueKeyoperation = "Add UNIQUE KEY"}if tableConstraint.Check_constraint() != nil {- code = advisor.CompatibilityAddCheck+ code = advisorcode.CompatibilityAddCheckoperation = "Add CHECK"}r.AddAdvice(&storepb.Advice{@@ -267,7 +268,7 @@ func (r *MigrationCompatibilityRule) enterAlterTable(ctx *parser.Alter_tableContif ctx.FOREIGN() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityAddForeignKey.Int32(),+ Code: advisorcode.CompatibilityAddForeignKey.Int32(),Title: r.title,Content: "Add FOREIGN KEY WITH NO CHECK may cause incompatibility with the existing data and code",StartPosition: common.ConvertANTLRLineToPosition(ctx.FOREIGN().GetSymbol().GetLine()),@@ -277,7 +278,7 @@ func (r *MigrationCompatibilityRule) enterAlterTable(ctx *parser.Alter_tableContif len(ctx.AllCHECK()) == 1 {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityAddForeignKey.Int32(),+ Code: advisorcode.CompatibilityAddForeignKey.Int32(),Title: r.title,Content: "Add CHECK WITH NO CHECK may cause incompatibility with the existing data and code",StartPosition: common.ConvertANTLRLineToPosition(ctx.CHECK(0).GetSymbol().GetLine()),@@ -325,7 +326,7 @@ func (r *MigrationCompatibilityRule) enterExecuteBody(ctx *parser.Execute_bodyCo}r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityRenameTable.Int32(),+ Code: advisorcode.CompatibilityRenameTable.Int32(),Title: r.title,Content: "sp_rename may cause incompatibility with the existing data and code, and break scripts and stored procedures.",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_naming_identifier_no_keyword.go b/backend/plugin/advisor/mssql/rule_naming_identifier_no_keyword.goindex a5489d4904..04483f9873 100644--- a/backend/plugin/advisor/mssql/rule_naming_identifier_no_keyword.go+++ b/backend/plugin/advisor/mssql/rule_naming_identifier_no_keyword.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/tsql""github.com/pkg/errors"@@ -107,7 +109,7 @@ func (r *NamingIdentifierNoKeywordRule) enterID(ctx *parser.Id_Context) {if tsqlparser.IsTSQLReservedKeyword(normalizedID, false) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NameIsKeywordIdentifier.Int32(),+ Code: code.NameIsKeywordIdentifier.Int32(),Title: r.title,Content: fmt.Sprintf("Identifier [%s] is a keyword identifier and should be avoided.", normalizedID),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_naming_table.go b/backend/plugin/advisor/mssql/rule_naming_table.goindex f1b751c159..c9335da13a 100644--- a/backend/plugin/advisor/mssql/rule_naming_table.go+++ b/backend/plugin/advisor/mssql/rule_naming_table.go@@ -14,6 +14,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql")@@ -104,7 +105,7 @@ func (r *NamingTableRule) enterCreateTable(ctx *parser.Create_tableContext) {if !r.format.MatchString(tableName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`%s mismatches table naming convention, naming format should be %q`, tableName, r.format),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -113,7 +114,7 @@ func (r *NamingTableRule) enterCreateTable(ctx *parser.Create_tableContext) {if r.maxLength > 0 && len(tableName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`%s mismatches table naming convention, its length should be within %d characters`, tableName, r.maxLength),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -186,7 +187,7 @@ func (r *NamingTableRule) enterExecuteBody(ctx *parser.Execute_bodyContext) {if !r.format.MatchString(newTableName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`%s mismatches table naming convention, naming format should be %q`, newTableName, r.format),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -195,7 +196,7 @@ func (r *NamingTableRule) enterExecuteBody(ctx *parser.Execute_bodyContext) {if r.maxLength > 0 && len(newTableName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`%s mismatches table naming convention, its length should be within %d characters`, newTableName, r.maxLength),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_naming_table_no_keyword.go b/backend/plugin/advisor/mssql/rule_naming_table_no_keyword.goindex a36df1e1d2..a7d4b53cf2 100644--- a/backend/plugin/advisor/mssql/rule_naming_table_no_keyword.go+++ b/backend/plugin/advisor/mssql/rule_naming_table_no_keyword.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/tsql""github.com/pkg/errors"@@ -89,7 +91,7 @@ func (r *NamingTableNoKeywordRule) enterCreateTable(ctx *parser.Create_tableContif tsqlparser.IsTSQLReservedKeyword(normalizedTableName, false) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NameIsKeywordIdentifier.Int32(),+ Code: code.NameIsKeywordIdentifier.Int32(),Title: r.title,Content: fmt.Sprintf("Table name [%s] is a reserved keyword and should be avoided.", normalizedTableName),StartPosition: common.ConvertANTLRLineToPosition(tableName.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_procedure_disallow_create_or_alter.go b/backend/plugin/advisor/mssql/rule_procedure_disallow_create_or_alter.goindex 30e3f0efd6..2dbb53fe15 100644--- a/backend/plugin/advisor/mssql/rule_procedure_disallow_create_or_alter.go+++ b/backend/plugin/advisor/mssql/rule_procedure_disallow_create_or_alter.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")func init() {@@ -77,7 +78,7 @@ func (*ProcedureDisallowCreateOrAlterRule) OnExit(_ antlr.ParserRuleContext, _ sfunc (r *ProcedureDisallowCreateOrAlterRule) enterCreateOrAlterProcedure(ctx *parser.Create_or_alter_procedureContext) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisallowCreateProcedure.Int32(),+ Code: code.DisallowCreateProcedure.Int32(),Title: r.title,Content: "Creating or altering procedures is prohibited",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_select_no_select_all.go b/backend/plugin/advisor/mssql/rule_select_no_select_all.goindex 836faa7097..912b29d681 100644--- a/backend/plugin/advisor/mssql/rule_select_no_select_all.go+++ b/backend/plugin/advisor/mssql/rule_select_no_select_all.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -86,7 +87,7 @@ func (r *SelectNoSelectAllRule) enterSelectListElem(ctx *parser.Select_list_elemif v.STAR() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementSelectAll.Int32(),+ Code: code.StatementSelectAll.Int32(),Title: r.title,Content: "Avoid using SELECT *.",StartPosition: common.ConvertANTLRLineToPosition(v.STAR().GetSymbol().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_statement_disallow_cross_db_queries.go b/backend/plugin/advisor/mssql/rule_statement_disallow_cross_db_queries.goindex 36d18e83a7..4401ad925a 100644--- a/backend/plugin/advisor/mssql/rule_statement_disallow_cross_db_queries.go+++ b/backend/plugin/advisor/mssql/rule_statement_disallow_cross_db_queries.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/parser/tsql")@@ -90,7 +91,7 @@ func (r *DisallowCrossDBQueriesRule) enterTableSourceItem(ctx *parser.Table_sourif fullTblName, err := tsql.NormalizeFullTableName(fullTblnameCtx); err == nil && fullTblName.Database != "" && !strings.EqualFold(fullTblName.Database, r.curDB) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementDisallowCrossDBQueries.Int32(),+ Code: code.StatementDisallowCrossDBQueries.Int32(),Title: r.title,Content: fmt.Sprintf("Cross database queries (target databse: '%s', current database: '%s') are prohibited", fullTblName.Database, r.curDB),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_statement_disallow_mix_in_ddl.go b/backend/plugin/advisor/mssql/rule_statement_disallow_mix_in_ddl.goindex d06c304986..40ff06971b 100644--- a/backend/plugin/advisor/mssql/rule_statement_disallow_mix_in_ddl.go+++ b/backend/plugin/advisor/mssql/rule_statement_disallow_mix_in_ddl.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql")@@ -103,7 +104,7 @@ func (r *StatementDisallowMixInDDLRule) enterSQLClauses(ctx *parser.Sql_clausesCStatus: r.level,Title: r.title,Content: "Alter schema can only run DDL",- Code: advisor.StatementDisallowMixDDLDML.Int32(),+ Code: code.StatementDisallowMixDDLDML.Int32(),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),})}diff --git a/backend/plugin/advisor/mssql/rule_statement_disallow_mix_in_dml.go b/backend/plugin/advisor/mssql/rule_statement_disallow_mix_in_dml.goindex cabd5c85e4..a83bee5eb5 100644--- a/backend/plugin/advisor/mssql/rule_statement_disallow_mix_in_dml.go+++ b/backend/plugin/advisor/mssql/rule_statement_disallow_mix_in_dml.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql")@@ -103,7 +104,7 @@ func (r *StatementDisallowMixInDMLRule) enterSQLClauses(ctx *parser.Sql_clausesCStatus: r.level,Title: r.title,Content: "Data change can only run DML",- Code: advisor.StatementDisallowMixDDLDML.Int32(),+ Code: code.StatementDisallowMixDDLDML.Int32(),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),})}diff --git a/backend/plugin/advisor/mssql/rule_statement_where_disallow_functions_and_calculations.go b/backend/plugin/advisor/mssql/rule_statement_where_disallow_functions_and_calculations.goindex 083d7c41ad..1848bbdf39 100644--- a/backend/plugin/advisor/mssql/rule_statement_where_disallow_functions_and_calculations.go+++ b/backend/plugin/advisor/mssql/rule_statement_where_disallow_functions_and_calculations.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")func init() {@@ -131,7 +132,7 @@ func (r *DisallowFuncAndCalculationsRule) generateAdviceOnFunctionUsing(ctx antlr.hasTriggeredRule = truereturn &storepb.Advice{Status: r.level,- Code: advisor.StatementDisallowFunctionsAndCalculations.Int32(),+ Code: code.StatementDisallowFunctionsAndCalculations.Int32(),Title: r.title,Content: fmt.Sprintf("Calling function '%s' in 'WHERE' clause is not allowed", ctx.GetText()),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -145,7 +146,7 @@ func (r *DisallowFuncAndCalculationsRule) generateAdviceOnPerformingCalculationsr.hasTriggeredRule = truereturn &storepb.Advice{Status: r.level,- Code: advisor.StatementDisallowFunctionsAndCalculations.Int32(),+ Code: code.StatementDisallowFunctionsAndCalculations.Int32(),Title: r.title,Content: "Performing calculations in 'WHERE' clause is not allowed",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_statement_where_requirement_for_select.go b/backend/plugin/advisor/mssql/rule_statement_where_requirement_for_select.goindex 72a5d914bc..ca592f5237 100644--- a/backend/plugin/advisor/mssql/rule_statement_where_requirement_for_select.go+++ b/backend/plugin/advisor/mssql/rule_statement_where_requirement_for_select.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -86,7 +87,7 @@ func (r *WhereRequirementForSelectRule) enterQuerySpecification(ctx *parser.Querif ctx.WHERE() == nil && ctx.From_table_sources() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: "WHERE clause is required for SELETE statement.",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_statement_where_requirement_for_update_delete.go b/backend/plugin/advisor/mssql/rule_statement_where_requirement_for_update_delete.goindex 180c4e09b0..0945050fea 100644--- a/backend/plugin/advisor/mssql/rule_statement_where_requirement_for_update_delete.go+++ b/backend/plugin/advisor/mssql/rule_statement_where_requirement_for_update_delete.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -90,7 +91,7 @@ func (r *WhereRequirementForUpdateDeleteRule) enterDeleteStatement(ctx *parser.Dif ctx.WHERE() == nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: "WHERE clause is required for DELETE statement.",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -102,7 +103,7 @@ func (r *WhereRequirementForUpdateDeleteRule) enterUpdateStatement(ctx *parser.Uif ctx.WHERE() == nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: "WHERE clause is required for UPDATE statement.",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_table_disallow_ddl.go b/backend/plugin/advisor/mssql/rule_table_disallow_ddl.goindex 53f774a45d..56d1202c0c 100644--- a/backend/plugin/advisor/mssql/rule_table_disallow_ddl.go+++ b/backend/plugin/advisor/mssql/rule_table_disallow_ddl.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/tsql""github.com/pkg/errors"@@ -139,7 +141,7 @@ func (r *TableDisallowDDLRule) checkTableName(normalizedTableName string, line iif normalizedTableName == disallow {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableDisallowDDL.Int32(),+ Code: code.TableDisallowDDL.Int32(),Title: r.title,Content: fmt.Sprintf("DDL is disallowed on table %s.", normalizedTableName),StartPosition: common.ConvertANTLRLineToPosition(line),diff --git a/backend/plugin/advisor/mssql/rule_table_disallow_dml.go b/backend/plugin/advisor/mssql/rule_table_disallow_dml.goindex 927907a07f..232624ff9c 100644--- a/backend/plugin/advisor/mssql/rule_table_disallow_dml.go+++ b/backend/plugin/advisor/mssql/rule_table_disallow_dml.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/tsql""github.com/pkg/errors"@@ -149,7 +151,7 @@ func (r *TableDisallowDMLRule) checkTableName(normalizedTableName string, line iif normalizedTableName == disallow {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableDisallowDML.Int32(),+ Code: code.TableDisallowDML.Int32(),Title: r.title,Content: fmt.Sprintf("DML is disallowed on table %s.", normalizedTableName),StartPosition: common.ConvertANTLRLineToPosition(line),diff --git a/backend/plugin/advisor/mssql/rule_table_drop_naming_convention.go b/backend/plugin/advisor/mssql/rule_table_drop_naming_convention.goindex 49704a521e..4d244e76bf 100644--- a/backend/plugin/advisor/mssql/rule_table_drop_naming_convention.go+++ b/backend/plugin/advisor/mssql/rule_table_drop_naming_convention.go@@ -5,6 +5,8 @@ import ("fmt""regexp"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/tsql""github.com/pkg/errors"@@ -101,7 +103,7 @@ func (r *TableDropNamingConventionRule) enterDropTable(ctx *parser.Drop_tableConif !r.format.MatchString(normalizedTableName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableDropNamingConventionMismatch.Int32(),+ Code: code.TableDropNamingConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("[%s] mismatches drop table naming convention, naming format should be %q", normalizedTableName, r.format),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mssql/rule_table_no_foreign_key.go b/backend/plugin/advisor/mssql/rule_table_no_foreign_key.goindex ca5d18f7da..a86f398610 100644--- a/backend/plugin/advisor/mssql/rule_table_no_foreign_key.go+++ b/backend/plugin/advisor/mssql/rule_table_no_foreign_key.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/tsql""github.com/pkg/errors"@@ -190,7 +192,7 @@ func (r *TableNoForeignKeyRule) generateFinalAdvice() {if hasForeignKey {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableHasFK.Int32(),+ Code: code.TableHasFK.Int32(),Title: r.title,Content: fmt.Sprintf("FOREIGN KEY is not allowed in the table %s.", r.tableOriginalName[tableName]),StartPosition: common.ConvertANTLRLineToPosition(r.tableLine[tableName]),diff --git a/backend/plugin/advisor/mssql/rule_table_require_pk.go b/backend/plugin/advisor/mssql/rule_table_require_pk.goindex 3307add757..17f366e88d 100644--- a/backend/plugin/advisor/mssql/rule_table_require_pk.go+++ b/backend/plugin/advisor/mssql/rule_table_require_pk.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql")@@ -188,7 +189,7 @@ func (r *TableRequirePkRule) generateFinalAdvice() {if !hasPK {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableNoPK.Int32(),+ Code: code.TableNoPK.Int32(),Title: r.title,Content: fmt.Sprintf("Table %s requires PRIMARY KEY.", r.tableOriginalName[tableName]),StartPosition: common.ConvertANTLRLineToPosition(r.tableLine[tableName]),diff --git a/backend/plugin/advisor/mysql/rule_builtin_prior_backup_check.go b/backend/plugin/advisor/mysql/rule_builtin_prior_backup_check.goindex b6ca49e484..bee5b2b361 100644--- a/backend/plugin/advisor/mysql/rule_builtin_prior_backup_check.go+++ b/backend/plugin/advisor/mysql/rule_builtin_prior_backup_check.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -46,7 +47,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: fmt.Sprintf("The size of the SQL statements exceeds the maximum limit of %d bytes for backup", common.MaxSheetCheckSize),- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: nil,})}@@ -60,7 +61,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: "Prior backup cannot deal with mixed DDL and DML statements",- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: common.ConvertANTLRLineToPosition(stmt.BaseLine),})}@@ -72,7 +73,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: fmt.Sprintf("Need database %q to do prior backup but it does not exist", databaseName),- Code: advisor.DatabaseNotExists.Int32(),+ Code: code.DatabaseNotExists.Int32(),StartPosition: nil,})}@@ -98,7 +99,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: fmt.Sprintf("Prior backup cannot handle mixed DML statements on the same table %q", key),- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: nil,})breakdiff --git a/backend/plugin/advisor/mysql/rule_charset_allowlist.go b/backend/plugin/advisor/mysql/rule_charset_allowlist.goindex 8cb146846f..2d388f9b1b 100644--- a/backend/plugin/advisor/mysql/rule_charset_allowlist.go+++ b/backend/plugin/advisor/mysql/rule_charset_allowlist.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -130,7 +131,7 @@ func (r *CharsetAllowlistRule) checkCharset(charset string, lineNumber int) {if _, exists := r.allowList[charset]; charset != "" && !exists {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisabledCharset.Int32(),+ Code: code.DisabledCharset.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" used disabled charset '%s'", r.text, charset),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + lineNumber),diff --git a/backend/plugin/advisor/mysql/rule_collation_allowlist.go b/backend/plugin/advisor/mysql/rule_collation_allowlist.goindex 1a0ce34af8..68899868f1 100644--- a/backend/plugin/advisor/mysql/rule_collation_allowlist.go+++ b/backend/plugin/advisor/mysql/rule_collation_allowlist.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -229,7 +230,7 @@ func (r *CollationAllowlistRule) checkCollation(collation string, lineNumber intif _, exists := r.allowList[collation]; collation != "" && !exists {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisabledCollation.Int32(),+ Code: code.DisabledCollation.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" used disabled collation '%s'", r.text, collation),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + lineNumber),diff --git a/backend/plugin/advisor/mysql/rule_column_auto_increment_initial_value.go b/backend/plugin/advisor/mysql/rule_column_auto_increment_initial_value.goindex 0fc3fd6868..1eafd5523b 100644--- a/backend/plugin/advisor/mysql/rule_column_auto_increment_initial_value.go+++ b/backend/plugin/advisor/mysql/rule_column_auto_increment_initial_value.go@@ -5,6 +5,8 @@ import ("fmt""strconv"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -124,7 +126,7 @@ func (r *ColumnAutoIncrementInitialValueRule) checkCreateTable(ctx *mysql.Createif value != uint64(r.value) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.AutoIncrementColumnInitialValueNotMatch.Int32(),+ Code: code.AutoIncrementColumnInitialValueNotMatch.Int32(),Title: r.title,Content: fmt.Sprintf("The initial auto-increment value in table `%s` is %v, which doesn't equal %v", tableName, value, r.value),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -171,7 +173,7 @@ func (r *ColumnAutoIncrementInitialValueRule) checkAlterTable(ctx *mysql.AlterTaif value != uint64(r.value) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.AutoIncrementColumnInitialValueNotMatch.Int32(),+ Code: code.AutoIncrementColumnInitialValueNotMatch.Int32(),Title: r.title,Content: fmt.Sprintf("The initial auto-increment value in table `%s` is %v, which doesn't equal %v", tableName, value, r.value),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_auto_increment_must_integer.go b/backend/plugin/advisor/mysql/rule_column_auto_increment_must_integer.goindex 7c33c2d1e7..ef591c1c22 100644--- a/backend/plugin/advisor/mysql/rule_column_auto_increment_must_integer.go+++ b/backend/plugin/advisor/mysql/rule_column_auto_increment_must_integer.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -174,7 +176,7 @@ func (r *ColumnAutoIncrementMustIntegerRule) checkFieldDefinition(tableName, colif !r.isAutoIncrementColumnIsInteger(ctx) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.AutoIncrementColumnNotInteger.Int32(),+ Code: code.AutoIncrementColumnNotInteger.Int32(),Title: r.title,Content: fmt.Sprintf("Auto-increment column `%s`.`%s` requires integer type", tableName, columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_auto_increment_must_unsigned.go b/backend/plugin/advisor/mysql/rule_column_auto_increment_must_unsigned.goindex c692becc0f..3013bce358 100644--- a/backend/plugin/advisor/mysql/rule_column_auto_increment_must_unsigned.go+++ b/backend/plugin/advisor/mysql/rule_column_auto_increment_must_unsigned.go@@ -5,6 +5,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -168,7 +170,7 @@ func (r *ColumnAutoIncrementMustUnsignedRule) checkFieldDefinition(tableName, coif !r.isAutoIncrementColumnIsUnsigned(ctx) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.AutoIncrementColumnSigned.Int32(),+ Code: code.AutoIncrementColumnSigned.Int32(),Title: r.title,Content: fmt.Sprintf("Auto-increment column `%s`.`%s` is not UNSIGNED type", tableName, columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_comment_convention.go b/backend/plugin/advisor/mysql/rule_column_comment_convention.goindex 5c4d2b645f..519108b4c7 100644--- a/backend/plugin/advisor/mysql/rule_column_comment_convention.go+++ b/backend/plugin/advisor/mysql/rule_column_comment_convention.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -196,7 +197,7 @@ func (r *ColumnCommentConventionRule) checkFieldDefinition(tableName, columnNameif r.payload.MaxLength >= 0 && len(comment) > r.payload.MaxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CommentTooLong.Int32(),+ Code: code.CommentTooLong.Int32(),Title: r.title,Content: fmt.Sprintf("The length of column `%s`.`%s` comment should be within %d characters", tableName, columnName, r.payload.MaxLength),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -207,7 +208,7 @@ func (r *ColumnCommentConventionRule) checkFieldDefinition(tableName, columnNameif classification, _ := common.GetClassificationAndUserComment(comment, r.classificationConfig); classification == "" {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CommentMissingClassification.Int32(),+ Code: code.CommentMissingClassification.Int32(),Title: r.title,Content: fmt.Sprintf("Column `%s`.`%s` comment requires classification", tableName, columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -221,7 +222,7 @@ func (r *ColumnCommentConventionRule) checkFieldDefinition(tableName, columnNameif len(comment) == 0 && r.payload.Required {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CommentEmpty.Int32(),+ Code: code.CommentEmpty.Int32(),Title: r.title,Content: fmt.Sprintf("Column `%s`.`%s` requires comments", tableName, columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_current_time_count_limit.go b/backend/plugin/advisor/mysql/rule_column_current_time_count_limit.goindex 4bffd006b6..a9f0938cda 100644--- a/backend/plugin/advisor/mysql/rule_column_current_time_count_limit.go+++ b/backend/plugin/advisor/mysql/rule_column_current_time_count_limit.go@@ -5,6 +5,8 @@ import ("fmt""slices"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -268,7 +270,7 @@ func (r *ColumnCurrentTimeCountLimitRule) generateAdvice() {if table.defaultCurrentTimeCount > maxDefaultCurrentTimeColumCount {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DefaultCurrentTimeColumnCountExceedsLimit.Int32(),+ Code: code.DefaultCurrentTimeColumnCountExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("Table `%s` has %d DEFAULT CURRENT_TIMESTAMP() columns. The count greater than %d.", table.tableName, table.defaultCurrentTimeCount, maxDefaultCurrentTimeColumCount),StartPosition: common.ConvertANTLRLineToPosition(table.line),@@ -277,7 +279,7 @@ func (r *ColumnCurrentTimeCountLimitRule) generateAdvice() {if table.onUpdateCurrentTimeCount > maxOnUpdateCurrentTimeColumnCount {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.OnUpdateCurrentTimeColumnCountExceedsLimit.Int32(),+ Code: code.OnUpdateCurrentTimeColumnCountExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("Table `%s` has %d ON UPDATE CURRENT_TIMESTAMP() columns. The count greater than %d.", table.tableName, table.onUpdateCurrentTimeCount, maxOnUpdateCurrentTimeColumnCount),StartPosition: common.ConvertANTLRLineToPosition(table.line),diff --git a/backend/plugin/advisor/mysql/rule_column_disallow_changing.go b/backend/plugin/advisor/mysql/rule_column_disallow_changing.goindex 4666ba5882..67d41982fd 100644--- a/backend/plugin/advisor/mysql/rule_column_disallow_changing.go+++ b/backend/plugin/advisor/mysql/rule_column_disallow_changing.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -119,7 +121,7 @@ func (r *ColumnDisallowChangingRule) checkAlterTable(ctx *mysql.AlterTableContexif item.CHANGE_SYMBOL() != nil && item.ColumnInternalRef() != nil && item.Identifier() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.UseChangeColumnStatement.Int32(),+ Code: code.UseChangeColumnStatement.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" contains CHANGE COLUMN statement", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_disallow_changing_order.go b/backend/plugin/advisor/mysql/rule_column_disallow_changing_order.goindex 6e40a2e38a..7f60378d71 100644--- a/backend/plugin/advisor/mysql/rule_column_disallow_changing_order.go+++ b/backend/plugin/advisor/mysql/rule_column_disallow_changing_order.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -129,7 +131,7 @@ func (r *ColumnDisallowChangingOrderRule) checkAlterTable(ctx *mysql.AlterTableCif item.Place() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.ChangeColumnOrder.Int32(),+ Code: code.ChangeColumnOrder.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" changes column order", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_disallow_changing_type.go b/backend/plugin/advisor/mysql/rule_column_disallow_changing_type.goindex 6d22a13b16..d9142336d7 100644--- a/backend/plugin/advisor/mysql/rule_column_disallow_changing_type.go+++ b/backend/plugin/advisor/mysql/rule_column_disallow_changing_type.go@@ -5,6 +5,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -177,7 +179,7 @@ func (r *ColumnDisallowChangingTypeRule) changeColumnType(tableName, columnNameif normalizeColumnType(column.Type()) != normalizeColumnType(tp) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.ChangeColumnType.Int32(),+ Code: code.ChangeColumnType.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" changes column type", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + dataType.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_disallow_drop.go b/backend/plugin/advisor/mysql/rule_column_disallow_drop.goindex df87a8eb56..b3f680ce4c 100644--- a/backend/plugin/advisor/mysql/rule_column_disallow_drop.go+++ b/backend/plugin/advisor/mysql/rule_column_disallow_drop.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -107,7 +109,7 @@ func (r *ColumnDisallowDropRule) checkAlterTable(ctx *mysql.AlterTableContext) {columnName := mysqlparser.NormalizeMySQLColumnInternalRef(item.ColumnInternalRef())r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DropColumn.Int32(),+ Code: code.DropColumn.Int32(),Title: r.title,Content: fmt.Sprintf("drops column \"%s\" of table \"%s\"", columnName, tableName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + item.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_disallow_drop_in_index.go b/backend/plugin/advisor/mysql/rule_column_disallow_drop_in_index.goindex 511bf9f7cb..65606592ca 100644--- a/backend/plugin/advisor/mysql/rule_column_disallow_drop_in_index.go+++ b/backend/plugin/advisor/mysql/rule_column_disallow_drop_in_index.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -173,7 +175,7 @@ func (r *ColumnDisallowDropInIndexRule) checkAlterTable(ctx *mysql.AlterTableConif !r.canDrop(tableName, columnName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DropIndexColumn.Int32(),+ Code: code.DropIndexColumn.Int32(),Title: r.title,Content: fmt.Sprintf("`%s`.`%s` cannot drop index column", tableName, columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + item.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_disallow_set_charset.go b/backend/plugin/advisor/mysql/rule_column_disallow_set_charset.goindex 0d305f34d0..6f4c8fa0bc 100644--- a/backend/plugin/advisor/mysql/rule_column_disallow_set_charset.go+++ b/backend/plugin/advisor/mysql/rule_column_disallow_set_charset.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -122,7 +124,7 @@ func (r *ColumnDisallowSetCharsetRule) checkCreateTable(ctx *mysql.CreateTableCoif !r.checkCharset(charset) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.SetColumnCharset.Int32(),+ Code: code.SetColumnCharset.Int32(),Title: r.title,Content: fmt.Sprintf("Disallow set column charset but \"%s\" does", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -201,7 +203,7 @@ func (r *ColumnDisallowSetCharsetRule) checkAlterTable(ctx *mysql.AlterTableContif !r.checkCharset(charsetName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.SetColumnCharset.Int32(),+ Code: code.SetColumnCharset.Int32(),Title: r.title,Content: fmt.Sprintf("Disallow set column charset but \"%s\" does", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_maximum_character_length.go b/backend/plugin/advisor/mysql/rule_column_maximum_character_length.goindex 45cbc42004..1b5727d0ac 100644--- a/backend/plugin/advisor/mysql/rule_column_maximum_character_length.go+++ b/backend/plugin/advisor/mysql/rule_column_maximum_character_length.go@@ -5,6 +5,8 @@ import ("fmt""strconv"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -127,7 +129,7 @@ func (r *ColumnMaximumCharacterLengthRule) checkCreateTable(ctx *mysql.CreateTabif r.maximum > 0 && charLength > r.maximum {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CharLengthExceedsLimit.Int32(),+ Code: code.CharLengthExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The length of the CHAR column `%s.%s` is bigger than %d, please use VARCHAR instead", tableName, columnName, r.maximum),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + tableElement.ColumnDefinition().GetStart().GetLine()),@@ -214,7 +216,7 @@ func (r *ColumnMaximumCharacterLengthRule) checkAlterTable(ctx *mysql.AlterTableif charLength, ok := charLengthMap[columnName]; ok && r.maximum > 0 && charLength > r.maximum {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CharLengthExceedsLimit.Int32(),+ Code: code.CharLengthExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The length of the CHAR column `%s.%s` is bigger than %d, please use VARCHAR instead", tableName, columnName, r.maximum),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_maximum_varchar_length.go b/backend/plugin/advisor/mysql/rule_column_maximum_varchar_length.goindex 7fd6225c21..e324130166 100644--- a/backend/plugin/advisor/mysql/rule_column_maximum_varchar_length.go+++ b/backend/plugin/advisor/mysql/rule_column_maximum_varchar_length.go@@ -5,6 +5,8 @@ import ("fmt""strconv"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -125,7 +127,7 @@ func (r *VarcharLengthRule) checkCreateTable(ctx *mysql.CreateTableContext) {if r.maximum > 0 && length > r.maximum {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.VarcharLengthExceedsLimit.Int32(),+ Code: code.VarcharLengthExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The length of the VARCHAR column `%s.%s` is bigger than %d", tableName, columnName, r.maximum),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + tableElement.ColumnDefinition().GetStart().GetLine()),@@ -209,7 +211,7 @@ func (r *VarcharLengthRule) checkAlterTable(ctx *mysql.AlterTableContext) {if length, ok := varcharLengthMap[columnName]; ok && r.maximum > 0 && length > r.maximum {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.VarcharLengthExceedsLimit.Int32(),+ Code: code.VarcharLengthExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The length of the VARCHAR column `%s.%s` is bigger than %d", tableName, columnName, r.maximum),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_no_null.go b/backend/plugin/advisor/mysql/rule_column_no_null.goindex 759af310b2..32d3884da9 100644--- a/backend/plugin/advisor/mysql/rule_column_no_null.go+++ b/backend/plugin/advisor/mysql/rule_column_no_null.go@@ -13,6 +13,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -138,7 +139,7 @@ func (r *ColumnNoNullRule) generateAdvice() {if col != nil && col.Nullable() {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.ColumnCannotNull.Int32(),+ Code: code.ColumnCannotNull.Int32(),Title: r.title,Content: fmt.Sprintf("`%s`.`%s` cannot have NULL value", column.tableName, column.columnName),StartPosition: common.ConvertANTLRLineToPosition(column.line),diff --git a/backend/plugin/advisor/mysql/rule_column_require_charset.go b/backend/plugin/advisor/mysql/rule_column_require_charset.goindex 9cd06ab44d..86ba84969c 100644--- a/backend/plugin/advisor/mysql/rule_column_require_charset.go+++ b/backend/plugin/advisor/mysql/rule_column_require_charset.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -114,7 +116,7 @@ func (r *ColumnRequireCharsetRule) checkCreateTable(ctx *mysql.CreateTableContexif dataType.CharsetWithOptBinary() == nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoCharset.Int32(),+ Code: code.NoCharset.Int32(),Title: r.title,Content: fmt.Sprintf("Column %s does not have a character set specified", columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + columnDefinition.GetStart().GetLine()),@@ -140,7 +142,7 @@ func (r *ColumnRequireCharsetRule) checkAlterTable(ctx *mysql.AlterTableContext)if dataType.CharsetWithOptBinary() == nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoCharset.Int32(),+ Code: code.NoCharset.Int32(),Title: r.title,Content: fmt.Sprintf("Column %s does not have a character set specified", columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + alterListItem.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_require_collation.go b/backend/plugin/advisor/mysql/rule_column_require_collation.goindex 8072e92c3d..691b1e9db5 100644--- a/backend/plugin/advisor/mysql/rule_column_require_collation.go+++ b/backend/plugin/advisor/mysql/rule_column_require_collation.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -113,7 +115,7 @@ func (r *ColumnRequireCollationRule) checkCreateTable(ctx *mysql.CreateTableContif columnDefinition.FieldDefinition().Collate() == nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoCollation.Int32(),+ Code: code.NoCollation.Int32(),Title: r.title,Content: fmt.Sprintf("Column %s does not have a collation specified", columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + columnDefinition.GetStart().GetLine()),@@ -139,7 +141,7 @@ func (r *ColumnRequireCollationRule) checkAlterTable(ctx *mysql.AlterTableContexif alterListItem.FieldDefinition().Collate() == nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoCollation.Int32(),+ Code: code.NoCollation.Int32(),Title: r.title,Content: fmt.Sprintf("Column %s does not have a collation specified", columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + alterListItem.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_require_default.go b/backend/plugin/advisor/mysql/rule_column_require_default.goindex 73f21a4db8..1805c22731 100644--- a/backend/plugin/advisor/mysql/rule_column_require_default.go+++ b/backend/plugin/advisor/mysql/rule_column_require_default.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -175,7 +177,7 @@ func (r *ColumnRequireDefaultRule) checkFieldDefinition(tableName, columnName stif !r.hasDefault(ctx) && r.columnNeedDefault(ctx) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoDefault.Int32(),+ Code: code.NoDefault.Int32(),Title: r.title,Content: fmt.Sprintf("Column `%s`.`%s` doesn't have DEFAULT.", tableName, columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_required.go b/backend/plugin/advisor/mysql/rule_column_required.goindex cea8021a8e..40f227f7a6 100644--- a/backend/plugin/advisor/mysql/rule_column_required.go+++ b/backend/plugin/advisor/mysql/rule_column_required.go@@ -6,6 +6,8 @@ import ("slices""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -212,7 +214,7 @@ func (r *ColumnRequiredRule) generateAdviceList() []*storepb.Advice {slices.Sort(missingColumns)r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoRequiredColumn.Int32(),+ Code: code.NoRequiredColumn.Int32(),Title: r.title,Content: fmt.Sprintf("Table `%s` requires columns: %s", tableName, strings.Join(missingColumns, ", ")),StartPosition: common.ConvertANTLRLineToPosition(r.line[tableName]),diff --git a/backend/plugin/advisor/mysql/rule_column_set_default_for_not_null.go b/backend/plugin/advisor/mysql/rule_column_set_default_for_not_null.goindex 50ce744ad3..0ad61faef8 100644--- a/backend/plugin/advisor/mysql/rule_column_set_default_for_not_null.go+++ b/backend/plugin/advisor/mysql/rule_column_set_default_for_not_null.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -150,7 +152,7 @@ func (r *ColumnSetDefaultForNotNullRule) checkCreateTable(ctx *mysql.CreateTableif !r.canNull(field) && !r.hasDefault(field) && r.columnNeedDefault(field) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NotNullColumnWithNoDefault.Int32(),+ Code: code.NotNullColumnWithNoDefault.Int32(),Title: r.title,Content: fmt.Sprintf("Column `%s`.`%s` is NOT NULL but doesn't have DEFAULT", tableName, columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + tableElement.ColumnDefinition().GetStart().GetLine()),@@ -163,7 +165,7 @@ func (r *ColumnSetDefaultForNotNullRule) checkFieldDefinition(tableName, columnNif !r.canNull(ctx) && !r.hasDefault(ctx) && r.columnNeedDefault(ctx) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NotNullColumnWithNoDefault.Int32(),+ Code: code.NotNullColumnWithNoDefault.Int32(),Title: r.title,Content: fmt.Sprintf("Column `%s`.`%s` is NOT NULL but doesn't have DEFAULT", tableName, columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_column_type_disallow_list.go b/backend/plugin/advisor/mysql/rule_column_type_disallow_list.goindex f174cd4d54..9ddf0424cb 100644--- a/backend/plugin/advisor/mysql/rule_column_type_disallow_list.go+++ b/backend/plugin/advisor/mysql/rule_column_type_disallow_list.go@@ -5,6 +5,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -142,7 +144,7 @@ func (r *ColumnTypeDisallowListRule) checkFieldDefinition(tableName, columnNameif _, exists := r.typeRestriction[columnType]; exists {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisabledColumnType.Int32(),+ Code: code.DisabledColumnType.Int32(),Title: r.title,Content: fmt.Sprintf("Disallow column type %s but column `%s`.`%s` is", columnType, tableName, columnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_database_drop_empty_db.go b/backend/plugin/advisor/mysql/rule_database_drop_empty_db.goindex a749231725..228d1c1e41 100644--- a/backend/plugin/advisor/mysql/rule_database_drop_empty_db.go+++ b/backend/plugin/advisor/mysql/rule_database_drop_empty_db.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -103,7 +105,7 @@ func (r *DatabaseDropEmptyDBRule) checkDropDatabase(ctx *mysql.DropDatabaseConteif r.originCatalog.DatabaseName() != dbName {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NotCurrentDatabase.Int32(),+ Code: code.NotCurrentDatabase.Int32(),Title: r.title,Content: fmt.Sprintf("Database `%s` that is trying to be deleted is not the current database `%s`", dbName, r.originCatalog.DatabaseName()),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -111,7 +113,7 @@ func (r *DatabaseDropEmptyDBRule) checkDropDatabase(ctx *mysql.DropDatabaseConte} else if !r.originCatalog.HasNoTable() {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DatabaseNotEmpty.Int32(),+ Code: code.DatabaseNotEmpty.Int32(),Title: r.title,Content: fmt.Sprintf("Database `%s` is not allowed to drop if not empty", dbName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_disallow_procedure.go b/backend/plugin/advisor/mysql/rule_disallow_procedure.goindex e0862846ce..d282fad943 100644--- a/backend/plugin/advisor/mysql/rule_disallow_procedure.go+++ b/backend/plugin/advisor/mysql/rule_disallow_procedure.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -99,12 +100,12 @@ func (r *ProcedureDisallowCreateRule) checkCreateProcedure(ctx *mysql.CreateProcif !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {return}- code := advisor.Ok+ code := advisorcode.Okif ctx.ProcedureName() != nil {- code = advisor.DisallowCreateProcedure+ code = advisorcode.DisallowCreateProcedure}- if code != advisor.Ok {+ if code != advisorcode.Ok {r.AddAdvice(&storepb.Advice{Status: r.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/mysql/rule_event_disallow_create.go b/backend/plugin/advisor/mysql/rule_event_disallow_create.goindex 9a0bce31ec..857008f8f5 100644--- a/backend/plugin/advisor/mysql/rule_event_disallow_create.go+++ b/backend/plugin/advisor/mysql/rule_event_disallow_create.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -98,12 +99,12 @@ func (r *EventDisallowCreateRule) checkCreateEvent(ctx *mysql.CreateEventContextif !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {return}- code := advisor.Ok+ code := advisorcode.Okif ctx.EventName() != nil {- code = advisor.DisallowCreateEvent+ code = advisorcode.DisallowCreateEvent}- if code != advisor.Ok {+ if code != advisorcode.Ok {r.AddAdvice(&storepb.Advice{Status: r.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/mysql/rule_function_disallow_create.go b/backend/plugin/advisor/mysql/rule_function_disallow_create.goindex ea881b2a0b..62d7e99c5b 100644--- a/backend/plugin/advisor/mysql/rule_function_disallow_create.go+++ b/backend/plugin/advisor/mysql/rule_function_disallow_create.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -98,12 +99,12 @@ func (r *FunctionDisallowCreateRule) checkCreateFunction(ctx *mysql.CreateFunctiif !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {return}- code := advisor.Ok+ code := advisorcode.Okif ctx.FunctionName() != nil {- code = advisor.DisallowCreateFunction+ code = advisorcode.DisallowCreateFunction}- if code != advisor.Ok {+ if code != advisorcode.Ok {r.AddAdvice(&storepb.Advice{Status: r.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/mysql/rule_function_disallowed_list.go b/backend/plugin/advisor/mysql/rule_function_disallowed_list.goindex de464253e3..e1eff2b4d1 100644--- a/backend/plugin/advisor/mysql/rule_function_disallowed_list.go+++ b/backend/plugin/advisor/mysql/rule_function_disallowed_list.go@@ -6,6 +6,8 @@ import ("slices""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -114,7 +116,7 @@ func (r *FunctionDisallowedListRule) checkFunctionCall(ctx *mysql.FunctionCallCoif slices.Contains(r.disallowList, strings.ToUpper(functionName)) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisabledFunction.Int32(),+ Code: code.DisabledFunction.Int32(),Title: r.title,Content: fmt.Sprintf("Function \"%s\" is disallowed, but \"%s\" uses", functionName, r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_index_key_number_limit.go b/backend/plugin/advisor/mysql/rule_index_key_number_limit.goindex fe7c683940..87b2a7183d 100644--- a/backend/plugin/advisor/mysql/rule_index_key_number_limit.go+++ b/backend/plugin/advisor/mysql/rule_index_key_number_limit.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -151,7 +153,7 @@ func (r *IndexKeyNumberLimitRule) handleConstraintDef(tableName string, ctx mysqif r.max > 0 && len(columnList) > r.max {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexKeyNumberExceedsLimit.Int32(),+ Code: code.IndexKeyNumberExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The number of index `%s` in table `%s` should be not greater than %d", indexName, tableName, r.max),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -185,7 +187,7 @@ func (r *IndexKeyNumberLimitRule) checkCreateIndex(ctx *mysql.CreateIndexContextif r.max > 0 && len(columnList) > r.max {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexKeyNumberExceedsLimit.Int32(),+ Code: code.IndexKeyNumberExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The number of index `%s` in table `%s` should be not greater than %d", indexName, tableName, r.max),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_index_no_duplicate_column.go b/backend/plugin/advisor/mysql/rule_index_no_duplicate_column.goindex 8dffba1c36..1dd6d61bed 100644--- a/backend/plugin/advisor/mysql/rule_index_no_duplicate_column.go+++ b/backend/plugin/advisor/mysql/rule_index_no_duplicate_column.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -189,7 +191,7 @@ func (r *IndexNoDuplicateColumnRule) checkCreateIndex(ctx *mysql.CreateIndexContif column, duplicate := r.hasDuplicateColumn(columnList); duplicate {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DuplicateColumnInIndex.Int32(),+ Code: code.DuplicateColumnInIndex.Int32(),Title: r.title,Content: fmt.Sprintf("%s`%s` has duplicate column `%s`.`%s`", indexType, indexName, tableName, column),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -241,7 +243,7 @@ func (r *IndexNoDuplicateColumnRule) handleConstraintDef(tableName string, ctx mif column, duplicate := r.hasDuplicateColumn(columnList); duplicate {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DuplicateColumnInIndex.Int32(),+ Code: code.DuplicateColumnInIndex.Int32(),Title: r.title,Content: fmt.Sprintf("%s`%s` has duplicate column `%s`.`%s`", indexType, indexName, tableName, column),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_index_pk_type.go b/backend/plugin/advisor/mysql/rule_index_pk_type.goindex 5ed5d196fa..d41d8ba5b8 100644--- a/backend/plugin/advisor/mysql/rule_index_pk_type.go+++ b/backend/plugin/advisor/mysql/rule_index_pk_type.go@@ -5,6 +5,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -223,7 +225,7 @@ func (r *IndexPkTypeRule) addAdvice(tableName, columnName, columnType string, liif !strings.EqualFold(columnType, "INT") && !strings.EqualFold(columnType, "BIGINT") {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexPKType.Int32(),+ Code: code.IndexPKType.Int32(),Title: r.title,Content: fmt.Sprintf("Columns in primary key must be INT/BIGINT but `%s`.`%s` is %s", tableName, columnName, columnType),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),diff --git a/backend/plugin/advisor/mysql/rule_index_primary_key_type_allowlist.go b/backend/plugin/advisor/mysql/rule_index_primary_key_type_allowlist.goindex 6f0899b101..5ac678661d 100644--- a/backend/plugin/advisor/mysql/rule_index_primary_key_type_allowlist.go+++ b/backend/plugin/advisor/mysql/rule_index_primary_key_type_allowlist.go@@ -5,6 +5,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -207,7 +209,7 @@ func (r *IndexPrimaryKeyTypeAllowlistRule) checkFieldDefinition(tableName, columif _, exists := r.allowlist[columnType]; !exists {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexPKType.Int32(),+ Code: code.IndexPKType.Int32(),Title: r.title,Content: fmt.Sprintf("The column `%s` in table `%s` is one of the primary key, but its type \"%s\" is not in allowlist", columnName, tableName, columnType),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -236,7 +238,7 @@ func (r *IndexPrimaryKeyTypeAllowlistRule) checkConstraintDef(tableName string,if _, exists := r.allowlist[columnType]; !exists {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexPKType.Int32(),+ Code: code.IndexPKType.Int32(),Title: r.title,Content: fmt.Sprintf("The column `%s` in table `%s` is one of the primary key, but its type \"%s\" is not in allowlist", columnName, tableName, columnType),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_index_total_number_limit.go b/backend/plugin/advisor/mysql/rule_index_total_number_limit.goindex 4bebbe53b8..77c4d51f78 100644--- a/backend/plugin/advisor/mysql/rule_index_total_number_limit.go+++ b/backend/plugin/advisor/mysql/rule_index_total_number_limit.go@@ -5,6 +5,8 @@ import ("fmt""slices"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -134,7 +136,7 @@ func (r *IndexTotalNumberLimitRule) generateAdvice() []*storepb.Advice {if tableInfo != nil && tableInfo.CountIndex() > r.max {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexCountExceedsLimit.Int32(),+ Code: code.IndexCountExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The count of index in table `%s` should be no more than %d, but found %d", table.name, r.max, tableInfo.CountIndex()),StartPosition: common.ConvertANTLRLineToPosition(table.line),diff --git a/backend/plugin/advisor/mysql/rule_index_type_allow_list.go b/backend/plugin/advisor/mysql/rule_index_type_allow_list.goindex 26f1e0c45c..e117ff1c12 100644--- a/backend/plugin/advisor/mysql/rule_index_type_allow_list.go+++ b/backend/plugin/advisor/mysql/rule_index_type_allow_list.go@@ -5,6 +5,8 @@ import ("fmt""slices"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -189,7 +191,7 @@ func (r *IndexTypeAllowListRule) validateIndexType(indexType string, line int) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexTypeNotAllowed.Int32(),+ Code: code.IndexTypeNotAllowed.Int32(),Title: r.title,Content: fmt.Sprintf("Index type `%s` is not allowed", indexType),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + line),diff --git a/backend/plugin/advisor/mysql/rule_index_type_no_blob.go b/backend/plugin/advisor/mysql/rule_index_type_no_blob.goindex d2d10d9664..753c41ce29 100644--- a/backend/plugin/advisor/mysql/rule_index_type_no_blob.go+++ b/backend/plugin/advisor/mysql/rule_index_type_no_blob.go@@ -5,6 +5,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -272,7 +274,7 @@ func (r *IndexTypeNoBlobRule) addAdvice(tableName, columnName, columnType stringif r.isBlob(columnType) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexTypeNoBlob.Int32(),+ Code: code.IndexTypeNoBlob.Int32(),Title: r.title,Content: fmt.Sprintf("Columns in index must not be BLOB but `%s`.`%s` is %s", tableName, columnName, columnType),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + lineNumber),diff --git a/backend/plugin/advisor/mysql/rule_insert_disallow_order_by_rand.go b/backend/plugin/advisor/mysql/rule_insert_disallow_order_by_rand.goindex 889f9ca5db..efb51e4af6 100644--- a/backend/plugin/advisor/mysql/rule_insert_disallow_order_by_rand.go+++ b/backend/plugin/advisor/mysql/rule_insert_disallow_order_by_rand.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -129,7 +130,7 @@ func (r *InsertDisallowOrderByRandRule) checkQueryExpression(ctx *mysql.QueryExpif strings.EqualFold(text, RandFn) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.InsertUseOrderByRand.Int32(),+ Code: code.InsertUseOrderByRand.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" uses ORDER BY RAND in the INSERT statement", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_insert_must_specify_column.go b/backend/plugin/advisor/mysql/rule_insert_must_specify_column.goindex 7e8a198b7c..eee753b4a3 100644--- a/backend/plugin/advisor/mysql/rule_insert_must_specify_column.go+++ b/backend/plugin/advisor/mysql/rule_insert_must_specify_column.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -119,7 +120,7 @@ func (r *InsertMustSpecifyColumnRule) checkInsertStatement(ctx *mysql.InsertStat}r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.InsertNotSpecifyColumn.Int32(),+ Code: code.InsertNotSpecifyColumn.Int32(),Title: r.title,Content: fmt.Sprintf("The INSERT statement must specify columns but \"%s\" does not", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -130,7 +131,7 @@ func (r *InsertMustSpecifyColumnRule) checkSelectItemList(ctx *mysql.SelectItemLif r.hasSelect && ctx.MULT_OPERATOR() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.InsertNotSpecifyColumn.Int32(),+ Code: code.InsertNotSpecifyColumn.Int32(),Title: r.title,Content: fmt.Sprintf("The INSERT statement must specify columns but \"%s\" does not", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_insert_row_limit.go b/backend/plugin/advisor/mysql/rule_insert_row_limit.goindex 591880fae3..d7d95f06d9 100644--- a/backend/plugin/advisor/mysql/rule_insert_row_limit.go+++ b/backend/plugin/advisor/mysql/rule_insert_row_limit.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -140,7 +141,7 @@ func (r *InsertRowLimitRule) handleInsertQueryExpression(ctx mysql.IInsertQueryEif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.InsertTooManyRows.Int32(),+ Code: code.InsertTooManyRows.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" dry runs failed: %s", r.text, err.Error()),StartPosition: common.ConvertANTLRLineToPosition(r.line),@@ -151,7 +152,7 @@ func (r *InsertRowLimitRule) handleInsertQueryExpression(ctx mysql.IInsertQueryEif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: r.title,Content: fmt.Sprintf("failed to get row count for \"%s\": %s", r.text, err.Error()),StartPosition: common.ConvertANTLRLineToPosition(r.line),@@ -159,7 +160,7 @@ func (r *InsertRowLimitRule) handleInsertQueryExpression(ctx mysql.IInsertQueryE} else if rowCount > int64(r.maxRow) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.InsertTooManyRows.Int32(),+ Code: code.InsertTooManyRows.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" inserts %d rows. The count exceeds %d.", r.text, rowCount, r.maxRow),StartPosition: common.ConvertANTLRLineToPosition(r.line),@@ -182,7 +183,7 @@ func (r *InsertRowLimitRule) handleNoInsertQueryExpression(ctx mysql.IInsertStatif len(allValues) > r.maxRow {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.InsertTooManyRows.Int32(),+ Code: code.InsertTooManyRows.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" inserts %d rows. The count exceeds %d.", r.text, len(allValues), r.maxRow),StartPosition: common.ConvertANTLRLineToPosition(r.line),diff --git a/backend/plugin/advisor/mysql/rule_migration_compatibility.go b/backend/plugin/advisor/mysql/rule_migration_compatibility.goindex ccb64daa29..8d44542211 100644--- a/backend/plugin/advisor/mysql/rule_migration_compatibility.go+++ b/backend/plugin/advisor/mysql/rule_migration_compatibility.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -61,7 +62,7 @@ type CompatibilityRule struct {BaseRuletext stringlastCreateTable string- code advisor.Code+ code code.Code}// NewCompatibilityRule creates a new CompatibilityRule.@@ -88,7 +89,7 @@ func (r *CompatibilityRule) OnEnter(ctx antlr.ParserRuleContext, nodeType stringreturn nil}r.text = queryCtx.GetParser().GetTokenStream().GetTextFromRuleContext(queryCtx)- r.code = advisor.Ok+ r.code = code.Okcase NodeTypeCreateTable:r.checkCreateTable(ctx.(*mysql.CreateTableContext))case NodeTypeDropDatabase:@@ -108,7 +109,7 @@ func (r *CompatibilityRule) OnEnter(ctx antlr.ParserRuleContext, nodeType string// OnExit is called when exiting a parse tree node.func (r *CompatibilityRule) OnExit(ctx antlr.ParserRuleContext, nodeType string) error {- if nodeType == NodeTypeQuery && r.code != advisor.Ok {+ if nodeType == NodeTypeQuery && r.code != code.Ok {r.AddAdvice(&storepb.Advice{Status: r.level,Code: r.code.Int32(),@@ -139,21 +140,21 @@ func (r *CompatibilityRule) checkDropDatabase(ctx *mysql.DropDatabaseContext) {if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {return}- r.code = advisor.CompatibilityDropDatabase+ r.code = code.CompatibilityDropDatabase}func (r *CompatibilityRule) checkRenameTableStatement(ctx *mysql.RenameTableStatementContext) {if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {return}- r.code = advisor.CompatibilityRenameTable+ r.code = code.CompatibilityRenameTable}func (r *CompatibilityRule) checkDropTable(ctx *mysql.DropTableContext) {if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {return}- r.code = advisor.CompatibilityDropTable+ r.code = code.CompatibilityDropTable}func (r *CompatibilityRule) checkAlterTable(ctx *mysql.AlterTableContext) {@@ -183,16 +184,16 @@ func (r *CompatibilityRule) checkAlterTable(ctx *mysql.AlterTableContext) {}if item.RENAME_SYMBOL() != nil && item.COLUMN_SYMBOL() != nil {- r.code = advisor.CompatibilityRenameColumn+ r.code = code.CompatibilityRenameColumnreturn}if item.DROP_SYMBOL() != nil && item.ColumnInternalRef() != nil {- r.code = advisor.CompatibilityDropColumn+ r.code = code.CompatibilityDropColumnreturn}if item.DROP_SYMBOL() != nil && item.TableName() != nil {- r.code = advisor.CompatibilityRenameTable+ r.code = code.CompatibilityRenameTablereturn}@@ -204,15 +205,15 @@ func (r *CompatibilityRule) checkAlterTable(ctx *mysql.AlterTableContext) {switch item.TableConstraintDef().GetType_().GetTokenType() {// add primary key.case mysql.MySQLParserPRIMARY_SYMBOL:- r.code = advisor.CompatibilityAddPrimaryKey+ r.code = code.CompatibilityAddPrimaryKeyreturn// add unique key.case mysql.MySQLParserUNIQUE_SYMBOL:- r.code = advisor.CompatibilityAddUniqueKey+ r.code = code.CompatibilityAddUniqueKeyreturn// add foreign key.case mysql.MySQLParserFOREIGN_SYMBOL:- r.code = advisor.CompatibilityAddForeignKey+ r.code = code.CompatibilityAddForeignKeyreturndefault:}@@ -221,7 +222,7 @@ func (r *CompatibilityRule) checkAlterTable(ctx *mysql.AlterTableContext) {// add check enforced.// Check is only supported after 8.0.16 https://dev.mysql.com/doc/refman/8.0/en/create-table-check-constraints.htmlif item.TableConstraintDef() != nil && item.TableConstraintDef().CheckConstraint() != nil && item.TableConstraintDef().ConstraintEnforcement() != nil {- r.code = advisor.CompatibilityAddCheck+ r.code = code.CompatibilityAddCheckreturn}}@@ -230,7 +231,7 @@ func (r *CompatibilityRule) checkAlterTable(ctx *mysql.AlterTableContext) {// Check is only supported after 8.0.16 https://dev.mysql.com/doc/refman/8.0/en/create-table-check-constraints.htmlif item.ALTER_SYMBOL() != nil && item.CHECK_SYMBOL() != nil {if item.ConstraintEnforcement() != nil {- r.code = advisor.CompatibilityAlterCheck+ r.code = code.CompatibilityAlterCheckreturn}}@@ -242,12 +243,12 @@ func (r *CompatibilityRule) checkAlterTable(ctx *mysql.AlterTableContext) {// 2. Change properties such as comment, change it to NULL// modify columnif item.MODIFY_SYMBOL() != nil && item.ColumnInternalRef() != nil {- r.code = advisor.CompatibilityAlterColumn+ r.code = code.CompatibilityAlterColumnreturn}// change columnif item.CHANGE_SYMBOL() != nil && item.ColumnInternalRef() != nil && item.Identifier() != nil {- r.code = advisor.CompatibilityAlterColumn+ r.code = code.CompatibilityAlterColumnreturn}}@@ -269,6 +270,6 @@ func (r *CompatibilityRule) checkCreateIndex(ctx *mysql.CreateIndexContext) {_, tableName := mysqlparser.NormalizeMySQLTableRef(ctx.CreateIndexTarget().TableRef())if r.lastCreateTable != tableName {- r.code = advisor.CompatibilityAddUniqueKey+ r.code = code.CompatibilityAddUniqueKey}}diff --git a/backend/plugin/advisor/mysql/rule_naming_auto_increment_column.go b/backend/plugin/advisor/mysql/rule_naming_auto_increment_column.goindex 22be86d3c6..85293849a7 100644--- a/backend/plugin/advisor/mysql/rule_naming_auto_increment_column.go+++ b/backend/plugin/advisor/mysql/rule_naming_auto_increment_column.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -185,7 +186,7 @@ func (r *NamingAutoIncrementColumnRule) checkFieldDefinition(tableName, columnNaif !r.format.MatchString(columnName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingAutoIncrementColumnConventionMismatch.Int32(),+ Code: code.NamingAutoIncrementColumnConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("`%s`.`%s` mismatches auto_increment column naming convention, naming format should be %q", tableName, columnName, r.format),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -194,7 +195,7 @@ func (r *NamingAutoIncrementColumnRule) checkFieldDefinition(tableName, columnNaif r.maxLength > 0 && len(columnName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingAutoIncrementColumnConventionMismatch.Int32(),+ Code: code.NamingAutoIncrementColumnConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("`%s`.`%s` mismatches auto_increment column naming convention, its length should be within %d characters", tableName, columnName, r.maxLength),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_naming_column.go b/backend/plugin/advisor/mysql/rule_naming_column.goindex aece9a0b8b..91efe5e842 100644--- a/backend/plugin/advisor/mysql/rule_naming_column.go+++ b/backend/plugin/advisor/mysql/rule_naming_column.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -187,7 +188,7 @@ func (r *NamingColumnRule) handleColumn(tableName string, columnName string, linif !r.format.MatchString(columnName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingColumnConventionMismatch.Int32(),+ Code: code.NamingColumnConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("`%s`.`%s` mismatches column naming convention, naming format should be %q", tableName, columnName, r.format),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),@@ -196,7 +197,7 @@ func (r *NamingColumnRule) handleColumn(tableName string, columnName string, linif r.maxLength > 0 && len(columnName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingColumnConventionMismatch.Int32(),+ Code: code.NamingColumnConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("`%s`.`%s` mismatches column naming convention, its length should be within %d characters", tableName, columnName, r.maxLength),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),diff --git a/backend/plugin/advisor/mysql/rule_naming_foreign_key_convention.go b/backend/plugin/advisor/mysql/rule_naming_foreign_key_convention.goindex ef6fd4d455..da4602f669 100644--- a/backend/plugin/advisor/mysql/rule_naming_foreign_key_convention.go+++ b/backend/plugin/advisor/mysql/rule_naming_foreign_key_convention.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -187,7 +188,7 @@ func (r *NamingFKConventionRule) handleIndexList(indexDataList []*fkIndexMetaDatif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for foreign key naming convention rule",Content: fmt.Sprintf("%q meet internal error %q", r.text, err.Error()),})@@ -196,7 +197,7 @@ func (r *NamingFKConventionRule) handleIndexList(indexDataList []*fkIndexMetaDatif !regex.MatchString(indexData.indexName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingFKConventionMismatch.Int32(),+ Code: code.NamingFKConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("Foreign key in table `%s` mismatches the naming convention, expect %q but found `%s`", indexData.tableName, regex, indexData.indexName),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),@@ -205,7 +206,7 @@ func (r *NamingFKConventionRule) handleIndexList(indexDataList []*fkIndexMetaDatif r.maxLength > 0 && len(indexData.indexName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingFKConventionMismatch.Int32(),+ Code: code.NamingFKConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("Foreign key `%s` in table `%s` mismatches the naming convention, its length should be within %d characters", indexData.indexName, indexData.tableName, r.maxLength),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),diff --git a/backend/plugin/advisor/mysql/rule_naming_identifier_no_keyword.go b/backend/plugin/advisor/mysql/rule_naming_identifier_no_keyword.goindex 6ba1fbf24b..2f15917740 100644--- a/backend/plugin/advisor/mysql/rule_naming_identifier_no_keyword.go+++ b/backend/plugin/advisor/mysql/rule_naming_identifier_no_keyword.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -119,7 +121,7 @@ func (r *NamingIdentifierNoKeywordRule) checkIdentifier(identifier string) *storif isKeyword(identifier) {return &storepb.Advice{Status: r.level,- Code: advisor.NameIsKeywordIdentifier.Int32(),+ Code: code.NameIsKeywordIdentifier.Int32(),Title: r.title,Content: fmt.Sprintf("Identifier %q is a keyword and should be avoided", identifier),}diff --git a/backend/plugin/advisor/mysql/rule_naming_index_convention.go b/backend/plugin/advisor/mysql/rule_naming_index_convention.goindex 75b7401ab9..46b1258a53 100644--- a/backend/plugin/advisor/mysql/rule_naming_index_convention.go+++ b/backend/plugin/advisor/mysql/rule_naming_index_convention.go@@ -13,6 +13,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -258,7 +259,7 @@ func (r *NamingIndexConventionRule) handleIndexList(indexDataList []*indexMetaDaif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for unique key naming convention rule",Content: fmt.Sprintf("%q meet internal error %q", r.text, err.Error()),})@@ -267,7 +268,7 @@ func (r *NamingIndexConventionRule) handleIndexList(indexDataList []*indexMetaDaif !regex.MatchString(indexData.indexName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingIndexConventionMismatch.Int32(),+ Code: code.NamingIndexConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("Index in table `%s` mismatches the naming convention, expect %q but found `%s`", indexData.tableName, regex, indexData.indexName),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),@@ -276,7 +277,7 @@ func (r *NamingIndexConventionRule) handleIndexList(indexDataList []*indexMetaDaif r.maxLength > 0 && len(indexData.indexName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingIndexConventionMismatch.Int32(),+ Code: code.NamingIndexConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("Index `%s` in table `%s` mismatches the naming convention, its length should be within %d characters", indexData.indexName, indexData.tableName, r.maxLength),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),diff --git a/backend/plugin/advisor/mysql/rule_naming_table.go b/backend/plugin/advisor/mysql/rule_naming_table.goindex 88db373940..d534d02a62 100644--- a/backend/plugin/advisor/mysql/rule_naming_table.go+++ b/backend/plugin/advisor/mysql/rule_naming_table.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -150,7 +151,7 @@ func (r *NamingTableRule) handleTableName(tableName string, lineNumber int) {if !r.format.MatchString(tableName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("`%s` mismatches table naming convention, naming format should be %q", tableName, r.format),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),@@ -159,7 +160,7 @@ func (r *NamingTableRule) handleTableName(tableName string, lineNumber int) {if r.maxLength > 0 && len(tableName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("`%s` mismatches table naming convention, its length should be within %d characters", tableName, r.maxLength),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),diff --git a/backend/plugin/advisor/mysql/rule_naming_unique_key_convention.go b/backend/plugin/advisor/mysql/rule_naming_unique_key_convention.goindex 48d8f13179..cc71d6822e 100644--- a/backend/plugin/advisor/mysql/rule_naming_unique_key_convention.go+++ b/backend/plugin/advisor/mysql/rule_naming_unique_key_convention.go@@ -13,6 +13,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -257,7 +258,7 @@ func (r *NamingUKConventionRule) handleIndexList(indexDataList []*ukIndexMetaDatif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for unique key naming convention rule",Content: fmt.Sprintf("%q meet internal error %q", r.text, err.Error()),})@@ -266,7 +267,7 @@ func (r *NamingUKConventionRule) handleIndexList(indexDataList []*ukIndexMetaDatif !regex.MatchString(indexData.indexName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingUKConventionMismatch.Int32(),+ Code: code.NamingUKConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("Unique key in table `%s` mismatches the naming convention, expect %q but found `%s`", indexData.tableName, regex, indexData.indexName),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),@@ -275,7 +276,7 @@ func (r *NamingUKConventionRule) handleIndexList(indexDataList []*ukIndexMetaDatif r.maxLength > 0 && len(indexData.indexName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingUKConventionMismatch.Int32(),+ Code: code.NamingUKConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("Unique key `%s` in table `%s` mismatches the naming convention, its length should be within %d characters", indexData.indexName, indexData.tableName, r.maxLength),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),diff --git a/backend/plugin/advisor/mysql/rule_online_migration.go b/backend/plugin/advisor/mysql/rule_online_migration.goindex 110178cca5..dbcbb8ac67 100644--- a/backend/plugin/advisor/mysql/rule_online_migration.go+++ b/backend/plugin/advisor/mysql/rule_online_migration.go@@ -14,6 +14,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"parserbase "github.com/bytebase/bytebase/backend/plugin/parser/base"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql""github.com/bytebase/bytebase/backend/store/model"@@ -61,7 +62,7 @@ func (*OnlineMigrationAdvisor) Check(ctx context.Context, checkCtx advisor.ConteStatus: level,Title: title,Content: fmt.Sprintf("Needs database %q to save temporary data for online migration but it does not exist", ghostDatabaseName),- Code: advisor.DatabaseNotExists.Int32(),+ Code: code.DatabaseNotExists.Int32(),StartPosition: nil,},}, nil@@ -101,7 +102,7 @@ func (*OnlineMigrationAdvisor) Check(ctx context.Context, checkCtx advisor.Contereturn nil, nil}- adviceList[0].Code = advisor.AdviseOnlineMigration.Int32()+ adviceList[0].Code = code.AdviseOnlineMigration.Int32()return adviceList, nil}@@ -111,7 +112,7 @@ func (*OnlineMigrationAdvisor) Check(ctx context.Context, checkCtx advisor.Conteif checkCtx.ChangeType == storepb.PlanCheckRunConfig_DDL_GHOST {return []*storepb.Advice{{Status: level,- Code: advisor.AdviseNoOnlineMigration.Int32(),+ Code: code.AdviseNoOnlineMigration.Int32(),Title: title,Content: "Advise to disable online migration because found no statements that need online migration",}}, nil@@ -212,7 +213,7 @@ func (r *OnlineMigrationRule) exitAlterStatement(ctx *mysql.AlterStatementContexif tableRows >= r.minRows {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.AdviseOnlineMigrationForStatement.Int32(),+ Code: code.AdviseOnlineMigrationForStatement.Int32(),Title: r.title,Content: fmt.Sprintf("Estimated table row count of %q is %d exceeding the set value %d. Consider using online migration for this statement", fmt.Sprintf("%s.%s", resource.Schema, resource.Table), tableRows, r.minRows),StartPosition: r.start,diff --git a/backend/plugin/advisor/mysql/rule_statement_add_column_without_position.go b/backend/plugin/advisor/mysql/rule_statement_add_column_without_position.goindex ccb454026c..8204f5a2de 100644--- a/backend/plugin/advisor/mysql/rule_statement_add_column_without_position.go+++ b/backend/plugin/advisor/mysql/rule_statement_add_column_without_position.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -138,7 +139,7 @@ func (r *StatementAddColumnWithoutPositionRule) checkAlterTable(ctx *mysql.Alterif len(position) != 0 {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementAddColumnWithPosition.Int32(),+ Code: code.StatementAddColumnWithPosition.Int32(),Title: r.title,Content: fmt.Sprintf("add column with position \"%s\"", position),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_statement_affected_row_limit.go b/backend/plugin/advisor/mysql/rule_statement_affected_row_limit.goindex f316757013..5215dfe8bc 100644--- a/backend/plugin/advisor/mysql/rule_statement_affected_row_limit.go+++ b/backend/plugin/advisor/mysql/rule_statement_affected_row_limit.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -127,7 +128,7 @@ func (r *StatementAffectedRowLimitRule) handleStmt(lineNumber int) {if err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementAffectedRowExceedsLimit.Int32(),+ Code: code.StatementAffectedRowExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" dry runs failed: %s", r.text, err.Error()),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),@@ -137,7 +138,7 @@ func (r *StatementAffectedRowLimitRule) handleStmt(lineNumber int) {if err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: r.title,Content: fmt.Sprintf("failed to get row count for \"%s\": %s", r.text, err.Error()),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),@@ -145,7 +146,7 @@ func (r *StatementAffectedRowLimitRule) handleStmt(lineNumber int) {} else if rowCount > int64(r.maxRow) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementAffectedRowExceedsLimit.Int32(),+ Code: code.StatementAffectedRowExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" affected %d rows (estimated). The count exceeds %d.", r.text, rowCount, r.maxRow),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),diff --git a/backend/plugin/advisor/mysql/rule_statement_disallow_mix_in_ddl.go b/backend/plugin/advisor/mysql/rule_statement_disallow_mix_in_ddl.goindex c4eb5166b2..6710b4c1a8 100644--- a/backend/plugin/advisor/mysql/rule_statement_disallow_mix_in_ddl.go+++ b/backend/plugin/advisor/mysql/rule_statement_disallow_mix_in_ddl.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -52,7 +53,7 @@ func (*StatementDisallowMixInDDLAdvisor) Check(_ context.Context, checkCtx advisStatus: level,Title: title,Content: fmt.Sprintf("Alter schema can only run DDL, \"%s\" is not DDL", checker.Text),- Code: advisor.StatementDisallowMixDDLDML.Int32(),+ Code: code.StatementDisallowMixDDLDML.Int32(),StartPosition: common.ConvertANTLRLineToPosition(stmt.BaseLine),})}diff --git a/backend/plugin/advisor/mysql/rule_statement_disallow_mix_in_dml.go b/backend/plugin/advisor/mysql/rule_statement_disallow_mix_in_dml.goindex d885c4d542..b24b4cb37c 100644--- a/backend/plugin/advisor/mysql/rule_statement_disallow_mix_in_dml.go+++ b/backend/plugin/advisor/mysql/rule_statement_disallow_mix_in_dml.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -52,7 +53,7 @@ func (*StatementDisallowMixInDMLAdvisor) Check(_ context.Context, checkCtx advisStatus: level,Title: title,Content: fmt.Sprintf("Data change can only run DML, \"%s\" is not DML", checker.Text),- Code: advisor.StatementDisallowMixDDLDML.Int32(),+ Code: code.StatementDisallowMixDDLDML.Int32(),StartPosition: common.ConvertANTLRLineToPosition(stmt.BaseLine),})}diff --git a/backend/plugin/advisor/mysql/rule_statement_disallow_using_filesort.go b/backend/plugin/advisor/mysql/rule_statement_disallow_using_filesort.goindex 7d1849a81a..182ccf5956 100644--- a/backend/plugin/advisor/mysql/rule_statement_disallow_using_filesort.go+++ b/backend/plugin/advisor/mysql/rule_statement_disallow_using_filesort.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -116,7 +117,7 @@ func (r *StatementDisallowUsingFilesortRule) checkSelectStatement(ctx *mysql.Selif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementExplainQueryFailed.Int32(),+ Code: code.StatementExplainQueryFailed.Int32(),Title: r.title,Content: fmt.Sprintf("Failed to explain query: %s, with error: %s", query, err),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -126,7 +127,7 @@ func (r *StatementDisallowUsingFilesortRule) checkSelectStatement(ctx *mysql.Selif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: r.title,Content: fmt.Sprintf("Failed to check extra column: %s, with error: %s", query, err),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -134,7 +135,7 @@ func (r *StatementDisallowUsingFilesortRule) checkSelectStatement(ctx *mysql.Sel} else if hasUsingFilesort {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementHasUsingFilesort.Int32(),+ Code: code.StatementHasUsingFilesort.Int32(),Title: r.title,Content: fmt.Sprintf("Using filesort detected on table(s): %s", tables),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_statement_disallow_using_temporary.go b/backend/plugin/advisor/mysql/rule_statement_disallow_using_temporary.goindex 420c2c37d0..2b28ae914f 100644--- a/backend/plugin/advisor/mysql/rule_statement_disallow_using_temporary.go+++ b/backend/plugin/advisor/mysql/rule_statement_disallow_using_temporary.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -116,7 +117,7 @@ func (r *StatementDisallowUsingTemporaryRule) checkSelectStatement(ctx *mysql.Seif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementExplainQueryFailed.Int32(),+ Code: code.StatementExplainQueryFailed.Int32(),Title: r.title,Content: fmt.Sprintf("Failed to explain query: %s, with error: %s", query, err),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -126,7 +127,7 @@ func (r *StatementDisallowUsingTemporaryRule) checkSelectStatement(ctx *mysql.Seif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: r.title,Content: fmt.Sprintf("Failed to check extra column: %s, with error: %s", query, err),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -134,7 +135,7 @@ func (r *StatementDisallowUsingTemporaryRule) checkSelectStatement(ctx *mysql.Se} else if hasUsingTemporary {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementHasUsingTemporary.Int32(),+ Code: code.StatementHasUsingTemporary.Int32(),Title: r.title,Content: fmt.Sprintf("Using temporary detected on table(s): %s", tables),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_statement_dml_dry_run.go b/backend/plugin/advisor/mysql/rule_statement_dml_dry_run.goindex 338191c27a..7ac544e907 100644--- a/backend/plugin/advisor/mysql/rule_statement_dml_dry_run.go+++ b/backend/plugin/advisor/mysql/rule_statement_dml_dry_run.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -129,7 +130,7 @@ func (r *StatementDmlDryRunRule) handleStmt(text string, lineNumber int) {if _, err := advisor.Query(r.ctx, advisor.QueryContext{}, r.driver, storepb.Engine_MYSQL, fmt.Sprintf("EXPLAIN %s", text)); err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementDMLDryRunFailed.Int32(),+ Code: code.StatementDMLDryRunFailed.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" dry runs failed: %s", text, err.Error()),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + lineNumber),diff --git a/backend/plugin/advisor/mysql/rule_statement_join_strict_column_attrs.go b/backend/plugin/advisor/mysql/rule_statement_join_strict_column_attrs.goindex 241ae9d65c..f919dc7627 100644--- a/backend/plugin/advisor/mysql/rule_statement_join_strict_column_attrs.go+++ b/backend/plugin/advisor/mysql/rule_statement_join_strict_column_attrs.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql""github.com/bytebase/bytebase/backend/store/model")@@ -232,7 +233,7 @@ func (r *StatementJoinStrictColumnAttrsRule) checkColumnAttrs(leftColumnAttr *Coif leftColumn.Type != rightColumn.Type || leftColumn.CharacterSet != rightColumn.CharacterSet || leftColumn.Collation != rightColumn.Collation {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementJoinColumnAttrsNotMatch.Int32(),+ Code: code.StatementJoinColumnAttrsNotMatch.Int32(),Title: r.title,Content: fmt.Sprintf("%s.%s and %s.%s column fields do not match", leftColumnAttr.Table, leftColumnAttr.Column, rightColumnAttr.Table, rightColumnAttr.Column),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine),diff --git a/backend/plugin/advisor/mysql/rule_statement_maximum_join_table_count.go b/backend/plugin/advisor/mysql/rule_statement_maximum_join_table_count.goindex 9c773657c5..c0090d2c73 100644--- a/backend/plugin/advisor/mysql/rule_statement_maximum_join_table_count.go+++ b/backend/plugin/advisor/mysql/rule_statement_maximum_join_table_count.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -107,7 +108,7 @@ func (r *StatementMaximumJoinTableCountRule) checkJoinedTable(ctx *mysql.JoinedTif r.count == r.limitMaxValue {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementMaximumJoinTableCount.Int32(),+ Code: code.StatementMaximumJoinTableCount.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" exceeds the maximum number of joins %d.", r.text, r.limitMaxValue),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_statement_maximum_limit_value.go b/backend/plugin/advisor/mysql/rule_statement_maximum_limit_value.goindex 3bd72e97a6..ac83863adf 100644--- a/backend/plugin/advisor/mysql/rule_statement_maximum_limit_value.go+++ b/backend/plugin/advisor/mysql/rule_statement_maximum_limit_value.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -131,7 +132,7 @@ func (r *StatementMaximumLimitValueRule) checkLimitClause(ctx *mysql.LimitClauseif limitValue > r.limitMaxValue {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementExceedMaximumLimitValue.Int32(),+ Code: code.StatementExceedMaximumLimitValue.Int32(),Title: r.title,Content: fmt.Sprintf("The limit value %d exceeds the maximum allowed value %d", limitValue, r.limitMaxValue),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_statement_merge_alter_table.go b/backend/plugin/advisor/mysql/rule_statement_merge_alter_table.goindex 5889b03ff6..53c33f5a08 100644--- a/backend/plugin/advisor/mysql/rule_statement_merge_alter_table.go+++ b/backend/plugin/advisor/mysql/rule_statement_merge_alter_table.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -167,7 +168,7 @@ func (r *StatementMergeAlterTableRule) generateAdvice() {if table.count > 1 {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementRedundantAlterTable.Int32(),+ Code: code.StatementRedundantAlterTable.Int32(),Title: r.title,Content: fmt.Sprintf("There are %d statements to modify table `%s`", table.count, table.name),StartPosition: common.ConvertANTLRLineToPosition(table.lastLine),diff --git a/backend/plugin/advisor/mysql/rule_statement_query_minimum_plan_level.go b/backend/plugin/advisor/mysql/rule_statement_query_minimum_plan_level.goindex 74854065cf..b1bb49b644 100644--- a/backend/plugin/advisor/mysql/rule_statement_query_minimum_plan_level.go+++ b/backend/plugin/advisor/mysql/rule_statement_query_minimum_plan_level.go@@ -14,6 +14,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -182,7 +183,7 @@ func (r *StatementQueryMinumumPlanLevelRule) checkSelectStatement(ctx *mysql.Selif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementExplainQueryFailed.Int32(),+ Code: code.StatementExplainQueryFailed.Int32(),Title: r.title,Content: fmt.Sprintf("Failed to explain query: %s, with error: %s", query, err),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -192,7 +193,7 @@ func (r *StatementQueryMinumumPlanLevelRule) checkSelectStatement(ctx *mysql.Selif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: r.title,Content: fmt.Sprintf("Failed to check explain type column: %s, with error: %s", query, err),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -209,7 +210,7 @@ func (r *StatementQueryMinumumPlanLevelRule) checkSelectStatement(ctx *mysql.Selif overused {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementUnwantedQueryPlanLevel.Int32(),+ Code: code.StatementUnwantedQueryPlanLevel.Int32(),Title: r.title,Content: fmt.Sprintf("Overused query plan level detected %s, minimum plan level: %s", overusedType.String(), r.explainType.String()),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_statement_select_full_table_scan.go b/backend/plugin/advisor/mysql/rule_statement_select_full_table_scan.goindex 5cebdff8f8..63840b91ce 100644--- a/backend/plugin/advisor/mysql/rule_statement_select_full_table_scan.go+++ b/backend/plugin/advisor/mysql/rule_statement_select_full_table_scan.go@@ -14,6 +14,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -118,7 +119,7 @@ func (r *StatementSelectFullTableScanRule) checkSelectStatement(ctx *mysql.Selecif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementCheckSelectFullTableScanFailed.Int32(),+ Code: code.StatementCheckSelectFullTableScanFailed.Int32(),Title: r.title,Content: fmt.Sprintf("Failed to check full table scan: %s, with error: %s", query, err),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -128,7 +129,7 @@ func (r *StatementSelectFullTableScanRule) checkSelectStatement(ctx *mysql.Selecif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: r.title,Content: fmt.Sprintf("Failed to check full table scan: %s, with error: %s", query, err),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -136,7 +137,7 @@ func (r *StatementSelectFullTableScanRule) checkSelectStatement(ctx *mysql.Selec} else if hasFullScan {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementHasTableFullScan.Int32(),+ Code: code.StatementHasTableFullScan.Int32(),Title: r.title,Content: fmt.Sprintf("Full table scan detected on table(s): %s", tables),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_statement_where_disallow_using_function.go b/backend/plugin/advisor/mysql/rule_statement_where_disallow_using_function.goindex ac42381a12..19f467b5ad 100644--- a/backend/plugin/advisor/mysql/rule_statement_where_disallow_using_function.go+++ b/backend/plugin/advisor/mysql/rule_statement_where_disallow_using_function.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -115,7 +117,7 @@ func (r *StatementWhereDisallowUsingFunctionRule) checkFunctionCall(ctx *mysql.Fif pi != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisabledFunction.Int32(),+ Code: code.DisabledFunction.Int32(),Title: r.title,Content: fmt.Sprintf("Function is disallowed in where clause, but \"%s\" uses", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_statement_where_maximum_logical_operator_count.go b/backend/plugin/advisor/mysql/rule_statement_where_maximum_logical_operator_count.goindex c816cda0b5..131915e3c1 100644--- a/backend/plugin/advisor/mysql/rule_statement_where_maximum_logical_operator_count.go+++ b/backend/plugin/advisor/mysql/rule_statement_where_maximum_logical_operator_count.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -143,7 +144,7 @@ func (r *StatementWhereMaximumLogicalOperatorCountRule) checkExprList(ctx *mysqlif count > r.maximum {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementWhereMaximumLogicalOperatorCount.Int32(),+ Code: code.StatementWhereMaximumLogicalOperatorCount.Int32(),Title: r.title,Content: fmt.Sprintf("Number of tokens (%d) in IN predicate operation exceeds limit (%d) in statement %q.", count, r.maximum, r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -164,7 +165,7 @@ func (r *StatementWhereMaximumLogicalOperatorCountRule) checkOrConditions() {if r.maxOrCount > r.maximum {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementWhereMaximumLogicalOperatorCount.Int32(),+ Code: code.StatementWhereMaximumLogicalOperatorCount.Int32(),Title: r.title,Content: fmt.Sprintf("Number of tokens (%d) in the OR predicate operation exceeds limit (%d) in statement %q.", r.maxOrCount, r.maximum, r.text),StartPosition: common.ConvertANTLRLineToPosition(r.maxOrCountLine),diff --git a/backend/plugin/advisor/mysql/rule_statement_where_no_equal_null.go b/backend/plugin/advisor/mysql/rule_statement_where_no_equal_null.goindex a796ca85b5..dbed6d22d4 100644--- a/backend/plugin/advisor/mysql/rule_statement_where_no_equal_null.go+++ b/backend/plugin/advisor/mysql/rule_statement_where_no_equal_null.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -112,7 +113,7 @@ func (r *StatementWhereNoEqualNullRule) checkPrimaryExprCompare(ctx *mysql.Primaif ctx.Predicate() != nil && ctx.Predicate().GetText() == "NULL" {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementWhereNoEqualNull.Int32(),+ Code: code.StatementWhereNoEqualNull.Int32(),Title: r.title,Content: fmt.Sprintf("WHERE clause contains equal null: %s", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_stmt_disallow_commit.go b/backend/plugin/advisor/mysql/rule_stmt_disallow_commit.goindex ddbe3cdee5..53c86a722c 100644--- a/backend/plugin/advisor/mysql/rule_stmt_disallow_commit.go+++ b/backend/plugin/advisor/mysql/rule_stmt_disallow_commit.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -107,7 +108,7 @@ func (r *StatementDisallowCommitRule) checkTransactionStatement(ctx *mysql.Transr.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementDisallowCommit.Int32(),+ Code: code.StatementDisallowCommit.Int32(),Title: r.title,Content: fmt.Sprintf("Commit is not allowed, related statement: \"%s\"", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_stmt_disallow_limit.go b/backend/plugin/advisor/mysql/rule_stmt_disallow_limit.goindex b72f026e30..b3727d6e37 100644--- a/backend/plugin/advisor/mysql/rule_stmt_disallow_limit.go+++ b/backend/plugin/advisor/mysql/rule_stmt_disallow_limit.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -109,13 +110,13 @@ func (r *StatementDisallowLimitRule) OnExit(_ antlr.ParserRuleContext, nodeTypefunc (r *StatementDisallowLimitRule) checkDeleteStatement(ctx *mysql.DeleteStatementContext) {if ctx.SimpleLimitClause() != nil && ctx.SimpleLimitClause().LIMIT_SYMBOL() != nil {- r.handleLimitClause(advisor.DeleteUseLimit, ctx.GetStart().GetLine())+ r.handleLimitClause(code.DeleteUseLimit, ctx.GetStart().GetLine())}}func (r *StatementDisallowLimitRule) checkUpdateStatement(ctx *mysql.UpdateStatementContext) {if ctx.SimpleLimitClause() != nil && ctx.SimpleLimitClause().LIMIT_SYMBOL() != nil {- r.handleLimitClause(advisor.UpdateUseLimit, ctx.GetStart().GetLine())+ r.handleLimitClause(code.UpdateUseLimit, ctx.GetStart().GetLine())}}@@ -124,11 +125,11 @@ func (r *StatementDisallowLimitRule) checkQueryExpression(ctx *mysql.QueryExpresreturn}if ctx.LimitClause() != nil && ctx.LimitClause().LIMIT_SYMBOL() != nil {- r.handleLimitClause(advisor.InsertUseLimit, ctx.GetStart().GetLine())+ r.handleLimitClause(code.InsertUseLimit, ctx.GetStart().GetLine())}}-func (r *StatementDisallowLimitRule) handleLimitClause(code advisor.Code, lineNumber int) {+func (r *StatementDisallowLimitRule) handleLimitClause(code code.Code, lineNumber int) {r.AddAdvice(&storepb.Advice{Status: r.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/mysql/rule_stmt_disallow_order_by.go b/backend/plugin/advisor/mysql/rule_stmt_disallow_order_by.goindex 9b8880093b..5ac28d80a7 100644--- a/backend/plugin/advisor/mysql/rule_stmt_disallow_order_by.go+++ b/backend/plugin/advisor/mysql/rule_stmt_disallow_order_by.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -101,17 +102,17 @@ func (*DisallowOrderByRule) OnExit(_ antlr.ParserRuleContext, _ string) error {func (r *DisallowOrderByRule) checkDeleteStatement(ctx *mysql.DeleteStatementContext) {if ctx.OrderClause() != nil && ctx.OrderClause().ORDER_SYMBOL() != nil {- r.handleOrderByClause(advisor.DeleteUseOrderBy, ctx.GetStart().GetLine())+ r.handleOrderByClause(code.DeleteUseOrderBy, ctx.GetStart().GetLine())}}func (r *DisallowOrderByRule) checkUpdateStatement(ctx *mysql.UpdateStatementContext) {if ctx.OrderClause() != nil && ctx.OrderClause().ORDER_SYMBOL() != nil {- r.handleOrderByClause(advisor.UpdateUseOrderBy, ctx.GetStart().GetLine())+ r.handleOrderByClause(code.UpdateUseOrderBy, ctx.GetStart().GetLine())}}-func (r *DisallowOrderByRule) handleOrderByClause(code advisor.Code, lineNumber int) {+func (r *DisallowOrderByRule) handleOrderByClause(code code.Code, lineNumber int) {r.AddAdvice(&storepb.Advice{Status: r.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/mysql/rule_stmt_max_execution_time.go b/backend/plugin/advisor/mysql/rule_stmt_max_execution_time.goindex 1316e10fe5..0c2f103752 100644--- a/backend/plugin/advisor/mysql/rule_stmt_max_execution_time.go+++ b/backend/plugin/advisor/mysql/rule_stmt_max_execution_time.go@@ -12,6 +12,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -152,7 +153,7 @@ func (r *MaxExecutionTimeRule) checkSetStatement(ctx *mysql.SetStatementContext)func (r *MaxExecutionTimeRule) setAdvice() {r.adviceList = append(r.adviceList, &storepb.Advice{Status: r.level,- Code: advisor.StatementNoMaxExecutionTime.Int32(),+ Code: code.StatementNoMaxExecutionTime.Int32(),Title: r.title,Content: fmt.Sprintf("The %s is not set", r.systemVariable),})diff --git a/backend/plugin/advisor/mysql/rule_stmt_no_leading_wildcard_like.go b/backend/plugin/advisor/mysql/rule_stmt_no_leading_wildcard_like.goindex 6aff23fe3d..3710cbf60b 100644--- a/backend/plugin/advisor/mysql/rule_stmt_no_leading_wildcard_like.go+++ b/backend/plugin/advisor/mysql/rule_stmt_no_leading_wildcard_like.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -108,7 +109,7 @@ func (r *NoLeadingWildcardLikeRule) checkPredicateExprLike(ctx *mysql.PredicateEif (strings.HasPrefix(pattern, "'%") && strings.HasSuffix(pattern, "'")) || (strings.HasPrefix(pattern, "\"%") && strings.HasSuffix(pattern, "\"")) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementLeadingWildcardLike.Int32(),+ Code: code.StatementLeadingWildcardLike.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" uses leading wildcard LIKE", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_stmt_no_select_all.go b/backend/plugin/advisor/mysql/rule_stmt_no_select_all.goindex 9302ba1b29..8bc726f21a 100644--- a/backend/plugin/advisor/mysql/rule_stmt_no_select_all.go+++ b/backend/plugin/advisor/mysql/rule_stmt_no_select_all.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -102,7 +103,7 @@ func (r *NoSelectAllRule) checkSelectItemList(ctx *mysql.SelectItemListContext)if ctx.MULT_OPERATOR() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementSelectAll.Int32(),+ Code: code.StatementSelectAll.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" uses SELECT all", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_stmt_require_algorithm_or_lock_options.go b/backend/plugin/advisor/mysql/rule_stmt_require_algorithm_or_lock_options.goindex 4d30aff1aa..d12bb27ff4 100644--- a/backend/plugin/advisor/mysql/rule_stmt_require_algorithm_or_lock_options.go+++ b/backend/plugin/advisor/mysql/rule_stmt_require_algorithm_or_lock_options.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -40,9 +41,9 @@ func (*RequireAlgorithmOrLockOptionAdvisor) Check(_ context.Context, checkCtx adreturn nil, err}- requiredOption, errorCode := "ALGORITHM", advisor.StatementNoAlgorithmOption+ requiredOption, errorCode := "ALGORITHM", code.StatementNoAlgorithmOptionif checkCtx.Rule.Type == string(advisor.SchemaRuleStatementRequireLockOption) {- requiredOption, errorCode = "LOCK", advisor.StatementNoLockOption+ requiredOption, errorCode = "LOCK", code.StatementNoLockOption}// Create the rule@@ -66,13 +67,13 @@ type RequireAlgorithmOrLockOptionRule struct {requiredOption stringhasOption boolinAlterTableStatement bool- errorCode advisor.Code+ errorCode code.Codetext stringline int}// NewRequireAlgorithmOrLockOptionRule creates a new RequireAlgorithmOrLockOptionRule.-func NewRequireAlgorithmOrLockOptionRule(level storepb.Advice_Status, title string, requiredOption string, errorCode advisor.Code) *RequireAlgorithmOrLockOptionRule {+func NewRequireAlgorithmOrLockOptionRule(level storepb.Advice_Status, title string, requiredOption string, errorCode code.Code) *RequireAlgorithmOrLockOptionRule {return &RequireAlgorithmOrLockOptionRule{BaseRule: BaseRule{level: level,diff --git a/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_select.go b/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_select.goindex 1590e27e31..df9853f4e9 100644--- a/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_select.go+++ b/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_select.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -105,7 +106,7 @@ func (r *WhereRequirementForSelectRule) checkQuerySpecification(ctx *mysql.Queryif ctx.WhereClause() == nil || ctx.WhereClause().WHERE_SYMBOL() == nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" requires WHERE clause", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_update_delete.go b/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_update_delete.goindex be888c0012..13435c95e1 100644--- a/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_update_delete.go+++ b/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_update_delete.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -120,7 +121,7 @@ func (r *WhereRequirementForUpdateDeleteRule) checkUpdateStatement(ctx *mysql.Upfunc (r *WhereRequirementForUpdateDeleteRule) handleWhereClause(lineNumber int) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" requires WHERE clause", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + lineNumber),diff --git a/backend/plugin/advisor/mysql/rule_table_comment_convention.go b/backend/plugin/advisor/mysql/rule_table_comment_convention.goindex 84955f419b..f136f1f93d 100644--- a/backend/plugin/advisor/mysql/rule_table_comment_convention.go+++ b/backend/plugin/advisor/mysql/rule_table_comment_convention.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -111,7 +112,7 @@ func (r *TableCommentConventionRule) checkCreateTable(ctx *mysql.CreateTableContif r.payload.Required && !exists {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CommentEmpty.Int32(),+ Code: code.CommentEmpty.Int32(),Title: r.title,Content: fmt.Sprintf("Table `%s` requires comments", tableName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -120,7 +121,7 @@ func (r *TableCommentConventionRule) checkCreateTable(ctx *mysql.CreateTableContif r.payload.MaxLength >= 0 && len(comment) > r.payload.MaxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CommentTooLong.Int32(),+ Code: code.CommentTooLong.Int32(),Title: r.title,Content: fmt.Sprintf("The length of table `%s` comment should be within %d characters", tableName, r.payload.MaxLength),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -130,7 +131,7 @@ func (r *TableCommentConventionRule) checkCreateTable(ctx *mysql.CreateTableContif classification, _ := common.GetClassificationAndUserComment(comment, r.classificationConfig); classification == "" {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CommentMissingClassification.Int32(),+ Code: code.CommentMissingClassification.Int32(),Title: r.title,Content: fmt.Sprintf("Table `%s` comment requires classification", tableName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_table_disallow_ddl.go b/backend/plugin/advisor/mysql/rule_table_disallow_ddl.goindex 0b65aab0d6..73fcaa22fc 100644--- a/backend/plugin/advisor/mysql/rule_table_disallow_ddl.go+++ b/backend/plugin/advisor/mysql/rule_table_disallow_ddl.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -150,7 +152,7 @@ func (r *TableDisallowDDLRule) checkTableName(tableName string, line int) {if tableName == disallow {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableDisallowDDL.Int32(),+ Code: code.TableDisallowDDL.Int32(),Title: r.title,Content: fmt.Sprintf("DDL is disallowed on table %s.", tableName),StartPosition: common.ConvertANTLRLineToPosition(line),diff --git a/backend/plugin/advisor/mysql/rule_table_disallow_dml.go b/backend/plugin/advisor/mysql/rule_table_disallow_dml.goindex b4e3ca4dfe..1c85882fbf 100644--- a/backend/plugin/advisor/mysql/rule_table_disallow_dml.go+++ b/backend/plugin/advisor/mysql/rule_table_disallow_dml.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -142,7 +144,7 @@ func (r *TableDisallowDMLRule) checkTableName(tableName string, line int) {if tableName == disallow {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableDisallowDML.Int32(),+ Code: code.TableDisallowDML.Int32(),Title: r.title,Content: fmt.Sprintf("DML is disallowed on table %s.", tableName),StartPosition: common.ConvertANTLRLineToPosition(line),diff --git a/backend/plugin/advisor/mysql/rule_table_disallow_partition.go b/backend/plugin/advisor/mysql/rule_table_disallow_partition.goindex 1fbf88b231..4f47c99631 100644--- a/backend/plugin/advisor/mysql/rule_table_disallow_partition.go+++ b/backend/plugin/advisor/mysql/rule_table_disallow_partition.go@@ -4,6 +4,8 @@ import ("context""fmt"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -103,12 +105,12 @@ func (r *TableDisallowPartitionRule) checkCreateTable(ctx *mysql.CreateTableContif !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {return}- code := advisor.Ok+ code := advisorcode.Okif ctx.PartitionClause() != nil && ctx.PartitionClause().PartitionTypeDef() != nil {- code = advisor.CreateTablePartition+ code = advisorcode.CreateTablePartition}- if code != advisor.Ok {+ if code != advisorcode.Ok {r.AddAdvice(&storepb.Advice{Status: r.level,Code: code.Int32(),@@ -123,11 +125,11 @@ func (r *TableDisallowPartitionRule) checkAlterTable(ctx *mysql.AlterTableContexif !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {return}- code := advisor.Ok+ code := advisorcode.Okif ctx.AlterTableActions() != nil && ctx.AlterTableActions().PartitionClause() != nil && ctx.AlterTableActions().PartitionClause().PartitionTypeDef() != nil {- code = advisor.CreateTablePartition+ code = advisorcode.CreateTablePartition}- if code != advisor.Ok {+ if code != advisorcode.Ok {r.AddAdvice(&storepb.Advice{Status: r.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/mysql/rule_table_disallow_set_charset.go b/backend/plugin/advisor/mysql/rule_table_disallow_set_charset.goindex 7572856188..47c3158fa6 100644--- a/backend/plugin/advisor/mysql/rule_table_disallow_set_charset.go+++ b/backend/plugin/advisor/mysql/rule_table_disallow_set_charset.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -105,7 +106,7 @@ func (r *TableDisallowSetCharsetRule) checkCreateTable(ctx *mysql.CreateTableConif option.DefaultCharset() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisallowSetCharset.Int32(),+ Code: code.DisallowSetCharset.Int32(),Title: r.title,Content: fmt.Sprintf("Set charset on tables is disallowed, but \"%s\" uses", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -135,7 +136,7 @@ func (r *TableDisallowSetCharsetRule) checkAlterTable(ctx *mysql.AlterTableConteif alterListItem.Charset() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisallowSetCharset.Int32(),+ Code: code.DisallowSetCharset.Int32(),Title: r.title,Content: fmt.Sprintf("Set charset on tables is disallowed, but \"%s\" uses", r.text),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_table_disallow_trigger.go b/backend/plugin/advisor/mysql/rule_table_disallow_trigger.goindex 0c50e65a3d..a8921b4169 100644--- a/backend/plugin/advisor/mysql/rule_table_disallow_trigger.go+++ b/backend/plugin/advisor/mysql/rule_table_disallow_trigger.go@@ -4,6 +4,8 @@ import ("context""fmt"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -100,12 +102,12 @@ func (r *TableDisallowTriggerRule) checkCreateTrigger(ctx *mysql.CreateTriggerCoif !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {return}- code := advisor.Ok+ code := advisorcode.Okif ctx.TriggerName() != nil {- code = advisor.CreateTableTrigger+ code = advisorcode.CreateTableTrigger}- if code != advisor.Ok {+ if code != advisorcode.Ok {r.AddAdvice(&storepb.Advice{Status: r.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/mysql/rule_table_drop_naming_convention.go b/backend/plugin/advisor/mysql/rule_table_drop_naming_convention.goindex 9a0e68d842..6688228269 100644--- a/backend/plugin/advisor/mysql/rule_table_drop_naming_convention.go+++ b/backend/plugin/advisor/mysql/rule_table_drop_naming_convention.go@@ -5,6 +5,8 @@ import ("fmt""regexp"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -107,7 +109,7 @@ func (r *TableDropNamingConventionRule) checkDropTable(ctx *mysql.DropTableConteif !r.format.MatchString(tableName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableDropNamingConventionMismatch.Int32(),+ Code: code.TableDropNamingConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("`%s` mismatches drop table naming convention, naming format should be %q", tableName, r.format),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_table_limit_size.go b/backend/plugin/advisor/mysql/rule_table_limit_size.goindex b2df856cde..4f47a7e433 100644--- a/backend/plugin/advisor/mysql/rule_table_limit_size.go+++ b/backend/plugin/advisor/mysql/rule_table_limit_size.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -145,7 +147,7 @@ func (r *TableLimitSizeRule) generateAdvice() {if tableRows >= int64(r.maxRows) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableExceedLimitSize.Int32(),+ Code: code.TableExceedLimitSize.Int32(),Title: r.title,Content: fmt.Sprintf("Apply DDL on large table '%s' ( %d rows ) will lock table for a long time", tabName, tableRows),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + r.statementBaseLine),diff --git a/backend/plugin/advisor/mysql/rule_table_no_duplicate_index.go b/backend/plugin/advisor/mysql/rule_table_no_duplicate_index.goindex b5f1ee8d6d..679bad0cca 100644--- a/backend/plugin/advisor/mysql/rule_table_no_duplicate_index.go+++ b/backend/plugin/advisor/mysql/rule_table_no_duplicate_index.go@@ -7,6 +7,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -134,7 +136,7 @@ func (r *TableNoDuplicateIndexRule) checkCreateTable(ctx *mysql.CreateTableConteif index := hasDuplicateIndexes(r.indexList); index != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DuplicateIndexInTable.Int32(),+ Code: code.DuplicateIndexInTable.Int32(),Title: r.title,Content: fmt.Sprintf("`%s` has duplicate index `%s`", tableName, index.indexName),StartPosition: common.ConvertANTLRLineToPosition(index.line),@@ -165,7 +167,7 @@ func (r *TableNoDuplicateIndexRule) checkAlterTable(ctx *mysql.AlterTableContextif index := hasDuplicateIndexes(r.indexList); index != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DuplicateIndexInTable.Int32(),+ Code: code.DuplicateIndexInTable.Int32(),Title: r.title,Content: fmt.Sprintf("`%s` has duplicate index `%s`", tableName, index.indexName),StartPosition: common.ConvertANTLRLineToPosition(index.line),@@ -247,7 +249,7 @@ func (r *TableNoDuplicateIndexRule) checkCreateIndex(ctx *mysql.CreateIndexConteif index := hasDuplicateIndexes(r.indexList); index != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DuplicateIndexInTable.Int32(),+ Code: code.DuplicateIndexInTable.Int32(),Title: r.title,Content: fmt.Sprintf("`%s` has duplicate index `%s`", tableName, index.indexName),StartPosition: common.ConvertANTLRLineToPosition(index.line),diff --git a/backend/plugin/advisor/mysql/rule_table_no_fk.go b/backend/plugin/advisor/mysql/rule_table_no_fk.goindex bb398ebb4f..10b5ff1e5e 100644--- a/backend/plugin/advisor/mysql/rule_table_no_fk.go+++ b/backend/plugin/advisor/mysql/rule_table_no_fk.go@@ -5,6 +5,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -137,7 +139,7 @@ func (r *TableNoFKRule) handleTableConstraintDef(tableName string, ctx mysql.ITacase "FOREIGN":r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableHasFK.Int32(),+ Code: code.TableHasFK.Int32(),Title: r.title,Content: fmt.Sprintf("Foreign key is not allowed in the table `%s`", tableName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_table_require_charset.go b/backend/plugin/advisor/mysql/rule_table_require_charset.goindex e185a9e73b..974b66bd5c 100644--- a/backend/plugin/advisor/mysql/rule_table_require_charset.go+++ b/backend/plugin/advisor/mysql/rule_table_require_charset.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -106,7 +108,7 @@ func (r *TableRequireCharsetRule) checkCreateTable(ctx *mysql.CreateTableContextif !hasCharset {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoCharset.Int32(),+ Code: code.NoCharset.Int32(),Title: r.title,Content: fmt.Sprintf("Table %s does not have a character set specified", tableName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_table_require_collation.go b/backend/plugin/advisor/mysql/rule_table_require_collation.goindex ca6c13645c..46c946fa5f 100644--- a/backend/plugin/advisor/mysql/rule_table_require_collation.go+++ b/backend/plugin/advisor/mysql/rule_table_require_collation.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/bytebase/parser/mysql""github.com/pkg/errors"@@ -106,7 +108,7 @@ func (r *TableRequireCollationRule) checkCreateTable(ctx *mysql.CreateTableConteif !hasCollation {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoCollation.Int32(),+ Code: code.NoCollation.Int32(),Title: r.title,Content: fmt.Sprintf("Table %s does not have a collation specified", tableName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_table_require_pk.go b/backend/plugin/advisor/mysql/rule_table_require_pk.goindex e80592c46d..2b3bc7517b 100644--- a/backend/plugin/advisor/mysql/rule_table_require_pk.go+++ b/backend/plugin/advisor/mysql/rule_table_require_pk.go@@ -14,6 +14,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -230,7 +231,7 @@ func (r *TableRequirePKRule) generateAdviceList() {if len(r.tables[tableName]) == 0 {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableNoPK.Int32(),+ Code: code.TableNoPK.Int32(),Title: r.title,Content: fmt.Sprintf("Table `%s` requires PRIMARY KEY", tableName),StartPosition: common.ConvertANTLRLineToPosition(r.line[tableName]),diff --git a/backend/plugin/advisor/mysql/rule_table_text_fields_total_length.go b/backend/plugin/advisor/mysql/rule_table_text_fields_total_length.goindex fa4a5d7583..b21a93707d 100644--- a/backend/plugin/advisor/mysql/rule_table_text_fields_total_length.go+++ b/backend/plugin/advisor/mysql/rule_table_text_fields_total_length.go@@ -7,6 +7,8 @@ import ("strconv""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4""github.com/pkg/errors"@@ -122,7 +124,7 @@ func (r *TableTextFieldsTotalLengthRule) checkCreateTable(ctx *mysql.CreateTableif total > int64(r.maximum) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexCountExceedsLimit.Int32(),+ Code: code.IndexCountExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("Table %q total text column length (%d) exceeds the limit (%d).", tableName, total, r.maximum),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),@@ -156,7 +158,7 @@ func (r *TableTextFieldsTotalLengthRule) checkAlterTable(ctx *mysql.AlterTableCoif total > int64(r.maximum) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TotalTextLengthExceedsLimit.Int32(),+ Code: code.TotalTextLengthExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("Table %q total text column length (%d) exceeds the limit (%d).", tableName, total, r.maximum),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/mysql/rule_use_innodb.go b/backend/plugin/advisor/mysql/rule_use_innodb.goindex 1730104589..da59a6cd70 100644--- a/backend/plugin/advisor/mysql/rule_use_innodb.go+++ b/backend/plugin/advisor/mysql/rule_use_innodb.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -126,7 +127,7 @@ func (r *UseInnoDBRule) checkAlterTable(ctx *mysql.AlterTableContext) {if ctx.AlterTableActions().AlterCommandList().AlterList() == nil {return}- code := advisor.Ok+ code := advisorcode.Okfor _, option := range ctx.AlterTableActions().AlterCommandList().AlterList().AllCreateTableOptionsSpaceSeparated() {for _, op := range option.AllCreateTableOption() {if op.ENGINE_SYMBOL() != nil {@@ -135,14 +136,14 @@ func (r *UseInnoDBRule) checkAlterTable(ctx *mysql.AlterTableContext) {}engine := op.EngineRef().GetText()if strings.ToLower(engine) != innoDB {- code = advisor.NotInnoDBEngine+ code = advisorcode.NotInnoDBEnginebreak}}}}- if code != advisor.Ok {+ if code != advisorcode.Ok {content := "ALTER " + ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx)line := ctx.GetStart().GetLine()r.addAdvice(content, line)@@ -150,7 +151,7 @@ func (r *UseInnoDBRule) checkAlterTable(ctx *mysql.AlterTableContext) {}func (r *UseInnoDBRule) checkSetStatement(ctx *mysql.SetStatementContext) {- code := advisor.Ok+ code := advisorcode.Okif ctx.StartOptionValueList() == nil {return}@@ -170,11 +171,11 @@ func (r *UseInnoDBRule) checkSetStatement(ctx *mysql.SetStatementContext) {if optionValueNoOptionType.SetExprOrDefault() != nil {engine := optionValueNoOptionType.SetExprOrDefault().GetText()if strings.ToLower(engine) != innoDB {- code = advisor.NotInnoDBEngine+ code = advisorcode.NotInnoDBEngine}}- if code != advisor.Ok {+ if code != advisorcode.Ok {content := ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx)line := ctx.GetStart().GetLine()r.addAdvice(content, line)@@ -185,7 +186,7 @@ func (r *UseInnoDBRule) addAdvice(content string, lineNumber int) {lineNumber += r.baseLiner.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NotInnoDBEngine.Int32(),+ Code: advisorcode.NotInnoDBEngine.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s;\" doesn't use InnoDB engine", content),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),diff --git a/backend/plugin/advisor/mysql/rule_view_disallow_create.go b/backend/plugin/advisor/mysql/rule_view_disallow_create.goindex dd418d264e..37aac838b4 100644--- a/backend/plugin/advisor/mysql/rule_view_disallow_create.go+++ b/backend/plugin/advisor/mysql/rule_view_disallow_create.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -99,12 +100,12 @@ func (r *ViewDisallowCreateRule) checkCreateView(ctx *mysql.CreateViewContext) {if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {return}- code := advisor.Ok+ code := advisorcode.Okif ctx.ViewName() != nil {- code = advisor.DisallowCreateView+ code = advisorcode.DisallowCreateView}- if code != advisor.Ok {+ if code != advisorcode.Ok {r.AddAdvice(&storepb.Advice{Status: r.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/oceanbase/advisor_disallow_offline_ddl.go b/backend/plugin/advisor/oceanbase/advisor_disallow_offline_ddl.goindex 7dfbaab3f3..a6f54e2c33 100644--- a/backend/plugin/advisor/oceanbase/advisor_disallow_offline_ddl.go+++ b/backend/plugin/advisor/oceanbase/advisor_disallow_offline_ddl.go@@ -16,6 +16,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -252,7 +253,7 @@ func (*disallowOfflineDdlChecker) isPrimaryKeyColumn(ctx mysql.IFieldDefinitionCfunc (checker *disallowOfflineDdlChecker) advice(ctx antlr.ParserRuleContext, operation string) {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.StatementOfflineDDL.Int32(),+ Code: code.StatementOfflineDDL.Int32(),Title: checker.title,Content: fmt.Sprintf("%s is an offline DDL operation.", operation),StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/oceanbase/advisor_insert_row_limit.go b/backend/plugin/advisor/oceanbase/advisor_insert_row_limit.goindex b2e8f32983..ecbfb0e14a 100644--- a/backend/plugin/advisor/oceanbase/advisor_insert_row_limit.go+++ b/backend/plugin/advisor/oceanbase/advisor_insert_row_limit.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -107,7 +108,7 @@ func (checker *insertRowLimitChecker) handleInsertQueryExpression(ctx mysql.IInsif err != nil {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.InsertTooManyRows.Int32(),+ Code: code.InsertTooManyRows.Int32(),Title: checker.title,Content: fmt.Sprintf("\"%s\" dry runs failed: %s", checker.text, err.Error()),StartPosition: common.ConvertANTLRLineToPosition(checker.line),@@ -118,7 +119,7 @@ func (checker *insertRowLimitChecker) handleInsertQueryExpression(ctx mysql.IInsif err != nil {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: checker.title,Content: fmt.Sprintf("failed to get row count for \"%s\": %s", checker.text, err.Error()),StartPosition: common.ConvertANTLRLineToPosition(checker.line),@@ -126,7 +127,7 @@ func (checker *insertRowLimitChecker) handleInsertQueryExpression(ctx mysql.IIns} else if rowCount > int64(checker.maxRow) {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.InsertTooManyRows.Int32(),+ Code: code.InsertTooManyRows.Int32(),Title: checker.title,Content: fmt.Sprintf("\"%s\" inserts %d rows. The count exceeds %d.", checker.text, rowCount, checker.maxRow),StartPosition: common.ConvertANTLRLineToPosition(checker.line),@@ -149,7 +150,7 @@ func (checker *insertRowLimitChecker) handleNoInsertQueryExpression(ctx mysql.IIif len(allValues) > checker.maxRow {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.InsertTooManyRows.Int32(),+ Code: code.InsertTooManyRows.Int32(),Title: checker.title,Content: fmt.Sprintf("\"%s\" inserts %d rows. The count exceeds %d.", checker.text, len(allValues), checker.maxRow),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/oceanbase/advisor_statement_affected_row_limit.go b/backend/plugin/advisor/oceanbase/advisor_statement_affected_row_limit.goindex 86ec05ccc2..c77bd0e975 100644--- a/backend/plugin/advisor/oceanbase/advisor_statement_affected_row_limit.go+++ b/backend/plugin/advisor/oceanbase/advisor_statement_affected_row_limit.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql")@@ -105,7 +106,7 @@ func (checker *statementAffectedRowLimitChecker) handleStmt(lineNumber int) {if err != nil {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.StatementAffectedRowExceedsLimit.Int32(),+ Code: code.StatementAffectedRowExceedsLimit.Int32(),Title: checker.title,Content: fmt.Sprintf("\"%s\" dry runs failed: %s", checker.text, err.Error()),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),@@ -115,7 +116,7 @@ func (checker *statementAffectedRowLimitChecker) handleStmt(lineNumber int) {if err != nil {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: checker.title,Content: fmt.Sprintf("failed to get row count for \"%s\": %s", checker.text, err.Error()),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),@@ -123,7 +124,7 @@ func (checker *statementAffectedRowLimitChecker) handleStmt(lineNumber int) {} else if rowCount > int64(checker.maxRow) {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.StatementAffectedRowExceedsLimit.Int32(),+ Code: code.StatementAffectedRowExceedsLimit.Int32(),Title: checker.title,Content: fmt.Sprintf("\"%s\" affected %d rows (estimated). The count exceeds %d.", checker.text, rowCount, checker.maxRow),StartPosition: common.ConvertANTLRLineToPosition(lineNumber),diff --git a/backend/plugin/advisor/oracle/rule_builtin_prior_backup_check.go b/backend/plugin/advisor/oracle/rule_builtin_prior_backup_check.goindex e13714fbf6..1b6ce5d0d9 100644--- a/backend/plugin/advisor/oracle/rule_builtin_prior_backup_check.go+++ b/backend/plugin/advisor/oracle/rule_builtin_prior_backup_check.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -252,7 +253,7 @@ func (r *StatementPriorBackupCheckRule) handleSQLScriptExit() {Status: r.level,Title: r.title,Content: fmt.Sprintf("The size of the SQL statements exceeds the maximum limit of %d bytes for backup", common.MaxSheetCheckSize),- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: nil,})}@@ -263,7 +264,7 @@ func (r *StatementPriorBackupCheckRule) handleSQLScriptExit() {Status: r.level,Title: r.title,Content: fmt.Sprintf("Need database %q to do prior backup but it does not exist", databaseName),- Code: advisor.DatabaseNotExists.Int32(),+ Code: code.DatabaseNotExists.Int32(),StartPosition: nil,})r.adviceList = append(r.adviceList, adviceList...)@@ -275,7 +276,7 @@ func (r *StatementPriorBackupCheckRule) handleSQLScriptExit() {Status: r.level,Title: r.title,Content: "Prior backup cannot deal with mixed DDL and DML statements",- Code: int32(advisor.BuiltinPriorBackupCheck),+ Code: int32(code.BuiltinPriorBackupCheck),StartPosition: nil,})}@@ -303,7 +304,7 @@ func (r *StatementPriorBackupCheckRule) handleSQLScriptExit() {Status: r.level,Title: r.title,Content: fmt.Sprintf("Prior backup cannot handle mixed DML statements on the same table %q", key),- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: nil,})breakdiff --git a/backend/plugin/advisor/oracle/rule_column_add_not_null_column_require_default.go b/backend/plugin/advisor/oracle/rule_column_add_not_null_column_require_default.goindex e8de7b7549..e3ebd9f99b 100644--- a/backend/plugin/advisor/oracle/rule_column_add_not_null_column_require_default.go+++ b/backend/plugin/advisor/oracle/rule_column_add_not_null_column_require_default.go@@ -5,6 +5,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/plsql""github.com/pkg/errors"@@ -125,7 +127,7 @@ func (r *ColumnAddNotNullColumnRequireDefaultRule) handleColumnDefinitionExit(ctif ctx.DEFAULT() == nil {r.AddAdvice(r.level,- advisor.NotNullColumnWithNoDefault.Int32(),+ code.NotNullColumnWithNoDefault.Int32(),fmt.Sprintf("Adding not null column %q requires default.", normalizeIdentifier(ctx.Column_name(), r.currentDatabase)),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_column_comment_convention.go b/backend/plugin/advisor/oracle/rule_column_comment_convention.goindex 09c4902870..e4c61b0a98 100644--- a/backend/plugin/advisor/oracle/rule_column_comment_convention.go+++ b/backend/plugin/advisor/oracle/rule_column_comment_convention.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -161,7 +162,7 @@ func (r *ColumnCommentConventionRule) GetAdviceList() ([]*storepb.Advice, error)if r.payload.Required {r.AddAdvice(r.level,- advisor.CommentEmpty.Int32(),+ code.CommentEmpty.Int32(),fmt.Sprintf("Comment is required for column %s", normalizeIdentifierName(columnName)),common.ConvertANTLRLineToPosition(r.columnLine[columnName]),)@@ -170,7 +171,7 @@ func (r *ColumnCommentConventionRule) GetAdviceList() ([]*storepb.Advice, error)if r.payload.MaxLength > 0 && len(comment) > r.payload.MaxLength {r.AddAdvice(r.level,- advisor.CommentTooLong.Int32(),+ code.CommentTooLong.Int32(),fmt.Sprintf("Column %s comment is too long. The length of comment should be within %d characters", normalizeIdentifierName(columnName), r.payload.MaxLength),common.ConvertANTLRLineToPosition(r.columnLine[columnName]),)@@ -179,7 +180,7 @@ func (r *ColumnCommentConventionRule) GetAdviceList() ([]*storepb.Advice, error)if classification, _ := common.GetClassificationAndUserComment(comment, r.classificationConfig); classification == "" {r.AddAdvice(r.level,- advisor.CommentMissingClassification.Int32(),+ code.CommentMissingClassification.Int32(),fmt.Sprintf("Column %s comment requires classification", normalizeIdentifierName(columnName)),common.ConvertANTLRLineToPosition(r.columnLine[columnName]),)diff --git a/backend/plugin/advisor/oracle/rule_column_maximum_character_length.go b/backend/plugin/advisor/oracle/rule_column_maximum_character_length.goindex eb3978152d..fc926c2547 100644--- a/backend/plugin/advisor/oracle/rule_column_maximum_character_length.go+++ b/backend/plugin/advisor/oracle/rule_column_maximum_character_length.go@@ -6,6 +6,8 @@ import ("fmt""strconv"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/plsql""github.com/pkg/errors"@@ -116,7 +118,7 @@ func (r *ColumnMaximumCharacterLengthRule) handleDatatype(ctx *parser.DatatypeCor.AddAdvice(r.level,- advisor.CharLengthExceedsLimit.Int32(),+ code.CharLengthExceedsLimit.Int32(),fmt.Sprintf("The maximum character length is %d.", r.maximum),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_column_maximum_varchar_length.go b/backend/plugin/advisor/oracle/rule_column_maximum_varchar_length.goindex c5ff4d2910..f21bf44788 100644--- a/backend/plugin/advisor/oracle/rule_column_maximum_varchar_length.go+++ b/backend/plugin/advisor/oracle/rule_column_maximum_varchar_length.go@@ -6,6 +6,8 @@ import ("fmt""strconv"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/plsql""github.com/pkg/errors"@@ -116,7 +118,7 @@ func (r *ColumnMaximumVarcharLengthRule) handleDatatype(ctx *parser.DatatypeContr.AddAdvice(r.level,- advisor.VarcharLengthExceedsLimit.Int32(),+ code.VarcharLengthExceedsLimit.Int32(),fmt.Sprintf("The maximum varchar length is %d.", r.maximum),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_column_no_null.go b/backend/plugin/advisor/oracle/rule_column_no_null.goindex 709e908526..bf7945f027 100644--- a/backend/plugin/advisor/oracle/rule_column_no_null.go+++ b/backend/plugin/advisor/oracle/rule_column_no_null.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -125,7 +126,7 @@ func (r *ColumnNoNullRule) GetAdviceList() ([]*storepb.Advice, error) {line := r.nullableColumns[columnID]r.AddAdvice(r.level,- advisor.ColumnCannotNull.Int32(),+ code.ColumnCannotNull.Int32(),fmt.Sprintf("Column %q is nullable, which is not allowed.", lastIdentifier(columnID)),common.ConvertANTLRLineToPosition(line),)diff --git a/backend/plugin/advisor/oracle/rule_column_require.go b/backend/plugin/advisor/oracle/rule_column_require.goindex 104e1c206b..6a145eb0a8 100644--- a/backend/plugin/advisor/oracle/rule_column_require.go+++ b/backend/plugin/advisor/oracle/rule_column_require.go@@ -7,6 +7,8 @@ import ("slices""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/plsql""github.com/pkg/errors"@@ -140,7 +142,7 @@ func (r *ColumnRequireRule) handleCreateTableExit(ctx *parser.Create_tableContextableName := normalizeIdentifier(ctx.Table_name(), r.currentDatabase)r.AddAdvice(r.level,- advisor.NoRequiredColumn.Int32(),+ code.NoRequiredColumn.Int32(),fmt.Sprintf("Table %q requires columns: %s", tableName, strings.Join(missingColumns, ", ")),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStop().GetLine()),)@@ -173,7 +175,7 @@ func (r *ColumnRequireRule) handleAlterTableExit(ctx *parser.Alter_tableContext)tableName := lastIdentifier(normalizeIdentifier(ctx.Tableview_name(), r.currentDatabase))r.AddAdvice(r.level,- advisor.NoRequiredColumn.Int32(),+ code.NoRequiredColumn.Int32(),fmt.Sprintf("Table %q requires columns: %s", tableName, strings.Join(missingColumns, ", ")),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStop().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_column_require_default.go b/backend/plugin/advisor/oracle/rule_column_require_default.goindex c80ba3847c..ca011b6eb4 100644--- a/backend/plugin/advisor/oracle/rule_column_require_default.go+++ b/backend/plugin/advisor/oracle/rule_column_require_default.go@@ -6,6 +6,8 @@ import ("fmt""slices"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/plsql""github.com/pkg/errors"@@ -116,7 +118,7 @@ func (r *ColumnRequireDefaultRule) GetAdviceList() ([]*storepb.Advice, error) {line := r.noDefaultColumns[columnID]r.AddAdvice(r.level,- advisor.NoDefault.Int32(),+ code.NoDefault.Int32(),fmt.Sprintf("Column %q doesn't have default value", lastIdentifier(columnID)),common.ConvertANTLRLineToPosition(line),)diff --git a/backend/plugin/advisor/oracle/rule_column_type_disallow_list.go b/backend/plugin/advisor/oracle/rule_column_type_disallow_list.goindex 68f5891249..f4228bb8c1 100644--- a/backend/plugin/advisor/oracle/rule_column_type_disallow_list.go+++ b/backend/plugin/advisor/oracle/rule_column_type_disallow_list.go@@ -5,6 +5,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/plsql""github.com/pkg/errors"@@ -112,7 +114,7 @@ func (r *ColumnTypeDisallowListRule) handleColumnDefinition(ctx *parser.Column_dif r.isDisallowType(ctx.Datatype()) {r.AddAdvice(r.level,- advisor.DisabledColumnType.Int32(),+ code.DisabledColumnType.Int32(),fmt.Sprintf("Disallow column type %s but column \"%s\" is", ctx.Datatype().GetText(), normalizeIdentifier(ctx.Column_name(), r.currentDatabase)),common.ConvertANTLRLineToPosition(r.baseLine+ctx.Datatype().GetStart().GetLine()),)@@ -122,7 +124,7 @@ func (r *ColumnTypeDisallowListRule) handleColumnDefinition(ctx *parser.Column_dif ctx.Regular_id().GetText() == tp {r.AddAdvice(r.level,- advisor.DisabledColumnType.Int32(),+ code.DisabledColumnType.Int32(),fmt.Sprintf("Disallow column type %s but column \"%s\" is", ctx.Regular_id().GetText(), normalizeIdentifier(ctx.Column_name(), r.currentDatabase)),common.ConvertANTLRLineToPosition(r.baseLine+ctx.Regular_id().GetStart().GetLine()),)@@ -136,7 +138,7 @@ func (r *ColumnTypeDisallowListRule) handleModifyColProperties(ctx *parser.Modifif r.isDisallowType(ctx.Datatype()) {r.AddAdvice(r.level,- advisor.DisabledColumnType.Int32(),+ code.DisabledColumnType.Int32(),fmt.Sprintf("Disallow column type %s but column \"%s\" is", ctx.Datatype().GetText(), normalizeIdentifier(ctx.Column_name(), r.currentDatabase)),common.ConvertANTLRLineToPosition(r.baseLine+ctx.Datatype().GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_index_key_number_limit.go b/backend/plugin/advisor/oracle/rule_index_key_number_limit.goindex b2d2f56369..341a1f313f 100644--- a/backend/plugin/advisor/oracle/rule_index_key_number_limit.go+++ b/backend/plugin/advisor/oracle/rule_index_key_number_limit.go@@ -5,6 +5,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/plsql""github.com/pkg/errors"@@ -103,7 +105,7 @@ func (r *IndexKeyNumberLimitRule) handleTableIndexClause(ctx *parser.Table_indexif keys > r.max {r.AddAdvice(r.level,- advisor.IndexKeyNumberExceedsLimit.Int32(),+ code.IndexKeyNumberExceedsLimit.Int32(),fmt.Sprintf("Index key number should be less than or equal to %d", r.max),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)@@ -115,7 +117,7 @@ func (r *IndexKeyNumberLimitRule) handleOutOfLineConstraint(ctx *parser.Out_of_lif keys > r.max {r.AddAdvice(r.level,- advisor.IndexKeyNumberExceedsLimit.Int32(),+ code.IndexKeyNumberExceedsLimit.Int32(),fmt.Sprintf("Index key number should be less than or equal to %d", r.max),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_insert_must_specify_column.go b/backend/plugin/advisor/oracle/rule_insert_must_specify_column.goindex 7a2a38d521..13176a01ac 100644--- a/backend/plugin/advisor/oracle/rule_insert_must_specify_column.go+++ b/backend/plugin/advisor/oracle/rule_insert_must_specify_column.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -87,7 +88,7 @@ func (r *InsertMustSpecifyColumnRule) handleInsertIntoClause(ctx *parser.Insert_if ctx.Paren_column_list() == nil {r.AddAdvice(r.level,- advisor.InsertNotSpecifyColumn.Int32(),+ code.InsertNotSpecifyColumn.Int32(),"INSERT statement should specify column name.",common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_naming_identifier_case.go b/backend/plugin/advisor/oracle/rule_naming_identifier_case.goindex 4bb148dc08..3d4761013c 100644--- a/backend/plugin/advisor/oracle/rule_naming_identifier_case.go+++ b/backend/plugin/advisor/oracle/rule_naming_identifier_case.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -97,7 +98,7 @@ func (r *NamingIdentifierCaseRule) handleIDExpression(ctx *parser.Id_expressionCif identifier != strings.ToUpper(identifier) {r.AddAdvice(r.level,- advisor.NamingCaseMismatch.Int32(),+ code.NamingCaseMismatch.Int32(),fmt.Sprintf("Identifier %q should be upper case", identifier),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)@@ -106,7 +107,7 @@ func (r *NamingIdentifierCaseRule) handleIDExpression(ctx *parser.Id_expressionCif identifier != strings.ToLower(identifier) {r.AddAdvice(r.level,- advisor.NamingCaseMismatch.Int32(),+ code.NamingCaseMismatch.Int32(),fmt.Sprintf("Identifier %q should be lower case", identifier),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_naming_identifier_no_keyword.go b/backend/plugin/advisor/oracle/rule_naming_identifier_no_keyword.goindex ae27c6381c..3dcf899149 100644--- a/backend/plugin/advisor/oracle/rule_naming_identifier_no_keyword.go+++ b/backend/plugin/advisor/oracle/rule_naming_identifier_no_keyword.go@@ -5,6 +5,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/plsql""github.com/pkg/errors"@@ -89,7 +91,7 @@ func (r *NamingIdentifierNoKeywordRule) handleIDExpression(ctx *parser.Id_expresif plsqlparser.IsOracleKeyword(identifier) {r.AddAdvice(r.level,- advisor.NameIsKeywordIdentifier.Int32(),+ code.NameIsKeywordIdentifier.Int32(),fmt.Sprintf("Identifier %q is a keyword and should be avoided", identifier),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_naming_table.go b/backend/plugin/advisor/oracle/rule_naming_table.goindex d636c9a80e..814431a52c 100644--- a/backend/plugin/advisor/oracle/rule_naming_table.go+++ b/backend/plugin/advisor/oracle/rule_naming_table.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -102,7 +103,7 @@ func (r *NamingTableRule) handleCreateTable(ctx *parser.Create_tableContext) {if !r.format.MatchString(tableName) {r.AddAdvice(r.level,- advisor.NamingTableConventionMismatch.Int32(),+ code.NamingTableConventionMismatch.Int32(),fmt.Sprintf(`"%s" mismatches table naming convention, naming format should be %q`, tableName, r.format),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)@@ -110,7 +111,7 @@ func (r *NamingTableRule) handleCreateTable(ctx *parser.Create_tableContext) {if r.maxLength > 0 && len(tableName) > r.maxLength {r.AddAdvice(r.level,- advisor.NamingTableConventionMismatch.Int32(),+ code.NamingTableConventionMismatch.Int32(),fmt.Sprintf("\"%s\" mismatches table naming convention, its length should be within %d characters", tableName, r.maxLength),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)@@ -128,7 +129,7 @@ func (r *NamingTableRule) handleAlterTableProperties(ctx *parser.Alter_table_proif !r.format.MatchString(tableName) {r.AddAdvice(r.level,- advisor.NamingTableConventionMismatch.Int32(),+ code.NamingTableConventionMismatch.Int32(),fmt.Sprintf(`"%s" mismatches table naming convention, naming format should be %q`, tableName, r.format),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)@@ -136,7 +137,7 @@ func (r *NamingTableRule) handleAlterTableProperties(ctx *parser.Alter_table_proif r.maxLength > 0 && len(tableName) > r.maxLength {r.AddAdvice(r.level,- advisor.NamingTableConventionMismatch.Int32(),+ code.NamingTableConventionMismatch.Int32(),fmt.Sprintf("\"%s\" mismatches table naming convention, its length should be within %d characters", tableName, r.maxLength),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_naming_table_no_keyword.go b/backend/plugin/advisor/oracle/rule_naming_table_no_keyword.goindex dd87a00dff..25451d11bd 100644--- a/backend/plugin/advisor/oracle/rule_naming_table_no_keyword.go+++ b/backend/plugin/advisor/oracle/rule_naming_table_no_keyword.go@@ -5,6 +5,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/plsql""github.com/pkg/errors"@@ -93,7 +95,7 @@ func (r *NamingTableNoKeywordRule) handleCreateTable(ctx *parser.Create_tableConif plsqlparser.IsOracleKeyword(tableName) {r.AddAdvice(r.level,- advisor.NameIsKeywordIdentifier.Int32(),+ code.NameIsKeywordIdentifier.Int32(),fmt.Sprintf("Table name %q is a keyword identifier and should be avoided.", tableName),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)@@ -108,7 +110,7 @@ func (r *NamingTableNoKeywordRule) handleAlterTableProperties(ctx *parser.Alter_if plsqlparser.IsOracleKeyword(tableName) {r.AddAdvice(r.level,- advisor.NameIsKeywordIdentifier.Int32(),+ code.NameIsKeywordIdentifier.Int32(),fmt.Sprintf("Table name %q is a keyword identifier and should be avoided.", tableName),common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_select_no_select_all.go b/backend/plugin/advisor/oracle/rule_select_no_select_all.goindex b43aca6aa6..35c63fca09 100644--- a/backend/plugin/advisor/oracle/rule_select_no_select_all.go+++ b/backend/plugin/advisor/oracle/rule_select_no_select_all.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -87,7 +88,7 @@ func (r *SelectNoSelectAllRule) handleSelectedList(ctx *parser.Selected_listContif ctx.ASTERISK() != nil {r.AddAdvice(r.level,- advisor.StatementSelectAll.Int32(),+ code.StatementSelectAll.Int32(),"Avoid using SELECT *.",common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_statement_disallow_mix_in_ddl.go b/backend/plugin/advisor/oracle/rule_statement_disallow_mix_in_ddl.goindex 93a903d162..0f1272b038 100644--- a/backend/plugin/advisor/oracle/rule_statement_disallow_mix_in_ddl.go+++ b/backend/plugin/advisor/oracle/rule_statement_disallow_mix_in_ddl.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -87,7 +88,7 @@ func (r *StatementDisallowMixInDDLRule) handleUnitStatement(ctx *parser.Unit_staif ctx.Data_manipulation_language_statements() != nil {r.AddAdvice(r.level,- advisor.StatementDisallowMixDDLDML.Int32(),+ code.StatementDisallowMixDDLDML.Int32(),"Alter schema can only run DDL",common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_statement_disallow_mix_in_dml.go b/backend/plugin/advisor/oracle/rule_statement_disallow_mix_in_dml.goindex ceb4d053f7..755279d857 100644--- a/backend/plugin/advisor/oracle/rule_statement_disallow_mix_in_dml.go+++ b/backend/plugin/advisor/oracle/rule_statement_disallow_mix_in_dml.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -88,7 +89,7 @@ func (r *StatementDisallowMixInDMLRule) handleUnitStatement(ctx *parser.Unit_staif ctx.Data_manipulation_language_statements() == nil {r.AddAdvice(r.level,- advisor.StatementDisallowMixDDLDML.Int32(),+ code.StatementDisallowMixDDLDML.Int32(),"Data change can only run DML",common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_statement_dml_dry_run.go b/backend/plugin/advisor/oracle/rule_statement_dml_dry_run.goindex 2c1a371a15..64a07cc9bb 100644--- a/backend/plugin/advisor/oracle/rule_statement_dml_dry_run.go+++ b/backend/plugin/advisor/oracle/rule_statement_dml_dry_run.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -128,7 +129,7 @@ func (r *StatementDmlDryRunRule) handleStmt(text string, lineNumber int) {if _, err := advisor.Query(r.ctx, advisor.QueryContext{}, r.driver, storepb.Engine_ORACLE, fmt.Sprintf("EXPLAIN PLAN FOR %s", text)); err != nil {r.AddAdvice(r.level,- advisor.StatementDMLDryRunFailed.Int32(),+ code.StatementDMLDryRunFailed.Int32(),fmt.Sprintf("Failed to dry run statement at line %d: %v", lineNumber, err),common.ConvertANTLRLineToPosition(lineNumber),)diff --git a/backend/plugin/advisor/oracle/rule_table_comment_convention.go b/backend/plugin/advisor/oracle/rule_table_comment_convention.goindex acebb70ee5..31e10bab10 100644--- a/backend/plugin/advisor/oracle/rule_table_comment_convention.go+++ b/backend/plugin/advisor/oracle/rule_table_comment_convention.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -130,7 +131,7 @@ func (r *TableCommentConventionRule) GetAdviceList() ([]*storepb.Advice, error)if r.payload.Required {r.AddAdvice(r.level,- advisor.CommentEmpty.Int32(),+ code.CommentEmpty.Int32(),fmt.Sprintf("Comment is required for table %s", normalizeIdentifierName(tableName)),common.ConvertANTLRLineToPosition(r.tableLine[tableName]),)@@ -139,7 +140,7 @@ func (r *TableCommentConventionRule) GetAdviceList() ([]*storepb.Advice, error)if r.payload.MaxLength > 0 && len(comment) > r.payload.MaxLength {r.AddAdvice(r.level,- advisor.CommentTooLong.Int32(),+ code.CommentTooLong.Int32(),fmt.Sprintf("Table %s comment is too long. The length of comment should be within %d characters", normalizeIdentifierName(tableName), r.payload.MaxLength),common.ConvertANTLRLineToPosition(r.tableLine[tableName]),)@@ -148,7 +149,7 @@ func (r *TableCommentConventionRule) GetAdviceList() ([]*storepb.Advice, error)if classification, _ := common.GetClassificationAndUserComment(comment, r.classificationConfig); classification == "" {r.AddAdvice(r.level,- advisor.CommentMissingClassification.Int32(),+ code.CommentMissingClassification.Int32(),fmt.Sprintf("Table %s comment requires classification", normalizeIdentifierName(tableName)),common.ConvertANTLRLineToPosition(r.tableLine[tableName]),)diff --git a/backend/plugin/advisor/oracle/rule_table_no_foreign_key.go b/backend/plugin/advisor/oracle/rule_table_no_foreign_key.goindex a96ac8bf88..40dd523d34 100644--- a/backend/plugin/advisor/oracle/rule_table_no_foreign_key.go+++ b/backend/plugin/advisor/oracle/rule_table_no_foreign_key.go@@ -5,6 +5,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/plsql""github.com/pkg/errors"@@ -108,7 +110,7 @@ func (r *TableNoForeignKeyRule) GetAdviceList() ([]*storepb.Advice, error) {if hasFK {r.AddAdvice(r.level,- advisor.TableHasFK.Int32(),+ code.TableHasFK.Int32(),fmt.Sprintf("Foreign key is not allowed in the table %s.", normalizeIdentifierName(tableName)),common.ConvertANTLRLineToPosition(r.tableLine[tableName]),)diff --git a/backend/plugin/advisor/oracle/rule_table_require_pk.go b/backend/plugin/advisor/oracle/rule_table_require_pk.goindex 7b0be4908f..fb7f456a78 100644--- a/backend/plugin/advisor/oracle/rule_table_require_pk.go+++ b/backend/plugin/advisor/oracle/rule_table_require_pk.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -116,7 +117,7 @@ func (r *TableRequirePKRule) GetAdviceList() ([]*storepb.Advice, error) {if !hasPK {r.AddAdvice(r.level,- advisor.TableNoPK.Int32(),+ code.TableNoPK.Int32(),fmt.Sprintf("Table %s requires PRIMARY KEY.", normalizeIdentifierName(tableName)),common.ConvertANTLRLineToPosition(r.tableLine[tableName]),)diff --git a/backend/plugin/advisor/oracle/rule_where_no_leading_wildcard_like.go b/backend/plugin/advisor/oracle/rule_where_no_leading_wildcard_like.goindex 4ae6d8a3c4..93228b174d 100644--- a/backend/plugin/advisor/oracle/rule_where_no_leading_wildcard_like.go+++ b/backend/plugin/advisor/oracle/rule_where_no_leading_wildcard_like.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -97,7 +98,7 @@ func (r *WhereNoLeadingWildcardLikeRule) handleCompoundExpression(ctx *parser.Coif strings.HasPrefix(text, "'%") && strings.HasSuffix(text, "'") {r.AddAdvice(r.level,- advisor.StatementLeadingWildcardLike.Int32(),+ code.StatementLeadingWildcardLike.Int32(),"Avoid using leading wildcard LIKE.",common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStart().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_where_require_for_select.go b/backend/plugin/advisor/oracle/rule_where_require_for_select.goindex e47460e104..c845ecc66e 100644--- a/backend/plugin/advisor/oracle/rule_where_require_for_select.go+++ b/backend/plugin/advisor/oracle/rule_where_require_for_select.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -95,7 +96,7 @@ func (r *WhereRequireForSelectRule) handleQueryBlock(ctx *parser.Query_blockContif ctx.Where_clause() == nil {r.AddAdvice(r.level,- advisor.StatementNoWhere.Int32(),+ code.StatementNoWhere.Int32(),"WHERE clause is required for SELECT statement.",common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStop().GetLine()),)diff --git a/backend/plugin/advisor/oracle/rule_where_require_for_update_delete.go b/backend/plugin/advisor/oracle/rule_where_require_for_update_delete.goindex d80658e691..448d768252 100644--- a/backend/plugin/advisor/oracle/rule_where_require_for_update_delete.go+++ b/backend/plugin/advisor/oracle/rule_where_require_for_update_delete.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql")@@ -92,7 +93,7 @@ func (r *WhereRequireForUpdateDeleteRule) handleUpdateStatement(ctx *parser.Updaif ctx.Where_clause() == nil {r.AddAdvice(r.level,- advisor.StatementNoWhere.Int32(),+ code.StatementNoWhere.Int32(),"WHERE clause is required for UPDATE statement.",common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStop().GetLine()),)@@ -103,7 +104,7 @@ func (r *WhereRequireForUpdateDeleteRule) handleDeleteStatement(ctx *parser.Deleif ctx.Where_clause() == nil {r.AddAdvice(r.level,- advisor.StatementNoWhere.Int32(),+ code.StatementNoWhere.Int32(),"WHERE clause is required for DELETE statement.",common.ConvertANTLRLineToPosition(r.baseLine+ctx.GetStop().GetLine()),)diff --git a/backend/plugin/advisor/pg/advisor_builtin_prior_backup_check.go b/backend/plugin/advisor/pg/advisor_builtin_prior_backup_check.goindex 8394dfab72..7799f63c62 100644--- a/backend/plugin/advisor/pg/advisor_builtin_prior_backup_check.go+++ b/backend/plugin/advisor/pg/advisor_builtin_prior_backup_check.go@@ -14,6 +14,7 @@ import ("github.com/bytebase/bytebase/backend/common/log"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -71,7 +72,7 @@ func (*BuiltinPriorBackupCheckAdvisor) Check(_ context.Context, checkCtx advisorStatus: level,Title: title,Content: fmt.Sprintf("Need schema %q to do prior backup but it does not exist", schemaName),- Code: advisor.SchemaNotExists.Int32(),+ Code: code.SchemaNotExists.Int32(),StartPosition: nil,})}@@ -100,7 +101,7 @@ func (*BuiltinPriorBackupCheckAdvisor) Check(_ context.Context, checkCtx advisorStatus: level,Title: title,Content: fmt.Sprintf("The statement type is not the same for all statements on the same table %q", key),- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: nil,})break@@ -247,7 +248,7 @@ func (r *ddlRule) handleEveryRule(ctx antlr.ParserRuleContext) error {Status: r.level,Title: r.title,Content: fmt.Sprintf("Data change can only run DML, \"%s\" is not DML", r.getStatementText(ctx)),- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: &storepb.Position{Line: int32(ctx.GetStart().GetLine()),Column: 0,diff --git a/backend/plugin/advisor/pg/advisor_collation_allowlist.go b/backend/plugin/advisor/pg/advisor_collation_allowlist.goindex e309ec3150..94e0397491 100644--- a/backend/plugin/advisor/pg/advisor_collation_allowlist.go+++ b/backend/plugin/advisor/pg/advisor_collation_allowlist.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -192,7 +193,7 @@ func (r *collationAllowlistRule) addAdvice(collation string, ctx antlr.ParserRulr.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisabledCollation.Int32(),+ Code: code.DisabledCollation.Int32(),Title: r.title,Content: fmt.Sprintf("Use disabled collation \"%s\", related statement \"%s\"", collation, text),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_column_comment_convention.go b/backend/plugin/advisor/pg/advisor_column_comment_convention.goindex 108bb52198..d01a112d0f 100644--- a/backend/plugin/advisor/pg/advisor_column_comment_convention.go+++ b/backend/plugin/advisor/pg/advisor_column_comment_convention.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -228,7 +229,7 @@ func (r *columnCommentConventionRule) generateAdvice() []*storepb.Advice {if r.payload.Required {adviceList = append(adviceList, &storepb.Advice{Status: r.level,- Code: advisor.CommentEmpty.Int32(),+ Code: code.CommentEmpty.Int32(),Title: r.title,Content: fmt.Sprintf("Comment is required for column `%s.%s`", col.table, col.column),StartPosition: &storepb.Position{@@ -244,7 +245,7 @@ func (r *columnCommentConventionRule) generateAdvice() []*storepb.Advice {if r.payload.MaxLength > 0 && len(comment) > r.payload.MaxLength {adviceList = append(adviceList, &storepb.Advice{Status: r.level,- Code: advisor.CommentTooLong.Int32(),+ Code: code.CommentTooLong.Int32(),Title: r.title,Content: fmt.Sprintf("Column `%s.%s` comment is too long. The length of comment should be within %d characters", col.table, col.column, r.payload.MaxLength),StartPosition: &storepb.Position{@@ -259,7 +260,7 @@ func (r *columnCommentConventionRule) generateAdvice() []*storepb.Advice {if classification, _ := common.GetClassificationAndUserComment(comment, r.classificationConfig); classification == "" {adviceList = append(adviceList, &storepb.Advice{Status: r.level,- Code: advisor.CommentMissingClassification.Int32(),+ Code: code.CommentMissingClassification.Int32(),Title: r.title,Content: fmt.Sprintf("Column `%s.%s` comment requires classification", col.table, col.column),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_column_default_disallow_volatile.go b/backend/plugin/advisor/pg/advisor_column_default_disallow_volatile.goindex 2869f892d7..46f946dc4b 100644--- a/backend/plugin/advisor/pg/advisor_column_default_disallow_volatile.go+++ b/backend/plugin/advisor/pg/advisor_column_default_disallow_volatile.go@@ -5,6 +5,8 @@ import ("fmt""slices"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -213,7 +215,7 @@ func (r *columnDefaultDisallowVolatileRule) generateAdvice() {for _, column := range columnList {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoDefault.Int32(),+ Code: code.NoDefault.Int32(),Title: r.title,Content: fmt.Sprintf("Column %q.%q in schema %q has volatile DEFAULT", column.table, column.name, column.schema),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.go b/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.goindex 51095db0e9..e2c857228c 100644--- a/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.go+++ b/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -93,7 +95,7 @@ func (r *columnDisallowChangingTypeRule) handleAltertablestmt(ctx *parser.Altertr.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.ChangeColumnType.Int32(),+ Code: code.ChangeColumnType.Int32(),Title: r.title,Content: fmt.Sprintf("The statement \"%s\" changes column type", text),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_column_maximum_character_length.go b/backend/plugin/advisor/pg/advisor_column_maximum_character_length.goindex d4b260e84f..c04be90b9c 100644--- a/backend/plugin/advisor/pg/advisor_column_maximum_character_length.go+++ b/backend/plugin/advisor/pg/advisor_column_maximum_character_length.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -235,7 +237,7 @@ func (*columnMaximumCharacterLengthRule) getCharLength(typename parser.ITypenamefunc (r *columnMaximumCharacterLengthRule) addAdvice(tableName, columnName string, line int) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CharLengthExceedsLimit.Int32(),+ Code: code.CharLengthExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The length of the CHAR column %q in table %s is bigger than %d, please use VARCHAR instead", columnName, tableName, r.maximum),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_column_no_null.go b/backend/plugin/advisor/pg/advisor_column_no_null.goindex 29d5e58875..cd256d4265 100644--- a/backend/plugin/advisor/pg/advisor_column_no_null.go+++ b/backend/plugin/advisor/pg/advisor_column_no_null.go@@ -12,6 +12,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -133,7 +134,7 @@ func (r *columnNoNullRule) OnExit(ctx antlr.ParserRuleContext, _ string) error {for _, column := range columnList {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.ColumnCannotNull.Int32(),+ Code: code.ColumnCannotNull.Int32(),Title: r.title,Content: fmt.Sprintf("Column %q in %s cannot have NULL value", column.column, column.normalizeTableName()),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_column_require_default.go b/backend/plugin/advisor/pg/advisor_column_require_default.goindex a7e81c48b0..5db46335c6 100644--- a/backend/plugin/advisor/pg/advisor_column_require_default.go+++ b/backend/plugin/advisor/pg/advisor_column_require_default.go@@ -5,6 +5,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -106,7 +108,7 @@ func (r *columnRequireDefaultRule) handleCreatestmt(ctx *parser.CreatestmtContexif !r.hasDefault(colDef) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoDefault.Int32(),+ Code: code.NoDefault.Int32(),Title: r.title,Content: fmt.Sprintf("Column %q.%q in schema %q doesn't have DEFAULT", tableName, columnName, "public"),StartPosition: &storepb.Position{@@ -148,7 +150,7 @@ func (r *columnRequireDefaultRule) handleAltertablestmt(ctx *parser.Altertablestif !r.hasDefault(colDef) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoDefault.Int32(),+ Code: code.NoDefault.Int32(),Title: r.title,Content: fmt.Sprintf("Column %q.%q in schema %q doesn't have DEFAULT", tableName, columnName, "public"),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_column_required.go b/backend/plugin/advisor/pg/advisor_column_required.goindex 245ec14dd9..d80cfd3bb3 100644--- a/backend/plugin/advisor/pg/advisor_column_required.go+++ b/backend/plugin/advisor/pg/advisor_column_required.go@@ -6,6 +6,8 @@ import ("slices""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -142,7 +144,7 @@ func (r *columnRequirementRule) handleCreatestmt(ctx antlr.ParserRuleContext) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoRequiredColumn.Int32(),+ Code: code.NoRequiredColumn.Int32(),Title: r.title,Content: fmt.Sprintf("Table %q requires columns: %s", tableName, strings.Join(missingColumns, ", ")),StartPosition: &storepb.Position{@@ -184,7 +186,7 @@ func (r *columnRequirementRule) handleAltertablestmt(ctx antlr.ParserRuleContextif r.requiredColumnsMap[columnName] {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoRequiredColumn.Int32(),+ Code: code.NoRequiredColumn.Int32(),Title: r.title,Content: fmt.Sprintf("Table %q requires columns: %s", tableName, columnName),StartPosition: &storepb.Position{@@ -235,7 +237,7 @@ func (r *columnRequirementRule) handleRenamestmt(ctx antlr.ParserRuleContext) {if r.requiredColumnsMap[oldName] && oldName != newName {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoRequiredColumn.Int32(),+ Code: code.NoRequiredColumn.Int32(),Title: r.title,Content: fmt.Sprintf("Table %q requires columns: %s", tableName, oldName),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_column_type_disallow_list.go b/backend/plugin/advisor/pg/advisor_column_type_disallow_list.goindex e6117c095b..bd4a8d1407 100644--- a/backend/plugin/advisor/pg/advisor_column_type_disallow_list.go+++ b/backend/plugin/advisor/pg/advisor_column_type_disallow_list.go@@ -5,6 +5,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -182,7 +184,7 @@ func (r *columnTypeDisallowListRule) checkType(tableName, columnName string, typif matchedDisallowedType != "" {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisabledColumnType.Int32(),+ Code: code.DisabledColumnType.Int32(),Title: r.title,Content: fmt.Sprintf("Disallow column type %s but column %q.%q is", strings.ToUpper(matchedDisallowedType), tableName, columnName),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_comment_convention.go b/backend/plugin/advisor/pg/advisor_comment_convention.goindex 75a0982830..c57e586050 100644--- a/backend/plugin/advisor/pg/advisor_comment_convention.go+++ b/backend/plugin/advisor/pg/advisor_comment_convention.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -97,7 +98,7 @@ func (r *commentConventionRule) handleCommentstmt(ctx antlr.ParserRuleContext) {if r.maxLength > 0 && len(comment) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CommentTooLong.Int32(),+ Code: code.CommentTooLong.Int32(),Title: r.title,Content: fmt.Sprintf("The length of comment should be within %d characters", r.maxLength),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_encoding_allowlist.go b/backend/plugin/advisor/pg/advisor_encoding_allowlist.goindex d7f28ed496..05e1fc3607 100644--- a/backend/plugin/advisor/pg/advisor_encoding_allowlist.go+++ b/backend/plugin/advisor/pg/advisor_encoding_allowlist.go@@ -11,6 +11,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -103,7 +104,7 @@ func (r *encodingAllowlistRule) handleCreatedbstmt(ctx *parser.CreatedbstmtConteif !r.allowlist[strings.ToLower(encoding)] {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DisabledCharset.Int32(),+ Code: code.DisabledCharset.Int32(),Title: r.title,Content: fmt.Sprintf("\"\" used disabled encoding '%s'", strings.ToLower(encoding)),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_hello_world.go b/backend/plugin/advisor/pg/advisor_hello_world.goindex cb67428904..5917b444bf 100644--- a/backend/plugin/advisor/pg/advisor_hello_world.go+++ b/backend/plugin/advisor/pg/advisor_hello_world.go@@ -3,6 +3,8 @@ package pgimport ("context"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor")@@ -29,7 +31,7 @@ func (*HelloWorldAdvisor) Check(_ context.Context, _ advisor.Context) ([]*storepreturn []*storepb.Advice{{Status: storepb.Advice_WARNING,- Code: advisor.Ok.Int32(),+ Code: code.Ok.Int32(),Title: "Hello World Test",Content: "hello world",StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_index_create_concurrently.go b/backend/plugin/advisor/pg/advisor_index_create_concurrently.goindex 86b6c27c24..d2f8d0c52b 100644--- a/backend/plugin/advisor/pg/advisor_index_create_concurrently.go+++ b/backend/plugin/advisor/pg/advisor_index_create_concurrently.go@@ -3,6 +3,8 @@ package pgimport ("context"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -120,7 +122,7 @@ func (r *indexCreateConcurrentlyRule) handleIndexstmt(ctx *parser.IndexstmtConter.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CreateIndexUnconcurrently.Int32(),+ Code: code.CreateIndexUnconcurrently.Int32(),Title: r.title,Content: "Creating indexes will block writes on the table, unless use CONCURRENTLY",StartPosition: &storepb.Position{@@ -143,7 +145,7 @@ func (r *indexCreateConcurrentlyRule) handleDropstmt(ctx *parser.DropstmtContextif ctx.CONCURRENTLY() == nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DropIndexUnconcurrently.Int32(),+ Code: code.DropIndexUnconcurrently.Int32(),Title: r.title,Content: "Droping indexes will block writes on the table, unless use CONCURRENTLY",StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_index_key_number_limit.go b/backend/plugin/advisor/pg/advisor_index_key_number_limit.goindex 313f08ea6a..33af5fb6e8 100644--- a/backend/plugin/advisor/pg/advisor_index_key_number_limit.go+++ b/backend/plugin/advisor/pg/advisor_index_key_number_limit.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -111,7 +113,7 @@ func (r *indexKeyNumberLimitRule) handleIndexstmt(ctx antlr.ParserRuleContext) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexKeyNumberExceedsLimit.Int32(),+ Code: code.IndexKeyNumberExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The number of keys of index %q in table %q should be not greater than %d", indexName, tableName, r.max),StartPosition: &storepb.Position{@@ -225,7 +227,7 @@ func (r *indexKeyNumberLimitRule) checkTableConstraint(constraint parser.ITablecif r.max > 0 && keyCount > r.max {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexKeyNumberExceedsLimit.Int32(),+ Code: code.IndexKeyNumberExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The number of keys of index %q in table %q should be not greater than %d", constraintName, tableName, r.max),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.go b/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.goindex 445874b718..8aee20c74b 100644--- a/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.go+++ b/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -262,7 +264,7 @@ func findDuplicate(columns []string) string {func (r *indexNoDuplicateColumnRule) addAdvice(constraintType, constraintName, tableName, duplicateColumn string, line int) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.DuplicateColumnInIndex.Int32(),+ Code: code.DuplicateColumnInIndex.Int32(),Title: r.title,Content: fmt.Sprintf("%s %q has duplicate column %q.%q", constraintType, constraintName, tableName, duplicateColumn),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_index_primary_key_type_allowlist.go b/backend/plugin/advisor/pg/advisor_index_primary_key_type_allowlist.goindex 738000cd42..e5467f660e 100644--- a/backend/plugin/advisor/pg/advisor_index_primary_key_type_allowlist.go+++ b/backend/plugin/advisor/pg/advisor_index_primary_key_type_allowlist.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -180,7 +182,7 @@ func (r *indexPrimaryKeyTypeAllowlistRule) isTypeAllowed(columnType string) boolfunc (r *indexPrimaryKeyTypeAllowlistRule) addAdvice(columnName, columnType string, line int) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexPKType.Int32(),+ Code: code.IndexPKType.Int32(),Title: r.title,Content: fmt.Sprintf("The column %q is one of the primary key, but its type %q is not in allowlist", columnName, columnType),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_index_total_number_limit.go b/backend/plugin/advisor/pg/advisor_index_total_number_limit.goindex f23962c2d3..1c3f7650f5 100644--- a/backend/plugin/advisor/pg/advisor_index_total_number_limit.go+++ b/backend/plugin/advisor/pg/advisor_index_total_number_limit.go@@ -5,6 +5,8 @@ import ("fmt""slices"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -124,7 +126,7 @@ func (r *indexTotalNumberLimitRule) generateAdvice() {if tableInfo != nil && tableInfo.CountIndex() > r.max {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.IndexCountExceedsLimit.Int32(),+ Code: code.IndexCountExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The count of index in table %q.%q should be no more than %d, but found %d", table.schema, table.table, r.max, tableInfo.CountIndex()),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_insert_disallow_order_by_rand.go b/backend/plugin/advisor/pg/advisor_insert_disallow_order_by_rand.goindex b4a7c3e396..1bde147729 100644--- a/backend/plugin/advisor/pg/advisor_insert_disallow_order_by_rand.go+++ b/backend/plugin/advisor/pg/advisor_insert_disallow_order_by_rand.go@@ -11,6 +11,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -97,7 +98,7 @@ func (r *insertDisallowOrderByRandRule) handleInsertstmt(ctx antlr.ParserRuleConr.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.InsertUseOrderByRand.Int32(),+ Code: code.InsertUseOrderByRand.Int32(),Title: r.title,Content: fmt.Sprintf("The INSERT statement uses ORDER BY random() or random_between(), related statement \"%s\"", stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_insert_must_specify_column.go b/backend/plugin/advisor/pg/advisor_insert_must_specify_column.goindex bc0899955a..d6780d363c 100644--- a/backend/plugin/advisor/pg/advisor_insert_must_specify_column.go+++ b/backend/plugin/advisor/pg/advisor_insert_must_specify_column.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -101,7 +102,7 @@ func (r *insertMustSpecifyColumnRule) handleInsertstmt(ctx antlr.ParserRuleConter.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.InsertNotSpecifyColumn.Int32(),+ Code: code.InsertNotSpecifyColumn.Int32(),Title: r.title,Content: fmt.Sprintf("The INSERT statement must specify columns but \"%s\" does not", stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_insert_row_limit.go b/backend/plugin/advisor/pg/advisor_insert_row_limit.goindex 2a0497a624..4db38027bf 100644--- a/backend/plugin/advisor/pg/advisor_insert_row_limit.go+++ b/backend/plugin/advisor/pg/advisor_insert_row_limit.go@@ -15,6 +15,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -122,7 +123,7 @@ func (r *insertRowLimitRule) handleInsertstmt(ctx *parser.InsertstmtContext) {return}- code := advisor.Ok+ code := advisorcode.Okrows := int64(0)// Check if this is INSERT ... VALUES or INSERT ... SELECT@@ -132,7 +133,7 @@ func (r *insertRowLimitRule) handleInsertstmt(ctx *parser.InsertstmtContext) {if rowCount > 0 {// This is INSERT ... VALUESif rowCount > r.maxRow {- code = advisor.InsertTooManyRows+ code = advisorcode.InsertTooManyRowsrows = int64(rowCount)}} else if r.driver != nil {@@ -151,7 +152,7 @@ func (r *insertRowLimitRule) handleInsertstmt(ctx *parser.InsertstmtContext) {if err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.InsertTooManyRows.Int32(),+ Code: advisorcode.InsertTooManyRows.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" dry runs failed: %s", stmtText, err.Error()),StartPosition: &storepb.Position{@@ -166,7 +167,7 @@ func (r *insertRowLimitRule) handleInsertstmt(ctx *parser.InsertstmtContext) {if err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: advisorcode.Internal.Int32(),Title: r.title,Content: fmt.Sprintf("failed to get row count for \"%s\": %s", stmtText, err.Error()),StartPosition: &storepb.Position{@@ -178,13 +179,13 @@ func (r *insertRowLimitRule) handleInsertstmt(ctx *parser.InsertstmtContext) {}if rowCount > int64(r.maxRow) {- code = advisor.InsertTooManyRows+ code = advisorcode.InsertTooManyRowsrows = rowCount}}}- if code != advisor.Ok {+ if code != advisorcode.Ok {stmtText := extractStatementText(r.statementsText, ctx.GetStart().GetLine(), ctx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,diff --git a/backend/plugin/advisor/pg/advisor_migration_compatibility.go b/backend/plugin/advisor/pg/advisor_migration_compatibility.goindex 0d002defa4..bb0352e33c 100644--- a/backend/plugin/advisor/pg/advisor_migration_compatibility.go+++ b/backend/plugin/advisor/pg/advisor_migration_compatibility.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -116,7 +117,7 @@ func (r *compatibilityRule) handleDropdbstmt(ctx antlr.ParserRuleContext) {stmtText := extractStatementText(r.statementsText, dropdbstmtCtx.GetStart().GetLine(), dropdbstmtCtx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityDropDatabase.Int32(),+ Code: advisorcode.CompatibilityDropDatabase.Int32(),Title: r.title,Content: fmt.Sprintf(`"%s" may cause incompatibility with the existing data and code`, stmtText),StartPosition: &storepb.Position{@@ -144,7 +145,7 @@ func (r *compatibilityRule) handleDropstmt(ctx antlr.ParserRuleContext) {stmtText := extractStatementText(r.statementsText, dropstmtCtx.GetStart().GetLine(), dropstmtCtx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityDropTable.Int32(),+ Code: advisorcode.CompatibilityDropTable.Int32(),Title: r.title,Content: fmt.Sprintf(`"%s" may cause incompatibility with the existing data and code`, stmtText),StartPosition: &storepb.Position{@@ -167,7 +168,7 @@ func (r *compatibilityRule) handleRenamestmt(ctx antlr.ParserRuleContext) {return}- code := advisor.Ok+ code := advisorcode.Ok// Check if this is a column renameif renamestmtCtx.Opt_column() != nil && renamestmtCtx.Opt_column().COLUMN() != nil {@@ -175,15 +176,15 @@ func (r *compatibilityRule) handleRenamestmt(ctx antlr.ParserRuleContext) {if renamestmtCtx.Relation_expr() != nil && renamestmtCtx.Relation_expr().Qualified_name() != nil {tableName := extractTableName(renamestmtCtx.Relation_expr().Qualified_name())if r.lastCreateTable != tableName {- code = advisor.CompatibilityRenameColumn+ code = advisorcode.CompatibilityRenameColumn}}} else {// RENAME TABLE/VIEW- code = advisor.CompatibilityRenameTable+ code = advisorcode.CompatibilityRenameTable}- if code != advisor.Ok {+ if code != advisorcode.Ok {stmtText := extractStatementText(r.statementsText, renamestmtCtx.GetStart().GetLine(), renamestmtCtx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,@@ -225,16 +226,16 @@ func (r *compatibilityRule) handleAltertablestmt(ctx antlr.ParserRuleContext) {allCmds := altertablestmtCtx.Alter_table_cmds().AllAlter_table_cmd()for _, cmd := range allCmds {- code := advisor.Ok+ code := advisorcode.Ok// DROP COLUMNif cmd.DROP() != nil && cmd.COLUMN() != nil {- code = advisor.CompatibilityDropColumn+ code = advisorcode.CompatibilityDropColumn}// ALTER COLUMN TYPEif cmd.ALTER() != nil && cmd.TYPE_P() != nil {- code = advisor.CompatibilityAlterColumn+ code = advisorcode.CompatibilityAlterColumn}// ADD CONSTRAINT@@ -245,17 +246,17 @@ func (r *compatibilityRule) handleAltertablestmt(ctx antlr.ParserRuleContext) {// PRIMARY KEYif elem.PRIMARY() != nil && elem.KEY() != nil {- code = advisor.CompatibilityAddPrimaryKey+ code = advisorcode.CompatibilityAddPrimaryKey}// UNIQUEif elem.UNIQUE() != nil {- code = advisor.CompatibilityAddUniqueKey+ code = advisorcode.CompatibilityAddUniqueKey}// FOREIGN KEYif elem.FOREIGN() != nil && elem.KEY() != nil {- code = advisor.CompatibilityAddForeignKey+ code = advisorcode.CompatibilityAddForeignKey}// CHECK - only if NOT VALID is not present@@ -272,13 +273,13 @@ func (r *compatibilityRule) handleAltertablestmt(ctx antlr.ParserRuleContext) {}}if !hasNotValid {- code = advisor.CompatibilityAddCheck+ code = advisorcode.CompatibilityAddCheck}}}}- if code != advisor.Ok {+ if code != advisorcode.Ok {stmtText := extractStatementText(r.statementsText, altertablestmtCtx.GetStart().GetLine(), altertablestmtCtx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,@@ -325,7 +326,7 @@ func (r *compatibilityRule) handleIndexstmt(ctx antlr.ParserRuleContext) {stmtText := extractStatementText(r.statementsText, indexstmtCtx.GetStart().GetLine(), indexstmtCtx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityAddUniqueKey.Int32(),+ Code: advisorcode.CompatibilityAddUniqueKey.Int32(),Title: r.title,Content: fmt.Sprintf(`"%s" may cause incompatibility with the existing data and code`, stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_naming_column.go b/backend/plugin/advisor/pg/advisor_naming_column.goindex b469ccf38c..c904e809b9 100644--- a/backend/plugin/advisor/pg/advisor_naming_column.go+++ b/backend/plugin/advisor/pg/advisor_naming_column.go@@ -11,6 +11,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -193,7 +194,7 @@ func (r *namingColumnConventionRule) checkColumnName(tableName, columnName strinif !r.format.MatchString(columnName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingColumnConventionMismatch.Int32(),+ Code: code.NamingColumnConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\".\"%s\" mismatches column naming convention, naming format should be %q", tableName, columnName, r.format),StartPosition: &storepb.Position{@@ -206,7 +207,7 @@ func (r *namingColumnConventionRule) checkColumnName(tableName, columnName strinif r.maxLength > 0 && len(columnName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingColumnConventionMismatch.Int32(),+ Code: code.NamingColumnConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\".\"%s\" mismatches column naming convention, its length should be within %d characters", tableName, columnName, r.maxLength),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.goindex d09666a67b..3e7dd71907 100644--- a/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.go+++ b/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.go@@ -12,6 +12,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -298,7 +299,7 @@ func (r *namingFKConventionRule) checkFKMetadata(fkData *fkMetaData) {if err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for foreign key naming convention rule",Content: fmt.Sprintf("Failed to compile regex: %s", err.Error()),StartPosition: &storepb.Position{@@ -312,7 +313,7 @@ func (r *namingFKConventionRule) checkFKMetadata(fkData *fkMetaData) {if !regex.MatchString(fkData.indexName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingFKConventionMismatch.Int32(),+ Code: code.NamingFKConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`Foreign key in table "%s" mismatches the naming convention, expect %q but found "%s"`, fkData.tableName, regex, fkData.indexName),StartPosition: &storepb.Position{@@ -325,7 +326,7 @@ func (r *namingFKConventionRule) checkFKMetadata(fkData *fkMetaData) {if r.maxLength > 0 && len(fkData.indexName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingFKConventionMismatch.Int32(),+ Code: code.NamingFKConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`Foreign key "%s" in table "%s" mismatches the naming convention, its length should be within %d characters`, fkData.indexName, fkData.tableName, r.maxLength),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_naming_fully_qualified.go b/backend/plugin/advisor/pg/advisor_naming_fully_qualified.goindex 8123eaf577..aba2735a50 100644--- a/backend/plugin/advisor/pg/advisor_naming_fully_qualified.go+++ b/backend/plugin/advisor/pg/advisor_naming_fully_qualified.go@@ -11,6 +11,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/parser/base"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -266,7 +267,7 @@ func (r *fullyQualifiedObjectNameRule) handleSelectstmt(ctx *parser.SelectstmtCoif !r.isFullyQualified(objName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: int32(advisor.NamingNotFullyQualifiedName),+ Code: int32(code.NamingNotFullyQualifiedName),Title: r.title,Content: fmt.Sprintf("unqualified object name: '%s'", objName),StartPosition: &storepb.Position{@@ -290,7 +291,7 @@ func (r *fullyQualifiedObjectNameRule) checkQualifiedName(ctx parser.IQualified_if !r.isFullyQualified(objName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: int32(advisor.NamingNotFullyQualifiedName),+ Code: int32(code.NamingNotFullyQualifiedName),Title: r.title,Content: fmt.Sprintf("unqualified object name: '%s'", objName),StartPosition: &storepb.Position{@@ -314,7 +315,7 @@ func (r *fullyQualifiedObjectNameRule) checkAnyName(ctx parser.IAny_nameContext,if !r.isFullyQualified(objName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: int32(advisor.NamingNotFullyQualifiedName),+ Code: int32(code.NamingNotFullyQualifiedName),Title: r.title,Content: fmt.Sprintf("unqualified object name: '%s'", objName),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_naming_index_convention.go b/backend/plugin/advisor/pg/advisor_naming_index_convention.goindex 61bf61e43b..af56fb3b88 100644--- a/backend/plugin/advisor/pg/advisor_naming_index_convention.go+++ b/backend/plugin/advisor/pg/advisor_naming_index_convention.go@@ -12,6 +12,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -193,7 +194,7 @@ func (r *namingIndexConventionRule) checkIndexName(indexName, tableName string,if err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for index naming convention rule",Content: fmt.Sprintf("Failed to compile regex: %v", err),StartPosition: &storepb.Position{@@ -207,7 +208,7 @@ func (r *namingIndexConventionRule) checkIndexName(indexName, tableName string,if !regex.MatchString(indexName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingIndexConventionMismatch.Int32(),+ Code: code.NamingIndexConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("Index in table %q mismatches the naming convention, expect %q but found %q", tableName, regex, indexName),StartPosition: &storepb.Position{@@ -220,7 +221,7 @@ func (r *namingIndexConventionRule) checkIndexName(indexName, tableName string,if r.maxLength > 0 && len(indexName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingIndexConventionMismatch.Int32(),+ Code: code.NamingIndexConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("Index %q in table %q mismatches the naming convention, its length should be within %d characters", indexName, tableName, r.maxLength),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.goindex d45eff4129..f7a290dc48 100644--- a/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go+++ b/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go@@ -12,6 +12,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -341,7 +342,7 @@ func (r *namingPKConventionRule) checkPKName(pkData *pkMetaData) {if err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for primary key naming convention rule",Content: fmt.Sprintf("Failed to compile regex: %v", err),StartPosition: &storepb.Position{@@ -355,7 +356,7 @@ func (r *namingPKConventionRule) checkPKName(pkData *pkMetaData) {if !regex.MatchString(pkData.pkName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingPKConventionMismatch.Int32(),+ Code: code.NamingPKConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`Primary key in table "%s" mismatches the naming convention, expect %q but found "%s"`, pkData.tableName, regex, pkData.pkName),StartPosition: &storepb.Position{@@ -368,7 +369,7 @@ func (r *namingPKConventionRule) checkPKName(pkData *pkMetaData) {if r.maxLength > 0 && len(pkData.pkName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingPKConventionMismatch.Int32(),+ Code: code.NamingPKConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`Primary key "%s" in table "%s" mismatches the naming convention, its length should be within %d characters`, pkData.pkName, pkData.tableName, r.maxLength),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_naming_table.go b/backend/plugin/advisor/pg/advisor_naming_table.goindex 11d0c48ca6..d6cf5e597d 100644--- a/backend/plugin/advisor/pg/advisor_naming_table.go+++ b/backend/plugin/advisor/pg/advisor_naming_table.go@@ -11,6 +11,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -119,7 +120,7 @@ func (r *namingTableConventionRule) checkTableName(tableName string, ctx antlr.Pif !r.format.MatchString(tableName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`"%s" mismatches table naming convention, naming format should be %q`, tableName, r.format),StartPosition: &storepb.Position{@@ -131,7 +132,7 @@ func (r *namingTableConventionRule) checkTableName(tableName string, ctx antlr.Pif r.maxLength > 0 && len(tableName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" mismatches table naming convention, its length should be within %d characters", tableName, r.maxLength),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.goindex dbe6b1454a..04d8b2f58e 100644--- a/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go+++ b/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go@@ -12,6 +12,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -361,7 +362,7 @@ func (r *namingUKConventionRule) checkUniqueKeyName(indexName, tableName string,if err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for unique key naming convention rule",Content: fmt.Sprintf("Failed to compile regex for unique key naming convention: %v", err),})@@ -371,7 +372,7 @@ func (r *namingUKConventionRule) checkUniqueKeyName(indexName, tableName string,if !regex.MatchString(indexName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingUKConventionMismatch.Int32(),+ Code: code.NamingUKConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`Unique key in table "%s" mismatches the naming convention, expect %q but found "%s"`, tableName, regex, indexName),StartPosition: &storepb.Position{@@ -384,7 +385,7 @@ func (r *namingUKConventionRule) checkUniqueKeyName(indexName, tableName string,if r.maxLength > 0 && len(indexName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingUKConventionMismatch.Int32(),+ Code: code.NamingUKConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`Unique key "%s" in table "%s" mismatches the naming convention, its length should be within %d characters`, indexName, tableName, r.maxLength),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_add_check_not_valid.go b/backend/plugin/advisor/pg/advisor_statement_add_check_not_valid.goindex 67f7cc4d45..1998b002b9 100644--- a/backend/plugin/advisor/pg/advisor_statement_add_check_not_valid.go+++ b/backend/plugin/advisor/pg/advisor_statement_add_check_not_valid.go@@ -9,6 +9,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -108,7 +109,7 @@ func (r *statementAddCheckNotValidRule) handleColconstraint(ctx antlr.ParserRule// (when NOT VALID is present, it's parsed as a table constraint)r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementAddCheckWithValidation.Int32(),+ Code: code.StatementAddCheckWithValidation.Int32(),Title: r.title,Content: "Adding check constraints with validation will block reads and writes. You can add check constraints not valid and then validate separately",StartPosition: &storepb.Position{@@ -167,7 +168,7 @@ func (r *statementAddCheckNotValidRule) handleTableconstraint(ctx antlr.ParserRuif !hasNotValid {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementAddCheckWithValidation.Int32(),+ Code: code.StatementAddCheckWithValidation.Int32(),Title: r.title,Content: "Adding check constraints with validation will block reads and writes. You can add check constraints not valid and then validate separately",StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_add_fk_not_valid.go b/backend/plugin/advisor/pg/advisor_statement_add_fk_not_valid.goindex 29c299dd1a..e6db8b0881 100644--- a/backend/plugin/advisor/pg/advisor_statement_add_fk_not_valid.go+++ b/backend/plugin/advisor/pg/advisor_statement_add_fk_not_valid.go@@ -9,6 +9,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -124,7 +125,7 @@ func (r *statementAddFKNotValidRule) handleAltertablestmt(ctx antlr.ParserRuleCoif !hasNotValid {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementAddFKWithValidation.Int32(),+ Code: code.StatementAddFKWithValidation.Int32(),Title: r.title,Content: "Adding foreign keys with validation will block reads and writes. You can add check foreign keys not valid and then validate separately",StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.go b/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.goindex 25f57d0f8b..784d75a9a4 100644--- a/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.go+++ b/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -157,7 +158,7 @@ func (r *statementAffectedRowLimitRule) checkAffectedRows(ctx antlr.ParserRuleCoif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.InsertTooManyRows.Int32(),+ Code: code.InsertTooManyRows.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" dry runs failed: %s", normalizedStmt, err.Error()),StartPosition: &storepb.Position{@@ -172,7 +173,7 @@ func (r *statementAffectedRowLimitRule) checkAffectedRows(ctx antlr.ParserRuleCoif err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: r.title,Content: fmt.Sprintf("failed to get row count for \"%s\": %s", normalizedStmt, err.Error()),StartPosition: &storepb.Position{@@ -186,7 +187,7 @@ func (r *statementAffectedRowLimitRule) checkAffectedRows(ctx antlr.ParserRuleCoif rowCount > int64(r.maxRow) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementAffectedRowExceedsLimit.Int32(),+ Code: code.StatementAffectedRowExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The statement \"%s\" affected %d rows (estimated). The count exceeds %d.", normalizedStmt, rowCount, r.maxRow),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_check_set_role_variable.go b/backend/plugin/advisor/pg/advisor_statement_check_set_role_variable.goindex 73abaec079..73a4e77b1c 100644--- a/backend/plugin/advisor/pg/advisor_statement_check_set_role_variable.go+++ b/backend/plugin/advisor/pg/advisor_statement_check_set_role_variable.go@@ -9,6 +9,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -46,7 +47,7 @@ func (*StatementCheckSetRoleVariable) Check(_ context.Context, checkCtx advisor.if !rule.hasSetRole {rule.AddAdvice(&storepb.Advice{Status: level,- Code: advisor.StatementCheckSetRoleVariable.Int32(),+ Code: code.StatementCheckSetRoleVariable.Int32(),Title: rule.title,Content: "No SET ROLE statement found.",StartPosition: nil,diff --git a/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.go b/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.goindex a43eeb1773..959394338b 100644--- a/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.go+++ b/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.go@@ -9,6 +9,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -85,7 +86,7 @@ func (r *statementCreateSpecifySchemaRule) handleCreatestmt(ctx antlr.ParserRuleif schemaName == "" {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementCreateWithoutSchemaName.Int32(),+ Code: code.StatementCreateWithoutSchemaName.Int32(),Title: r.title,Content: "Table schema should be specified.",StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_add_column_with_default.go b/backend/plugin/advisor/pg/advisor_statement_disallow_add_column_with_default.goindex b8d0e79afd..59b1c26efe 100644--- a/backend/plugin/advisor/pg/advisor_statement_disallow_add_column_with_default.go+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_add_column_with_default.go@@ -9,6 +9,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -95,7 +96,7 @@ func (r *statementDisallowAddColumnWithDefaultRule) handleAltertablestmt(ctx *paif constraintElem.DEFAULT() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementAddColumnWithDefault.Int32(),+ Code: code.StatementAddColumnWithDefault.Int32(),Title: r.title,Content: "Adding column with DEFAULT will locked the whole table and rewriting each rows",StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_add_not_null.go b/backend/plugin/advisor/pg/advisor_statement_disallow_add_not_null.goindex 9c11a37cff..9a2ca1196a 100644--- a/backend/plugin/advisor/pg/advisor_statement_disallow_add_not_null.go+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_add_not_null.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -95,7 +96,7 @@ func (r *statementDisallowAddNotNullRule) handleAltertablestmt(ctx antlr.ParserRcolumnName := pgparser.NormalizePostgreSQLColid(allColIDs[0])r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementAddNotNull.Int32(),+ Code: code.StatementAddNotNull.Int32(),Title: r.title,Content: fmt.Sprintf("Setting NOT NULL will block reads and writes. You can use CHECK (%q IS NOT NULL) instead", columnName),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_commit.go b/backend/plugin/advisor/pg/advisor_statement_disallow_commit.goindex 7139d528b4..262ecde3a9 100644--- a/backend/plugin/advisor/pg/advisor_statement_disallow_commit.go+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_commit.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -81,7 +82,7 @@ func (r *statementDisallowCommitRule) OnEnter(ctx antlr.ParserRuleContext, nodeTstmtText := extractStatementText(r.statementsText, transactionCtx.GetStart().GetLine(), transactionCtx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementDisallowCommit.Int32(),+ Code: code.StatementDisallowCommit.Int32(),Title: r.title,Content: fmt.Sprintf("Commit is not allowed, related statement: \"%s\"", stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_mix_in_ddl.go b/backend/plugin/advisor/pg/advisor_statement_disallow_mix_in_ddl.goindex 81037ecb99..3dc46f1ff0 100644--- a/backend/plugin/advisor/pg/advisor_statement_disallow_mix_in_ddl.go+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_mix_in_ddl.go@@ -8,6 +8,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -144,7 +145,7 @@ func (r *statementDisallowMixInDDLRule) addDMLAdvice(ctx antlr.ParserRuleContextr.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementDisallowMixDDLDML.Int32(),+ Code: code.StatementDisallowMixDDLDML.Int32(),Title: r.title,Content: fmt.Sprintf("Alter schema can only run DDL, %q is not DDL", stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_mix_in_dml.go b/backend/plugin/advisor/pg/advisor_statement_disallow_mix_in_dml.goindex d0327ddb5c..f8ec4c1a5f 100644--- a/backend/plugin/advisor/pg/advisor_statement_disallow_mix_in_dml.go+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_mix_in_dml.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -342,7 +343,7 @@ func (r *statementDisallowMixInDMLRule) addDDLAdvice(ctx antlr.ParserRuleContextr.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementDisallowMixDDLDML.Int32(),+ Code: code.StatementDisallowMixDDLDML.Int32(),Title: r.title,Content: fmt.Sprintf("Data change can only run DML, %q is not DML", stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_on_del_cascade.go b/backend/plugin/advisor/pg/advisor_statement_disallow_on_del_cascade.goindex a6217a737b..f007002f3f 100644--- a/backend/plugin/advisor/pg/advisor_statement_disallow_on_del_cascade.go+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_on_del_cascade.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -107,7 +108,7 @@ func (r *statementDisallowOnDelCascadeRule) handleKeyDelete(ctx *parser.Key_dele}r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementDisallowCascade.Int32(),+ Code: code.StatementDisallowCascade.Int32(),Title: r.title,Content: "The CASCADE option is not permitted for ON DELETE clauses",StartPosition: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_rm_tbl_cascade.go b/backend/plugin/advisor/pg/advisor_statement_disallow_rm_tbl_cascade.goindex 4977f6533c..254226495c 100644--- a/backend/plugin/advisor/pg/advisor_statement_disallow_rm_tbl_cascade.go+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_rm_tbl_cascade.go@@ -9,6 +9,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -89,7 +90,7 @@ func (r *statementDisallowRemoveTblCascadeRule) handleDropstmt(ctx *parser.Dropsif r.hasCascadeOption(ctx.Opt_drop_behavior()) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementDisallowCascade.Int32(),+ Code: code.StatementDisallowCascade.Int32(),Title: r.title,Content: "The use of CASCADE is not permitted when removing a table",StartPosition: &storepb.Position{@@ -109,7 +110,7 @@ func (r *statementDisallowRemoveTblCascadeRule) handleTruncatestmt(ctx *parser.Tif r.hasCascadeOption(ctx.Opt_drop_behavior()) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementDisallowCascade.Int32(),+ Code: code.StatementDisallowCascade.Int32(),Title: r.title,Content: "The use of CASCADE is not permitted when removing a table",StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.go b/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.goindex eb730c077a..8aa38ae58c 100644--- a/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.go+++ b/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -156,7 +157,7 @@ func (r *statementDMLDryRunRule) checkDMLDryRun(ctx antlr.ParserRuleContext) {if err != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementDMLDryRunFailed.Int32(),+ Code: code.StatementDMLDryRunFailed.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" dry runs failed: %s", normalizedStmt, err.Error()),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_maximum_limit_value.go b/backend/plugin/advisor/pg/advisor_statement_maximum_limit_value.goindex b0926cb978..32e19348d9 100644--- a/backend/plugin/advisor/pg/advisor_statement_maximum_limit_value.go+++ b/backend/plugin/advisor/pg/advisor_statement_maximum_limit_value.go@@ -11,6 +11,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -85,7 +86,7 @@ func (r *statementMaximumLimitValueRule) OnEnter(ctx antlr.ParserRuleContext, noif limitValue > 0 && limitValue > r.limitMaxValue {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementExceedMaximumLimitValue.Int32(),+ Code: code.StatementExceedMaximumLimitValue.Int32(),Title: r.title,Content: fmt.Sprintf("The limit value %d exceeds the maximum allowed value %d", limitValue, r.limitMaxValue),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.go b/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.goindex ad25494c6a..a5cb7aa508 100644--- a/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.go+++ b/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -180,7 +181,7 @@ func (r *statementMergeAlterTableRule) generateAdvice() []*storepb.Advice {if table.count > 1 {adviceList = append(adviceList, &storepb.Advice{Status: r.level,- Code: advisor.StatementRedundantAlterTable.Int32(),+ Code: code.StatementRedundantAlterTable.Int32(),Title: r.title,Content: fmt.Sprintf("There are %d statements to modify table `%s`", table.count, table.name),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_no_leading_wildcard_like.go b/backend/plugin/advisor/pg/advisor_statement_no_leading_wildcard_like.goindex 157e5fe6d6..9ac0f88590 100644--- a/backend/plugin/advisor/pg/advisor_statement_no_leading_wildcard_like.go+++ b/backend/plugin/advisor/pg/advisor_statement_no_leading_wildcard_like.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -110,7 +111,7 @@ func (r *statementNoLeadingWildcardLikeRule) handleAExprLike(ctx *parser.A_expr_stmtText := extractStatementText(r.statementsText, stmtCtx.GetStart().GetLine(), stmtCtx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementLeadingWildcardLike.Int32(),+ Code: code.StatementLeadingWildcardLike.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" uses leading wildcard LIKE", stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_no_select_all.go b/backend/plugin/advisor/pg/advisor_statement_no_select_all.goindex 70e9b81762..98be21fdea 100644--- a/backend/plugin/advisor/pg/advisor_statement_no_select_all.go+++ b/backend/plugin/advisor/pg/advisor_statement_no_select_all.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -125,7 +126,7 @@ func (r *noSelectAllRule) handleSimpleSelectPramary(ctx *parser.Simple_select_prr.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementSelectAll.Int32(),+ Code: code.StatementSelectAll.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" uses SELECT all", stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_non_transactional.go b/backend/plugin/advisor/pg/advisor_statement_non_transactional.goindex 60cef71c33..f94823bbd0 100644--- a/backend/plugin/advisor/pg/advisor_statement_non_transactional.go+++ b/backend/plugin/advisor/pg/advisor_statement_non_transactional.go@@ -9,6 +9,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/db/pg")@@ -108,7 +109,7 @@ func (r *nonTransactionalRule) checkStatement(ctx antlr.ParserRuleContext) {if pg.IsNonTransactionStatement(stmtText) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNonTransactional.Int32(),+ Code: code.StatementNonTransactional.Int32(),Title: r.title,Content: "This statement is non-transactional",StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go b/backend/plugin/advisor/pg/advisor_statement_object_owner_check.goindex 475fa5adf5..a10d825a98 100644--- a/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go+++ b/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common/log"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/parser/pg""github.com/bytebase/bytebase/backend/store/model")@@ -155,7 +156,7 @@ func (r *statementObjectOwnerCheckRule) checkSchemaOwnership(schemaName string,Status: r.level,Title: r.title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, r.currentRole),- Code: advisor.StatementObjectOwnerCheck.Int32(),+ Code: code.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(line),Column: 0,@@ -188,7 +189,7 @@ func (r *statementObjectOwnerCheckRule) checkTableOwnership(schemaName, tableNamStatus: r.level,Title: r.title,Content: fmt.Sprintf("Table \"%s\" is owned by \"%s\", but the current role is \"%s\".", tableName, owner, r.currentRole),- Code: advisor.StatementObjectOwnerCheck.Int32(),+ Code: code.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(line),Column: 0,@@ -312,7 +313,7 @@ func (r *statementObjectOwnerCheckRule) handleCreateschemastmt(ctx *parser.CreatStatus: r.level,Title: r.title,Content: fmt.Sprintf("Database \"%s\" is owned by \"%s\", but the current role is \"%s\".", r.dbMetadata.GetName(), owner, r.currentRole),- Code: advisor.StatementObjectOwnerCheck.Int32(),+ Code: code.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(ctx.GetStart().GetLine()),Column: 0,diff --git a/backend/plugin/advisor/pg/advisor_statement_where_required_select.go b/backend/plugin/advisor/pg/advisor_statement_where_required_select.goindex cb3533ba87..20d0a44ffa 100644--- a/backend/plugin/advisor/pg/advisor_statement_where_required_select.go+++ b/backend/plugin/advisor/pg/advisor_statement_where_required_select.go@@ -9,6 +9,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -122,7 +123,7 @@ func (r *statementWhereRequiredSelectRule) checkSelect(r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" requires WHERE clause", stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_statement_where_required_update_delete.go b/backend/plugin/advisor/pg/advisor_statement_where_required_update_delete.goindex 51de7264e0..ccb701468c 100644--- a/backend/plugin/advisor/pg/advisor_statement_where_required_update_delete.go+++ b/backend/plugin/advisor/pg/advisor_statement_where_required_update_delete.go@@ -10,6 +10,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -88,7 +89,7 @@ func (r *statementWhereRequiredRule) handleUpdatestmt(ctx *parser.UpdatestmtContstmtText := extractStatementText(r.statementsText, ctx.GetStart().GetLine(), ctx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" requires WHERE clause", stmtText),StartPosition: &storepb.Position{@@ -109,7 +110,7 @@ func (r *statementWhereRequiredRule) handleDeletestmt(ctx *parser.DeletestmtContstmtText := extractStatementText(r.statementsText, ctx.GetStart().GetLine(), ctx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" requires WHERE clause", stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_table_comment_convention.go b/backend/plugin/advisor/pg/advisor_table_comment_convention.goindex 043281f507..edc07ac60b 100644--- a/backend/plugin/advisor/pg/advisor_table_comment_convention.go+++ b/backend/plugin/advisor/pg/advisor_table_comment_convention.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -65,7 +66,7 @@ func (*TableCommentConventionAdvisor) Check(_ context.Context, checkCtx advisor.if rule.payload.Required {rule.AddAdvice(&storepb.Advice{Status: rule.level,- Code: advisor.CommentEmpty.Int32(),+ Code: code.CommentEmpty.Int32(),Title: rule.title,Content: fmt.Sprintf("Comment is required for table `%s`", tableInfo.displayName),StartPosition: &storepb.Position{@@ -79,7 +80,7 @@ func (*TableCommentConventionAdvisor) Check(_ context.Context, checkCtx advisor.if rule.payload.MaxLength > 0 && len(comment) > rule.payload.MaxLength {rule.AddAdvice(&storepb.Advice{Status: rule.level,- Code: advisor.CommentTooLong.Int32(),+ Code: code.CommentTooLong.Int32(),Title: rule.title,Content: fmt.Sprintf("Table `%s` comment is too long. The length of comment should be within %d characters", tableInfo.displayName, rule.payload.MaxLength),StartPosition: &storepb.Position{@@ -92,7 +93,7 @@ func (*TableCommentConventionAdvisor) Check(_ context.Context, checkCtx advisor.if classification, _ := common.GetClassificationAndUserComment(comment, rule.classificationConfig); classification == "" {rule.AddAdvice(&storepb.Advice{Status: rule.level,- Code: advisor.CommentMissingClassification.Int32(),+ Code: code.CommentMissingClassification.Int32(),Title: rule.title,Content: fmt.Sprintf("Table `%s` comment requires classification", tableInfo.displayName),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_table_disallow_partition.go b/backend/plugin/advisor/pg/advisor_table_disallow_partition.goindex 874bdfa81f..01339a3839 100644--- a/backend/plugin/advisor/pg/advisor_table_disallow_partition.go+++ b/backend/plugin/advisor/pg/advisor_table_disallow_partition.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -89,7 +91,7 @@ func (r *tableDisallowPartitionRule) handleCreatestmt(ctx *parser.CreatestmtContr.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CreateTablePartition.Int32(),+ Code: code.CreateTablePartition.Int32(),Title: r.title,Content: fmt.Sprintf("Table partition is forbidden, but %q creates", stmtText),StartPosition: &storepb.Position{@@ -115,7 +117,7 @@ func (r *tableDisallowPartitionRule) handlePartitionCmd(ctx *parser.Partition_cmstmtText := extractStatementText(r.statementsText, alterTableCtx.GetStart().GetLine(), alterTableCtx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CreateTablePartition.Int32(),+ Code: code.CreateTablePartition.Int32(),Title: r.title,Content: fmt.Sprintf("Table partition is forbidden, but %q creates", stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.goindex a0845e22c4..b8374a9b0c 100644--- a/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.go+++ b/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.go@@ -5,6 +5,8 @@ import ("fmt""regexp"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -101,7 +103,7 @@ func (r *tableDropNamingConventionRule) handleDropstmt(ctx *parser.DropstmtConteif tableName != "" && !r.format.MatchString(tableName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableDropNamingConventionMismatch.Int32(),+ Code: code.TableDropNamingConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("`%s` mismatches drop table naming convention, naming format should be %q", tableName, r.format),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_table_no_fk.go b/backend/plugin/advisor/pg/advisor_table_no_fk.goindex 42c94259dc..6d1fa71abc 100644--- a/backend/plugin/advisor/pg/advisor_table_no_fk.go+++ b/backend/plugin/advisor/pg/advisor_table_no_fk.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"@@ -178,7 +180,7 @@ func (r *tableNoFKRule) addFKAdvice(schemaName, tableName string, ctx antlr.ParsstmtText := extractStatementText(r.statementsText, ctx.GetStart().GetLine(), ctx.GetStop().GetLine())r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableHasFK.Int32(),+ Code: code.TableHasFK.Int32(),Title: r.title,Content: fmt.Sprintf("Foreign key is not allowed in the table %q.%q, related statement: \"%s\"", schemaName, tableName, stmtText),StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/advisor_table_require_pk.go b/backend/plugin/advisor/pg/advisor_table_require_pk.goindex fd9132a308..294c6170cf 100644--- a/backend/plugin/advisor/pg/advisor_table_require_pk.go+++ b/backend/plugin/advisor/pg/advisor_table_require_pk.go@@ -11,6 +11,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -192,7 +193,7 @@ func (r *tableRequirePKRule) validateFinalState() {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableNoPK.Int32(),+ Code: code.TableNoPK.Int32(),Title: r.title,Content: content,StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/sdl_check.go b/backend/plugin/advisor/pg/sdl_check.goindex 12214cb347..2b25b4ef77 100644--- a/backend/plugin/advisor/pg/sdl_check.go+++ b/backend/plugin/advisor/pg/sdl_check.go@@ -3,11 +3,12 @@ package pgimport ("fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/postgresql"storepb "github.com/bytebase/bytebase/backend/generated-go/store"- "github.com/bytebase/bytebase/backend/plugin/advisor"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -58,7 +59,7 @@ func (c *sdlChecker) EnterCreatestmt(ctx *parser.CreatestmtContext) {if schemaName == "" {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLRequireSchemaName.Int32(),+ Code: code.SDLRequireSchemaName.Int32(),Title: "sdl.require-schema-name",Content: fmt.Sprintf("Table '%s' is created without explicit schema name.\n\n"+@@ -110,7 +111,7 @@ func (c *sdlChecker) EnterIndexstmt(ctx *parser.IndexstmtContext) {if indexName == "" {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLRequireIndexName.Int32(),+ Code: code.SDLRequireIndexName.Int32(),Title: "sdl.require-index-name",Content: "Index is created without an explicit name.\n\n" +"SDL requires all indexes to have explicit names.\n\n" +@@ -158,7 +159,7 @@ func (c *sdlChecker) EnterIndexstmt(ctx *parser.IndexstmtContext) {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLRequireSchemaName.Int32(),+ Code: code.SDLRequireSchemaName.Int32(),Title: "sdl.require-schema-name",Content: content,StartPosition: &storepb.Position{@@ -182,7 +183,7 @@ func (c *sdlChecker) EnterViewstmt(ctx *parser.ViewstmtContext) {if schemaName == "" {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLRequireSchemaName.Int32(),+ Code: code.SDLRequireSchemaName.Int32(),Title: "sdl.require-schema-name",Content: fmt.Sprintf("View '%s' is created without explicit schema name.\n\n"+@@ -214,7 +215,7 @@ func (c *sdlChecker) EnterCreateseqstmt(ctx *parser.CreateseqstmtContext) {if schemaName == "" {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLRequireSchemaName.Int32(),+ Code: code.SDLRequireSchemaName.Int32(),Title: "sdl.require-schema-name",Content: fmt.Sprintf("Sequence '%s' is created without explicit schema name.\n\n"+@@ -245,7 +246,7 @@ func (c *sdlChecker) EnterCreatefunctionstmt(ctx *parser.CreatefunctionstmtConteif schemaName == "" {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLRequireSchemaName.Int32(),+ Code: code.SDLRequireSchemaName.Int32(),Title: "sdl.require-schema-name",Content: fmt.Sprintf("Function '%s' is created without explicit schema name.\n\n"+@@ -277,7 +278,7 @@ func (c *sdlChecker) EnterAlterseqstmt(ctx *parser.AlterseqstmtContext) {if schemaName == "" {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLRequireSchemaName.Int32(),+ Code: code.SDLRequireSchemaName.Int32(),Title: "sdl.require-schema-name",Content: fmt.Sprintf("Sequence '%s' is altered without explicit schema name.\n\n"+@@ -354,7 +355,7 @@ func (c *sdlChecker) checkColumnConstraints(columnDef parser.IColumnDefContext,c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLDisallowColumnConstraint.Int32(),+ Code: code.SDLDisallowColumnConstraint.Int32(),Title: "sdl.disallow-column-constraint",Content: content,StartPosition: &storepb.Position{@@ -427,7 +428,7 @@ func (c *sdlChecker) checkTableConstraintName(constraint parser.ITableconstraintc.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLRequireConstraintName.Int32(),+ Code: code.SDLRequireConstraintName.Int32(),Title: "sdl.require-constraint-name",Content: content,StartPosition: &storepb.Position{@@ -476,7 +477,7 @@ func (c *sdlChecker) checkForeignKeyReferenceSchema(constraint parser.ITableconsc.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLRequireSchemaName.Int32(),+ Code: code.SDLRequireSchemaName.Int32(),Title: "sdl.require-schema-name",Content: content,StartPosition: &storepb.Position{@@ -525,7 +526,7 @@ func (c *sdlChecker) checkColumnForeignKeyReferenceSchema(elem parser.IColconstrc.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLRequireSchemaName.Int32(),+ Code: code.SDLRequireSchemaName.Int32(),Title: "sdl.require-schema-name",Content: content,StartPosition: &storepb.Position{diff --git a/backend/plugin/advisor/pg/sdl_check_test.go b/backend/plugin/advisor/pg/sdl_check_test.goindex b056f8c5b8..eea3b59f72 100644--- a/backend/plugin/advisor/pg/sdl_check_test.go+++ b/backend/plugin/advisor/pg/sdl_check_test.go@@ -3,10 +3,11 @@ package pgimport ("testing"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/stretchr/testify/require"storepb "github.com/bytebase/bytebase/backend/generated-go/store"- "github.com/bytebase/bytebase/backend/plugin/advisor")func TestCheckSDLStyle(t *testing.T) {@@ -14,7 +15,7 @@ func TestCheckSDLStyle(t *testing.T) {name stringstatement stringwantCount int- wantCodes []advisor.Code+ wantCodes []code.Code}{{name: "Valid SDL - table with schema name, table-level named constraints",@@ -56,7 +57,7 @@ func TestCheckSDLStyle(t *testing.T) {CONSTRAINT pk_users PRIMARY KEY (id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireSchemaName},+ wantCodes: []code.Code{code.SDLRequireSchemaName},},{name: "Error - Column-level PRIMARY KEY constraint",@@ -65,7 +66,7 @@ func TestCheckSDLStyle(t *testing.T) {email TEXT);`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDisallowColumnConstraint},+ wantCodes: []code.Code{code.SDLDisallowColumnConstraint},},{name: "Error - Column-level UNIQUE constraint",@@ -74,7 +75,7 @@ func TestCheckSDLStyle(t *testing.T) {email TEXT UNIQUE);`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDisallowColumnConstraint},+ wantCodes: []code.Code{code.SDLDisallowColumnConstraint},},{name: "Error - Column-level CHECK constraint",@@ -83,7 +84,7 @@ func TestCheckSDLStyle(t *testing.T) {email TEXT);`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDisallowColumnConstraint},+ wantCodes: []code.Code{code.SDLDisallowColumnConstraint},},{name: "Error - Column-level FOREIGN KEY constraint",@@ -92,7 +93,7 @@ func TestCheckSDLStyle(t *testing.T) {user_id INTEGER REFERENCES public.users(id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDisallowColumnConstraint},+ wantCodes: []code.Code{code.SDLDisallowColumnConstraint},},{name: "Error - Table-level constraint without name",@@ -101,7 +102,7 @@ func TestCheckSDLStyle(t *testing.T) {PRIMARY KEY (id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireConstraintName},+ wantCodes: []code.Code{code.SDLRequireConstraintName},},{name: "Error - Table-level UNIQUE without name",@@ -111,7 +112,7 @@ func TestCheckSDLStyle(t *testing.T) {UNIQUE (email));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireConstraintName},+ wantCodes: []code.Code{code.SDLRequireConstraintName},},{name: "Error - Table-level CHECK without name",@@ -120,7 +121,7 @@ func TestCheckSDLStyle(t *testing.T) {CHECK (id > 0));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireConstraintName},+ wantCodes: []code.Code{code.SDLRequireConstraintName},},{name: "Error - Table-level FOREIGN KEY without name",@@ -134,7 +135,7 @@ func TestCheckSDLStyle(t *testing.T) {FOREIGN KEY (user_id) REFERENCES public.users(id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireConstraintName},+ wantCodes: []code.Code{code.SDLRequireConstraintName},},{name: "Error - Multiple disallowed column-level constraints on one column",@@ -143,8 +144,8 @@ func TestCheckSDLStyle(t *testing.T) {email TEXT);`,wantCount: 1, // One column with multiple disallowed constraints- wantCodes: []advisor.Code{- advisor.SDLDisallowColumnConstraint,+ wantCodes: []code.Code{+ code.SDLDisallowColumnConstraint,},},{@@ -154,9 +155,9 @@ func TestCheckSDLStyle(t *testing.T) {email TEXT UNIQUE);`,wantCount: 2, // Two columns with disallowed constraints- wantCodes: []advisor.Code{- advisor.SDLDisallowColumnConstraint,- advisor.SDLDisallowColumnConstraint,+ wantCodes: []code.Code{+ code.SDLDisallowColumnConstraint,+ code.SDLDisallowColumnConstraint,},},{@@ -178,9 +179,9 @@ func TestCheckSDLStyle(t *testing.T) {PRIMARY KEY (id));`,wantCount: 2,- wantCodes: []advisor.Code{- advisor.SDLRequireSchemaName,- advisor.SDLRequireConstraintName,+ wantCodes: []code.Code{+ code.SDLRequireSchemaName,+ code.SDLRequireConstraintName,},},{@@ -190,10 +191,10 @@ func TestCheckSDLStyle(t *testing.T) {UNIQUE (id));`,wantCount: 3,- wantCodes: []advisor.Code{- advisor.SDLRequireSchemaName,- advisor.SDLDisallowColumnConstraint,- advisor.SDLRequireConstraintName,+ wantCodes: []code.Code{+ code.SDLRequireSchemaName,+ code.SDLDisallowColumnConstraint,+ code.SDLRequireConstraintName,},},{@@ -206,13 +207,13 @@ func TestCheckSDLStyle(t *testing.T) {name: "Error - CREATE INDEX without schema name",statement: `CREATE INDEX idx_users_email ON users (email);`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireSchemaName},+ wantCodes: []code.Code{code.SDLRequireSchemaName},},{name: "Error - CREATE INDEX without schema name (quoted table)",statement: `CREATE INDEX "idx_departments_budget" ON ONLY "departments" (budget);`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireSchemaName},+ wantCodes: []code.Code{code.SDLRequireSchemaName},},{name: "Valid SDL - CREATE UNIQUE INDEX with schema name",@@ -224,22 +225,22 @@ func TestCheckSDLStyle(t *testing.T) {name: "Error - CREATE UNIQUE INDEX without schema name",statement: `CREATE UNIQUE INDEX idx_users_email ON users (email);`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireSchemaName},+ wantCodes: []code.Code{code.SDLRequireSchemaName},},{name: "Error - CREATE INDEX (unnamed) without schema name",statement: `CREATE INDEX ON users (email);`,wantCount: 2, // Both: missing index name AND missing schema name- wantCodes: []advisor.Code{- advisor.SDLRequireIndexName,- advisor.SDLRequireSchemaName,+ wantCodes: []code.Code{+ code.SDLRequireIndexName,+ code.SDLRequireSchemaName,},},{name: "Error - CREATE INDEX (unnamed) with schema name",statement: `CREATE INDEX ON public.users (email);`,wantCount: 1, // Only missing index name- wantCodes: []advisor.Code{advisor.SDLRequireIndexName},+ wantCodes: []code.Code{code.SDLRequireIndexName},},{name: "Valid SDL - CREATE VIEW with schema name",@@ -253,7 +254,7 @@ CREATE VIEW public.active_users AS SELECT * FROM public.users WHERE active = trustatement: `CREATE TABLE public.users (id INTEGER, active BOOLEAN, CONSTRAINT pk_users PRIMARY KEY (id));CREATE VIEW active_users AS SELECT * FROM public.users WHERE active = true;`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireSchemaName},+ wantCodes: []code.Code{code.SDLRequireSchemaName},},{name: "Valid SDL - CREATE SEQUENCE with schema name",@@ -265,7 +266,7 @@ CREATE VIEW active_users AS SELECT * FROM public.users WHERE active = true;`,name: "Error - CREATE SEQUENCE without schema name",statement: `CREATE SEQUENCE user_id_seq START 1;`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireSchemaName},+ wantCodes: []code.Code{code.SDLRequireSchemaName},},{name: "Valid SDL - CREATE FUNCTION with schema name",@@ -281,7 +282,7 @@ CREATE VIEW active_users AS SELECT * FROM public.users WHERE active = true;`,SELECT COUNT(*) FROM public.users;$$ LANGUAGE SQL;`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireSchemaName},+ wantCodes: []code.Code{code.SDLRequireSchemaName},},{name: "Valid SDL - ALTER SEQUENCE with schema name",@@ -293,7 +294,7 @@ CREATE VIEW active_users AS SELECT * FROM public.users WHERE active = true;`,name: "Error - ALTER SEQUENCE without schema name",statement: `ALTER SEQUENCE user_id_seq OWNED BY public.users.id;`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireSchemaName},+ wantCodes: []code.Code{code.SDLRequireSchemaName},},{name: "Valid SDL - ALTER SEQUENCE with other options",@@ -325,11 +326,11 @@ CREATE VIEW active_users AS SELECT * FROM public.users WHERE active = true;`,CREATE VIEW active_users AS SELECT * FROM users;`,wantCount: 4, // schema name for table + column constraint + schema name for index + schema name for view- wantCodes: []advisor.Code{- advisor.SDLRequireSchemaName, // table- advisor.SDLDisallowColumnConstraint, // column constraint- advisor.SDLRequireSchemaName, // index- advisor.SDLRequireSchemaName, // view+ wantCodes: []code.Code{+ code.SDLRequireSchemaName, // table+ code.SDLDisallowColumnConstraint, // column constraint+ code.SDLRequireSchemaName, // index+ code.SDLRequireSchemaName, // view},},{@@ -371,7 +372,7 @@ CREATE VIEW active_users AS SELECT * FROM public.users WHERE active = true;`,CONSTRAINT fk_orders_user FOREIGN KEY (user_id) REFERENCES users(id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLRequireSchemaName},+ wantCodes: []code.Code{code.SDLRequireSchemaName},},{name: "Error - FK reference without schema name (column-level)",@@ -380,9 +381,9 @@ CREATE VIEW active_users AS SELECT * FROM public.users WHERE active = true;`,user_id INTEGER REFERENCES users(id));`,wantCount: 2, // Both: disallowed column constraint AND missing schema- wantCodes: []advisor.Code{- advisor.SDLRequireSchemaName,- advisor.SDLDisallowColumnConstraint,+ wantCodes: []code.Code{+ code.SDLRequireSchemaName,+ code.SDLDisallowColumnConstraint,},},{@@ -403,9 +404,9 @@ CREATE VIEW active_users AS SELECT * FROM public.users WHERE active = true;`,CONSTRAINT fk_orders_product FOREIGN KEY (product_id) REFERENCES products(id));`,wantCount: 2, // Two FK references without schema- wantCodes: []advisor.Code{- advisor.SDLRequireSchemaName,- advisor.SDLRequireSchemaName,+ wantCodes: []code.Code{+ code.SDLRequireSchemaName,+ code.SDLRequireSchemaName,},},{diff --git a/backend/plugin/advisor/pg/sdl_integrity_check.go b/backend/plugin/advisor/pg/sdl_integrity_check.goindex b4b95a6684..880dc61d28 100644--- a/backend/plugin/advisor/pg/sdl_integrity_check.go+++ b/backend/plugin/advisor/pg/sdl_integrity_check.go@@ -9,7 +9,7 @@ import (parser "github.com/bytebase/parser/postgresql"storepb "github.com/bytebase/bytebase/backend/generated-go/store"- "github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg")@@ -38,7 +38,7 @@ func CheckSDLIntegrity(files map[string]string) (map[string][]*storepb.Advice, ereturn map[string][]*storepb.Advice{filePath: {{Status: storepb.Advice_ERROR,- Code: advisor.StatementSyntaxError.Int32(),+ Code: code.StatementSyntaxError.Int32(),Title: "SQL syntax error",Content: fmt.Sprintf("Failed to parse SQL in file '%s': %v", filePath, err),}},@@ -208,7 +208,7 @@ func detectCrossFileDuplicates(fileCheckers []*fileSymbolTable) map[string][]*stif first, exists := seenTables[key]; exists {advice := &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLDuplicateTableName.Int32(),+ Code: code.SDLDuplicateTableName.Int32(),Title: "Duplicate table name across files",Content: fmt.Sprintf("Table '%s.%s' is defined in multiple SDL files.\n\n"+@@ -236,7 +236,7 @@ func detectCrossFileDuplicates(fileCheckers []*fileSymbolTable) map[string][]*stif first, exists := seenIndexes[key]; exists {advice := &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLDuplicateIndexName.Int32(),+ Code: code.SDLDuplicateIndexName.Int32(),Title: "Duplicate index name across files",Content: fmt.Sprintf("Index '%s.%s' is defined in multiple SDL files.\n\n"+@@ -264,7 +264,7 @@ func detectCrossFileDuplicates(fileCheckers []*fileSymbolTable) map[string][]*stif first, exists := seenViews[key]; exists {advice := &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLDuplicateTableName.Int32(),+ Code: code.SDLDuplicateTableName.Int32(),Title: "Duplicate view name across files",Content: fmt.Sprintf("View '%s.%s' is defined in multiple SDL files.\n\n"+@@ -297,7 +297,7 @@ func detectCrossFileDuplicates(fileCheckers []*fileSymbolTable) map[string][]*stif first, exists := seenConstraints[schema][name]; exists {advice := &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLDuplicateConstraintName.Int32(),+ Code: code.SDLDuplicateConstraintName.Int32(),Title: "Duplicate constraint name across files",Content: fmt.Sprintf("Constraint '%s' in schema '%s' is defined in multiple SDL files.\n\n"+@@ -357,7 +357,7 @@ func (c *sdlIntegrityChecker) validateForeignKeysWithMergedTable(merged *mergedSif refTable == nil {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLForeignKeyTableNotFound.Int32(),+ Code: code.SDLForeignKeyTableNotFound.Int32(),Title: "Foreign key references non-existent table",Content: fmt.Sprintf("Foreign key constraint '%s' on table '%s.%s' references table '%s.%s' which does not exist in any SDL file.\n\n"+@@ -390,7 +390,7 @@ func (c *sdlIntegrityChecker) validateForeignKeysWithMergedTable(merged *mergedSif targetCol == nil {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLForeignKeyColumnNotFound.Int32(),+ Code: code.SDLForeignKeyColumnNotFound.Int32(),Title: "Foreign key references non-existent column",Content: fmt.Sprintf("Foreign key constraint '%s' on table '%s.%s' references column '%s' in table '%s.%s', but this column does not exist.\n\n"+@@ -442,7 +442,7 @@ func (c *sdlIntegrityChecker) validateViewDependenciesWithMergedTable(merged *meobjectType := "table or view"c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLViewDependencyNotFound.Int32(),+ Code: code.SDLViewDependencyNotFound.Int32(),Title: "View references non-existent table or view",Content: fmt.Sprintf("View '%s.%s' (line %d) references %s '%s.%s' which does not exist in any SDL file.\n\n"+@@ -664,7 +664,7 @@ func (c *sdlIntegrityChecker) EnterCreatestmt(ctx *parser.CreatestmtContext) {if existing := c.symbolTable.getTable(schemaName, tableName); existing != nil {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLDuplicateTableName.Int32(),+ Code: code.SDLDuplicateTableName.Int32(),Title: "Duplicate table name",Content: fmt.Sprintf("Table '%s.%s' is defined multiple times in the SDL.\n\n"+@@ -698,7 +698,7 @@ func (c *sdlIntegrityChecker) EnterCreatestmt(ctx *parser.CreatestmtContext) {if _, exists := table.columns[colName]; exists {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLDuplicateColumnName.Int32(),+ Code: code.SDLDuplicateColumnName.Int32(),Title: "Duplicate column name",Content: fmt.Sprintf("Column '%s' is defined multiple times in table '%s.%s'.\n\n"+@@ -828,7 +828,7 @@ func (c *sdlIntegrityChecker) collectTableConstraint(ctx parser.ITableconstraintc.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLDuplicateConstraintName.Int32(),+ Code: code.SDLDuplicateConstraintName.Int32(),Title: "Duplicate constraint name",Content: fmt.Sprintf("Constraint '%s' is defined multiple times in %s '%s'.\n\n"+@@ -936,7 +936,7 @@ func (c *sdlIntegrityChecker) EnterIndexstmt(ctx *parser.IndexstmtContext) {if existing, exists := c.symbolTable.indexes[key]; exists {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLDuplicateIndexName.Int32(),+ Code: code.SDLDuplicateIndexName.Int32(),Title: "Duplicate index name",Content: fmt.Sprintf("Index '%s.%s' is defined multiple times in the SDL.\n\n"+@@ -997,7 +997,7 @@ func (c *sdlIntegrityChecker) checkMultiplePrimaryKeys() {c.adviceList = append(c.adviceList, &storepb.Advice{Status: storepb.Advice_ERROR,- Code: advisor.SDLMultiplePrimaryKey.Int32(),+ Code: code.SDLMultiplePrimaryKey.Int32(),Title: "Multiple primary keys defined",Content: fmt.Sprintf("Table '%s.%s' has multiple PRIMARY KEY constraints defined.\n\n"+diff --git a/backend/plugin/advisor/pg/sdl_integrity_check_multifile_test.go b/backend/plugin/advisor/pg/sdl_integrity_check_multifile_test.goindex 8c68bc00c3..3ba928c02d 100644--- a/backend/plugin/advisor/pg/sdl_integrity_check_multifile_test.go+++ b/backend/plugin/advisor/pg/sdl_integrity_check_multifile_test.go@@ -4,10 +4,11 @@ import ("strings""testing"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/stretchr/testify/require"storepb "github.com/bytebase/bytebase/backend/generated-go/store"- "github.com/bytebase/bytebase/backend/plugin/advisor")func TestCheckSDLIntegrity_ValidCrossFileReferences(t *testing.T) {@@ -111,7 +112,7 @@ func TestCheckSDLIntegrity_DuplicateTableAcrossFiles(t *testing.T) {}require.Equal(t, storepb.Advice_ERROR, advice.Status)- require.Equal(t, advisor.SDLDuplicateTableName.Int32(), advice.Code)+ require.Equal(t, code.SDLDuplicateTableName.Int32(), advice.Code)require.Contains(t, advice.Content, "Table 'public.users' is defined in multiple SDL files")}@@ -149,7 +150,7 @@ func TestCheckSDLIntegrity_DuplicateIndexAcrossFiles(t *testing.T) {}require.Equal(t, storepb.Advice_ERROR, advice.Status)- require.Equal(t, advisor.SDLDuplicateIndexName.Int32(), advice.Code)+ require.Equal(t, code.SDLDuplicateIndexName.Int32(), advice.Code)require.Contains(t, advice.Content, "Index 'public.idx_employee_email' is defined in multiple SDL files")}@@ -180,7 +181,7 @@ func TestCheckSDLIntegrity_DuplicateConstraintAcrossFiles(t *testing.T) {hasError := falsefor _, advices := range results {for _, advice := range advices {- if advice.Code == advisor.SDLDuplicateConstraintName.Int32() {+ if advice.Code == code.SDLDuplicateConstraintName.Int32() {require.Contains(t, advice.Content, "Constraint 'pk_common' in schema 'public' is defined in multiple SDL files")require.Contains(t, advice.Content, "PostgreSQL requires PRIMARY KEY and UNIQUE constraint names to be unique within a schema")hasError = true@@ -253,7 +254,7 @@ func TestCheckSDLIntegrity_ForeignKeyTableNotFound(t *testing.T) {var foundError boolfor _, advice := range results["orders.sql"] {- if advice.Code == advisor.SDLForeignKeyTableNotFound.Int32() {+ if advice.Code == code.SDLForeignKeyTableNotFound.Int32() {require.Contains(t, advice.Content, "references table 'public.users' which does not exist in any SDL file")foundError = true}@@ -283,7 +284,7 @@ func TestCheckSDLIntegrity_ViewReferencesNonExistentTable(t *testing.T) {// Should have view dependency error in views.sqlvar foundError boolfor _, advice := range results["views.sql"] {- if advice.Code == advisor.SDLViewDependencyNotFound.Int32() {+ if advice.Code == code.SDLViewDependencyNotFound.Int32() {require.Contains(t, advice.Content, "View 'public.order_summary'")require.Contains(t, advice.Content, "references table or view 'public.orders' which does not exist")foundError = true@@ -423,7 +424,7 @@ func TestCheckSDLIntegrity_ViewWithCTEAndMissingTable(t *testing.T) {var foundOrdersError boolvar foundCTEError boolfor _, advice := range results["views.sql"] {- if advice.Code == advisor.SDLViewDependencyNotFound.Int32() {+ if advice.Code == code.SDLViewDependencyNotFound.Int32() {if strings.Contains(advice.Content, "'public.orders'") {foundOrdersError = true}@@ -510,7 +511,7 @@ func TestCheckSDLIntegrity_ViewReferencesMixedTablesWithError(t *testing.T) {// Should have error for 'orders' table but not for pg_table_size or pg_size_prettyvar foundOrdersError boolfor _, advice := range results["views.sql"] {- if advice.Code == advisor.SDLViewDependencyNotFound.Int32() {+ if advice.Code == code.SDLViewDependencyNotFound.Int32() {require.Contains(t, advice.Content, "public.orders")require.NotContains(t, advice.Content, "pg_")foundOrdersError = true@@ -557,9 +558,9 @@ func TestCheckSDLIntegrity_MultipleErrorsInSameFile(t *testing.T) {}// Should have: duplicate table, FK table not found, view dependency not found- require.Greater(t, errorCodes[advisor.SDLDuplicateTableName.Int32()], 0, "Should have duplicate table")- require.Greater(t, errorCodes[advisor.SDLForeignKeyTableNotFound.Int32()], 0, "Should have FK table not found")- require.Greater(t, errorCodes[advisor.SDLViewDependencyNotFound.Int32()], 0, "Should have view dependency error")+ require.Greater(t, errorCodes[code.SDLDuplicateTableName.Int32()], 0, "Should have duplicate table")+ require.Greater(t, errorCodes[code.SDLForeignKeyTableNotFound.Int32()], 0, "Should have FK table not found")+ require.Greater(t, errorCodes[code.SDLViewDependencyNotFound.Int32()], 0, "Should have view dependency error")// Should have at least 3 total errorstotalErrors := 0@@ -609,7 +610,7 @@ func TestCheckSDLIntegrity_SyntaxErrorInOneFile(t *testing.T) {var foundSyntaxError boolfor _, advice := range results["invalid.sql"] {- if advice.Code == advisor.StatementSyntaxError.Int32() {+ if advice.Code == code.StatementSyntaxError.Int32() {foundSyntaxError = true}}@@ -708,7 +709,7 @@ func TestCheckSDLIntegrity_ForeignKeyColumnNotFound(t *testing.T) {// Should have FK column not found errorvar foundError boolfor _, advice := range results["orders.sql"] {- if advice.Code == advisor.SDLForeignKeyColumnNotFound.Int32() {+ if advice.Code == code.SDLForeignKeyColumnNotFound.Int32() {require.Contains(t, advice.Content, "references column 'user_uuid'")require.Contains(t, advice.Content, "does not exist")foundError = true@@ -737,7 +738,7 @@ func TestCheckSDLIntegrity_DuplicateViewAcrossFiles(t *testing.T) {var foundError boolfor _, advices := range results {for _, advice := range advices {- if advice.Code == advisor.SDLDuplicateTableName.Int32() && advice.Title == "Duplicate view name across files" {+ if advice.Code == code.SDLDuplicateTableName.Int32() && advice.Title == "Duplicate view name across files" {require.Contains(t, advice.Content, "View 'public.product_list' is defined in multiple SDL files")foundError = true}diff --git a/backend/plugin/advisor/pg/sdl_integrity_check_test.go b/backend/plugin/advisor/pg/sdl_integrity_check_test.goindex 5b3a9d291b..869b40b39f 100644--- a/backend/plugin/advisor/pg/sdl_integrity_check_test.go+++ b/backend/plugin/advisor/pg/sdl_integrity_check_test.go@@ -3,10 +3,11 @@ package pgimport ("testing"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/stretchr/testify/require"storepb "github.com/bytebase/bytebase/backend/generated-go/store"- "github.com/bytebase/bytebase/backend/plugin/advisor")func TestCheckSDLIntegrity(t *testing.T) {@@ -14,7 +15,7 @@ func TestCheckSDLIntegrity(t *testing.T) {name stringstatement stringwantCount int- wantCodes []advisor.Code+ wantCodes []code.Code}{// ============================================================// FOREIGN KEY VALIDATION TESTS@@ -46,7 +47,7 @@ CREATE TABLE public.orders (CONSTRAINT fk_orders_user FOREIGN KEY (user_id) REFERENCES public.users(id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLForeignKeyTableNotFound},+ wantCodes: []code.Code{code.SDLForeignKeyTableNotFound},},{name: "Error - FK references non-existent column",@@ -64,7 +65,7 @@ CREATE TABLE public.orders (CONSTRAINT fk_orders_user FOREIGN KEY (user_id) REFERENCES public.users(user_id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLForeignKeyColumnNotFound},+ wantCodes: []code.Code{code.SDLForeignKeyColumnNotFound},},{name: "Valid FK - Composite FK with matching types",@@ -133,7 +134,7 @@ CREATE TABLE public.users (CONSTRAINT pk_users2 PRIMARY KEY (user_id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDuplicateTableName},+ wantCodes: []code.Code{code.SDLDuplicateTableName},},{name: "Valid - Same table name in different schemas",@@ -161,7 +162,7 @@ CREATE TABLE public.users (CREATE INDEX idx_users_email ON public.users(email);CREATE INDEX idx_users_email ON public.users(id);`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDuplicateIndexName},+ wantCodes: []code.Code{code.SDLDuplicateIndexName},},{name: "Error - Duplicate constraint name in same schema",@@ -180,7 +181,7 @@ CREATE TABLE public.products (CONSTRAINT uk_products_code UNIQUE (code));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDuplicateConstraintName},+ wantCodes: []code.Code{code.SDLDuplicateConstraintName},},{name: "Error - Duplicate column name in same table",@@ -192,7 +193,7 @@ CREATE TABLE public.users (CONSTRAINT pk_users PRIMARY KEY (id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDuplicateColumnName},+ wantCodes: []code.Code{code.SDLDuplicateColumnName},},{name: "Valid - Same column name in different tables",@@ -224,7 +225,7 @@ CREATE TABLE public.users (CONSTRAINT pk_users_email PRIMARY KEY (email));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLMultiplePrimaryKey},+ wantCodes: []code.Code{code.SDLMultiplePrimaryKey},},{name: "Error - Three PRIMARY KEY constraints on same table",@@ -238,7 +239,7 @@ CREATE TABLE public.users (CONSTRAINT pk3 PRIMARY KEY (username));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLMultiplePrimaryKey},+ wantCodes: []code.Code{code.SDLMultiplePrimaryKey},},{name: "Valid - One PRIMARY KEY with multiple columns (composite PK)",@@ -274,7 +275,7 @@ CREATE VIEW public.active_users ASCREATE VIEW public.active_users ASSELECT id, email FROM public.users WHERE active = true;`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLViewDependencyNotFound},+ wantCodes: []code.Code{code.SDLViewDependencyNotFound},},{name: "Error - VIEW references multiple tables, one doesn't exist",@@ -290,7 +291,7 @@ CREATE VIEW public.user_orders ASFROM public.users uJOIN public.orders o ON u.id = o.user_id;`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLViewDependencyNotFound},+ wantCodes: []code.Code{code.SDLViewDependencyNotFound},},{name: "Valid VIEW - references all existing tables",@@ -329,8 +330,8 @@ CREATE TABLE public.orders (CONSTRAINT fk_orders_user FOREIGN KEY (user_id) REFERENCES public.users(id));`,wantCount: 1,- wantCodes: []advisor.Code{- advisor.SDLForeignKeyTableNotFound,+ wantCodes: []code.Code{+ code.SDLForeignKeyTableNotFound,},},{@@ -349,9 +350,9 @@ CREATE TABLE public.orders (CONSTRAINT pk_common PRIMARY KEY (id));`,wantCount: 2,- wantCodes: []advisor.Code{- advisor.SDLDuplicateConstraintName, // Detected first during Pass 1- advisor.SDLMultiplePrimaryKey, // Detected during Pass 2+ wantCodes: []code.Code{+ code.SDLDuplicateConstraintName, // Detected first during Pass 1+ code.SDLMultiplePrimaryKey, // Detected during Pass 2},},@@ -416,7 +417,7 @@ CREATE TABLE public.posts (CONSTRAINT fk_user FOREIGN KEY (editor_id) REFERENCES public.users(id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDuplicateConstraintName},+ wantCodes: []code.Code{code.SDLDuplicateConstraintName},},{name: "Error - Duplicate PRIMARY KEY name across tables (schema-level scoping)",@@ -431,7 +432,7 @@ CREATE TABLE public.orders (CONSTRAINT pk_common PRIMARY KEY (id));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDuplicateConstraintName},+ wantCodes: []code.Code{code.SDLDuplicateConstraintName},},{name: "Error - Duplicate UNIQUE name across tables (schema-level scoping)",@@ -446,7 +447,7 @@ CREATE TABLE public.customers (CONSTRAINT uk_email UNIQUE (email));`,wantCount: 1,- wantCodes: []advisor.Code{advisor.SDLDuplicateConstraintName},+ wantCodes: []code.Code{code.SDLDuplicateConstraintName},},// ============================================================@@ -547,7 +548,7 @@ func TestCheckSDLIntegrity_InvalidSQL(t *testing.T) {// Syntax errors are returned as advices, not as errorsrequire.NoError(t, err)require.Greater(t, len(advices), 0, "Should have syntax error advice")- require.Equal(t, advisor.StatementSyntaxError.Int32(), advices[0].Code)+ require.Equal(t, code.StatementSyntaxError.Int32(), advices[0].Code)})}}diff --git a/backend/plugin/advisor/redshift/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/redshift/advisor_table_drop_naming_convention.goindex faa93854ef..69c61e7d01 100644--- a/backend/plugin/advisor/redshift/advisor_table_drop_naming_convention.go+++ b/backend/plugin/advisor/redshift/advisor_table_drop_naming_convention.go@@ -5,6 +5,8 @@ import ("fmt""regexp"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/redshift""github.com/pkg/errors"@@ -79,7 +81,7 @@ func (l *tableDropNamingConventionListener) EnterDropstmt(ctx *parser.DropstmtCoif tableName != "" && !l.format.MatchString(tableName) {l.adviceList = append(l.adviceList, &storepb.Advice{Status: l.level,- Code: advisor.TableDropNamingConventionMismatch.Int32(),+ Code: code.TableDropNamingConventionMismatch.Int32(),Title: l.title,Content: fmt.Sprintf("`%s` mismatches drop table naming convention, naming format should be %q", tableName, l.format),StartPosition: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{diff --git a/backend/plugin/advisor/snowflake/rule_column_maximum_varchar_length.go b/backend/plugin/advisor/snowflake/rule_column_maximum_varchar_length.goindex 5127d06afb..78b674fef4 100644--- a/backend/plugin/advisor/snowflake/rule_column_maximum_varchar_length.go+++ b/backend/plugin/advisor/snowflake/rule_column_maximum_varchar_length.go@@ -5,6 +5,8 @@ import ("fmt""strconv"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/snowflake""github.com/pkg/errors"@@ -116,7 +118,7 @@ func (r *ColumnMaximumVarcharLengthRule) checkDataType(ctx *parser.Data_typeContif length > r.maximum {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.VarcharLengthExceedsLimit.Int32(),+ Code: code.VarcharLengthExceedsLimit.Int32(),Title: r.title,Content: fmt.Sprintf("The maximum varchar length is %d.", r.maximum),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/snowflake/rule_column_no_null.go b/backend/plugin/advisor/snowflake/rule_column_no_null.goindex fd5e4d1db3..a993058760 100644--- a/backend/plugin/advisor/snowflake/rule_column_no_null.go+++ b/backend/plugin/advisor/snowflake/rule_column_no_null.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake")@@ -121,7 +122,7 @@ func (r *ColumnNoNullRule) exitCreateTable() {for normalizedColumnName, columnNullableLine := range r.columnNullable {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.ColumnCannotNull.Int32(),+ Code: code.ColumnCannotNull.Int32(),Title: r.title,Content: fmt.Sprintf("Column %s is nullable, which is not allowed.", normalizedColumnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + columnNullableLine),@@ -173,7 +174,7 @@ func (r *ColumnNoNullRule) exitAlterTable() {for normalizedColumnName, columnNullableLine := range r.columnNullable {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.ColumnCannotNull.Int32(),+ Code: code.ColumnCannotNull.Int32(),Title: r.title,Content: fmt.Sprintf("Column %s is nullable, which is not allowed.", normalizedColumnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + columnNullableLine),@@ -215,7 +216,7 @@ func (r *ColumnNoNullRule) exitAlterTableAlterColumn() {for normalizedColumnName, columnNullableLine := range r.columnNullable {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.ColumnCannotNull.Int32(),+ Code: code.ColumnCannotNull.Int32(),Title: r.title,Content: fmt.Sprintf("After dropping NOT NULL of column %s, it will be nullable, which is not allowed.", normalizedColumnName),StartPosition: common.ConvertANTLRLineToPosition(r.baseLine + columnNullableLine),diff --git a/backend/plugin/advisor/snowflake/rule_column_require.go b/backend/plugin/advisor/snowflake/rule_column_require.goindex e2db9c3d77..3ec117df9d 100644--- a/backend/plugin/advisor/snowflake/rule_column_require.go+++ b/backend/plugin/advisor/snowflake/rule_column_require.go@@ -6,6 +6,8 @@ import ("fmt""slices"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/snowflake""github.com/pkg/errors"@@ -151,7 +153,7 @@ func (r *ColumnRequireRule) exitCreateTable(ctx *parser.Create_tableContext) {for _, column := range columnNames {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoRequiredColumn.Int32(),+ Code: code.NoRequiredColumn.Int32(),Title: r.title,Content: fmt.Sprintf("Table %s missing required column %q", r.currentOriginalTableName, column),StartPosition: common.ConvertANTLRLineToPosition(ctx.Column_decl_item_list().GetStop().GetLine()),@@ -193,7 +195,7 @@ func (r *ColumnRequireRule) exitAlterTable(ctx *parser.Alter_tableContext) {for _, column := range columnNames {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NoRequiredColumn.Int32(),+ Code: code.NoRequiredColumn.Int32(),Title: r.title,Content: fmt.Sprintf("Table %s missing required column %q", r.currentOriginalTableName, column),StartPosition: common.ConvertANTLRLineToPosition(ctx.Table_column_action().GetStart().GetLine()),diff --git a/backend/plugin/advisor/snowflake/rule_migration_compatibility.go b/backend/plugin/advisor/snowflake/rule_migration_compatibility.goindex 823dbb5abc..cca8f926ab 100644--- a/backend/plugin/advisor/snowflake/rule_migration_compatibility.go+++ b/backend/plugin/advisor/snowflake/rule_migration_compatibility.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake")@@ -144,7 +145,7 @@ func (r *MigrationCompatibilityRule) enterDropTable(ctx *parser.Drop_tableContex}r.AddAdvice(&storepb.Advice{Status: level,- Code: advisor.CompatibilityDropTable.Int32(),+ Code: code.CompatibilityDropTable.Int32(),Title: r.title,Content: fmt.Sprintf("Drop table %q may cause incompatibility with the existing data and code", normalizedFullDropTableName),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -163,7 +164,7 @@ func (r *MigrationCompatibilityRule) enterDropSchema(ctx *parser.Drop_schemaCont}r.AddAdvice(&storepb.Advice{Status: level,- Code: advisor.CompatibilityDropSchema.Int32(),+ Code: code.CompatibilityDropSchema.Int32(),Title: r.title,Content: fmt.Sprintf("Drop schema %q may cause incompatibility with the existing data and code", normalizedFullDropSchemaName),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -182,7 +183,7 @@ func (r *MigrationCompatibilityRule) enterDropDatabase(ctx *parser.Drop_database}r.AddAdvice(&storepb.Advice{Status: level,- Code: advisor.CompatibilityDropDatabase.Int32(),+ Code: code.CompatibilityDropDatabase.Int32(),Title: r.title,Content: fmt.Sprintf("Drop database %q may cause incompatibility with the existing data and code", normalizedFullDropDatabaseName),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -205,7 +206,7 @@ func (r *MigrationCompatibilityRule) enterAlterTable(ctx *parser.Alter_tableCont}r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.CompatibilityDropColumn.Int32(),+ Code: code.CompatibilityDropColumn.Int32(),Title: r.title,Content: fmt.Sprintf("Drop column %s may cause incompatibility with the existing data and code", strings.Join(normalizedAllColumnNames, ",")),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/snowflake/rule_naming_identifier_case.go b/backend/plugin/advisor/snowflake/rule_naming_identifier_case.goindex 847de49275..71e88188e4 100644--- a/backend/plugin/advisor/snowflake/rule_naming_identifier_case.go+++ b/backend/plugin/advisor/snowflake/rule_naming_identifier_case.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake")@@ -115,7 +116,7 @@ func (r *NamingIdentifierCaseRule) enterColumnDeclItemList(ctx *parser.Column_deif strings.ToUpper(originalColName) != originalColName {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingCaseMismatch.Int32(),+ Code: code.NamingCaseMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("Identifier %q should be upper case", originalColName),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -135,7 +136,7 @@ func (r *NamingIdentifierCaseRule) enterAlterTable(ctx *parser.Alter_tableContexif strings.ToUpper(renameToColName) != renameToColName {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingCaseMismatch.Int32(),+ Code: code.NamingCaseMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("Identifier %q should be upper case", renameToColName),StartPosition: common.ConvertANTLRLineToPosition(renameToID.GetStart().GetLine()),diff --git a/backend/plugin/advisor/snowflake/rule_naming_identifier_no_keyword.go b/backend/plugin/advisor/snowflake/rule_naming_identifier_no_keyword.goindex 20d4e5d142..05cd35bf7c 100644--- a/backend/plugin/advisor/snowflake/rule_naming_identifier_no_keyword.go+++ b/backend/plugin/advisor/snowflake/rule_naming_identifier_no_keyword.go@@ -5,6 +5,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/snowflake""github.com/pkg/errors"@@ -114,7 +116,7 @@ func (r *NamingIdentifierNoKeywordRule) enterColumnDeclItemList(ctx *parser.Coluif snowsqlparser.IsSnowflakeKeyword(originalColName, false) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NameIsKeywordIdentifier.Int32(),+ Code: code.NameIsKeywordIdentifier.Int32(),Title: r.title,Content: fmt.Sprintf("Identifier %s is a keyword and should be avoided", originalID.GetText()),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -134,7 +136,7 @@ func (r *NamingIdentifierNoKeywordRule) enterAlterTable(ctx *parser.Alter_tableCif snowsqlparser.IsSnowflakeKeyword(renameToColName, false) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NameIsKeywordIdentifier.Int32(),+ Code: code.NameIsKeywordIdentifier.Int32(),Title: r.title,Content: fmt.Sprintf("Identifier %s is a keyword and should be avoided", renameToID.GetText()),StartPosition: common.ConvertANTLRLineToPosition(renameToID.GetStart().GetLine()),diff --git a/backend/plugin/advisor/snowflake/rule_naming_table.go b/backend/plugin/advisor/snowflake/rule_naming_table.goindex d920d9306d..c1a9f81628 100644--- a/backend/plugin/advisor/snowflake/rule_naming_table.go+++ b/backend/plugin/advisor/snowflake/rule_naming_table.go@@ -15,6 +15,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -103,7 +104,7 @@ func (r *NamingTableRule) enterCreateTable(ctx *parser.Create_tableContext) {if !r.format.MatchString(tableName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`"%s" mismatches table naming convention, naming format should be %q`, tableName, r.format),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -112,7 +113,7 @@ func (r *NamingTableRule) enterCreateTable(ctx *parser.Create_tableContext) {if r.maxLength > 0 && len(tableName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" mismatches table naming convention, its length should be within %d characters", tableName, r.maxLength),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -137,7 +138,7 @@ func (r *NamingTableRule) enterAlterTable(ctx *parser.Alter_tableContext) {if !r.format.MatchString(tableName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf(`"%s" mismatches table naming convention, naming format should be %q`, tableName, r.format),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -146,7 +147,7 @@ func (r *NamingTableRule) enterAlterTable(ctx *parser.Alter_tableContext) {if r.maxLength > 0 && len(tableName) > r.maxLength {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("\"%s\" mismatches table naming convention, its length should be within %d characters", tableName, r.maxLength),StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/snowflake/rule_naming_table_no_keyword.go b/backend/plugin/advisor/snowflake/rule_naming_table_no_keyword.goindex 463de2f6e3..b15517b9be 100644--- a/backend/plugin/advisor/snowflake/rule_naming_table_no_keyword.go+++ b/backend/plugin/advisor/snowflake/rule_naming_table_no_keyword.go@@ -5,6 +5,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/snowflake""github.com/pkg/errors"@@ -90,7 +92,7 @@ func (r *NamingTableNoKeywordRule) enterCreateTable(ctx *parser.Create_tableContif snowsqlparser.IsSnowflakeKeyword(tableName, false) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NameIsKeywordIdentifier.Int32(),+ Code: code.NameIsKeywordIdentifier.Int32(),Title: r.title,Content: fmt.Sprintf("Table name %q is a keyword identifier and should be avoided.", tableName),})@@ -106,7 +108,7 @@ func (r *NamingTableNoKeywordRule) enterAlterTable(ctx *parser.Alter_tableContexif snowsqlparser.IsSnowflakeKeyword(tableName, false) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.NameIsKeywordIdentifier.Int32(),+ Code: code.NameIsKeywordIdentifier.Int32(),Title: r.title,Content: fmt.Sprintf("Table name %q is a keyword identifier and should be avoided.", tableName),})diff --git a/backend/plugin/advisor/snowflake/rule_select_no_select_all.go b/backend/plugin/advisor/snowflake/rule_select_no_select_all.goindex 3dc83ed230..91dfbf967a 100644--- a/backend/plugin/advisor/snowflake/rule_select_no_select_all.go+++ b/backend/plugin/advisor/snowflake/rule_select_no_select_all.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -84,7 +85,7 @@ func (r *SelectNoSelectAllRule) enterSelectListElem(ctx *parser.Select_list_elemif v.STAR() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementSelectAll.Int32(),+ Code: code.StatementSelectAll.Int32(),Title: r.title,Content: "Avoid using SELECT *.",StartPosition: common.ConvertANTLRLineToPosition(v.STAR().GetSymbol().GetLine()),diff --git a/backend/plugin/advisor/snowflake/rule_table_drop_naming_convention.go b/backend/plugin/advisor/snowflake/rule_table_drop_naming_convention.goindex 118c07fef5..fa42d420dc 100644--- a/backend/plugin/advisor/snowflake/rule_table_drop_naming_convention.go+++ b/backend/plugin/advisor/snowflake/rule_table_drop_naming_convention.go@@ -6,6 +6,8 @@ import ("fmt""regexp"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/snowflake""github.com/pkg/errors"@@ -94,7 +96,7 @@ func (r *TableDropNamingConventionRule) enterDropTable(ctx *parser.Drop_tableConif !r.format.MatchString(normalizedObjectName) {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableDropNamingConventionMismatch.Int32(),+ Code: code.TableDropNamingConventionMismatch.Int32(),Title: r.title,Content: fmt.Sprintf("%q mismatches drop table naming convention, naming format should be %q", normalizedObjectName, r.format),StartPosition: common.ConvertANTLRLineToPosition(ctx.Object_name().GetO().GetStart().GetLine()),diff --git a/backend/plugin/advisor/snowflake/rule_table_no_foreign_key.go b/backend/plugin/advisor/snowflake/rule_table_no_foreign_key.goindex f5c9acc867..7a922941c8 100644--- a/backend/plugin/advisor/snowflake/rule_table_no_foreign_key.go+++ b/backend/plugin/advisor/snowflake/rule_table_no_foreign_key.go@@ -5,6 +5,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/parser/snowflake""github.com/pkg/errors"@@ -124,7 +126,7 @@ func (r *TableNoForeignKeyRule) GetAdviceList() []*storepb.Advice {if times > 0 {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableHasFK.Int32(),+ Code: code.TableHasFK.Int32(),Title: r.title,Content: fmt.Sprintf("FOREIGN KEY is not allowed in the table %s.", r.tableOriginalName[tableName]),StartPosition: common.ConvertANTLRLineToPosition(r.tableLine[tableName]),diff --git a/backend/plugin/advisor/snowflake/rule_table_require_pk.go b/backend/plugin/advisor/snowflake/rule_table_require_pk.goindex 92f9b79488..66e1bd636d 100644--- a/backend/plugin/advisor/snowflake/rule_table_require_pk.go+++ b/backend/plugin/advisor/snowflake/rule_table_require_pk.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake")@@ -126,7 +127,7 @@ func (r *TableRequirePkRule) GetAdviceList() []*storepb.Advice {if !has {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.TableNoPK.Int32(),+ Code: code.TableNoPK.Int32(),Title: r.title,Content: fmt.Sprintf("Table %s requires PRIMARY KEY.", r.tableOriginalName[tableName]),StartPosition: common.ConvertANTLRLineToPosition(r.tableLine[tableName]),diff --git a/backend/plugin/advisor/snowflake/rule_where_require_select.go b/backend/plugin/advisor/snowflake/rule_where_require_select.goindex 5480a5b48c..cb2251e0fd 100644--- a/backend/plugin/advisor/snowflake/rule_where_require_select.go+++ b/backend/plugin/advisor/snowflake/rule_where_require_select.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -91,7 +92,7 @@ func (r *WhereRequireForSelectRule) enterQueryStatement(ctx *parser.Query_statemif optional.Where_clause() == nil && optional.From_clause() != nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: "WHERE clause is required for SELECT statement.",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/snowflake/rule_where_require_update_delete.go b/backend/plugin/advisor/snowflake/rule_where_require_update_delete.goindex 28f793f27f..2ffada5bf9 100644--- a/backend/plugin/advisor/snowflake/rule_where_require_update_delete.go+++ b/backend/plugin/advisor/snowflake/rule_where_require_update_delete.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -88,7 +89,7 @@ func (r *WhereRequireForUpdateDeleteRule) enterUpdateStatement(ctx *parser.Updatif ctx.WHERE() == nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: "WHERE clause is required for UPDATE statement.",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),@@ -100,7 +101,7 @@ func (r *WhereRequireForUpdateDeleteRule) enterDeleteStatement(ctx *parser.Deletif ctx.WHERE() == nil {r.AddAdvice(&storepb.Advice{Status: r.level,- Code: advisor.StatementNoWhere.Int32(),+ Code: code.StatementNoWhere.Int32(),Title: r.title,Content: "WHERE clause is required for DELETE statement.",StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.goindex 962e2bfdd8..cff44d76bd 100644--- a/backend/plugin/advisor/sql_review.go+++ b/backend/plugin/advisor/sql_review.go@@ -4,7 +4,6 @@ import ("context""database/sql""encoding/json"- "fmt""regexp""github.com/pkg/errors"@@ -13,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/component/sheet"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/bytebase/bytebase/backend/plugin/parser/base")@@ -607,186 +607,20 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {return nil, err}- var res []*storepb.Advice- switch walkThroughError.Type {- case catalog.ErrorTypeUnsupported:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: Unsupported.Int32(),+ // Determine the advice status based on the error code+ // Most errors are ERROR level, except for a few special cases+ status := storepb.Advice_ERROR+ if walkThroughError.Code == code.ReferenceOtherDatabase {+ status = storepb.Advice_WARNING+ }++ return []*storepb.Advice{+ {+ Status: status,+ Code: walkThroughError.Code.Int32(),Title: walkThroughError.Content,- Content: "",- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeParseError:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: StatementSyntaxError.Int32(),- Title: SyntaxErrorTitle,- Content: walkThroughError.Content,- })- case catalog.ErrorTypeDeparseError:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: Internal.Int32(),- Title: "Internal error for walk-through",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeAccessOtherDatabase:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: NotCurrentDatabase.Int32(),- Title: "Access other database",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeDatabaseIsDeleted:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: DatabaseIsDeleted.Int32(),- Title: "Access deleted database",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeReferenceOtherDatabase:- res = append(res, &storepb.Advice{- Status: storepb.Advice_WARNING,- Code: ReferenceOtherDatabase.Int32(),- Title: "Reference other database",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeTableExists:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: TableExists.Int32(),- Title: "Table already exists",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeTableNotExists:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: TableNotExists.Int32(),- Title: "Table does not exist",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeColumnExists:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: ColumnExists.Int32(),- Title: "Column already exists",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeColumnNotExists:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: ColumnNotExists.Int32(),- Title: "Column does not exist",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeDropAllColumns:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: DropAllColumns.Int32(),- Title: "Drop all columns",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypePrimaryKeyExists:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: PrimaryKeyExists.Int32(),- Title: "Primary key exists",Content: walkThroughError.Content,StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeIndexExists:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: IndexExists.Int32(),- Title: "Index exists",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeIndexEmptyKeys:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: IndexEmptyKeys.Int32(),- Title: "Index empty keys",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypePrimaryKeyNotExists:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: PrimaryKeyNotExists.Int32(),- Title: "Primary key does not exist",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeIndexNotExists:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: IndexNotExists.Int32(),- Title: "Index does not exist",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeIncorrectIndexName:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: IncorrectIndexName.Int32(),- Title: "Incorrect index name",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeSpatialIndexKeyNullable:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: SpatialIndexKeyNullable.Int32(),- Title: "Spatial index key must be NOT NULL",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeColumnIsReferencedByView:- details := walkThroughError.Content- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: ColumnIsReferencedByView.Int32(),- Title: "Column is referenced by view",- Content: details,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeTableIsReferencedByView:- details := walkThroughError.Content- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: TableIsReferencedByView.Int32(),- Title: "Table is referenced by view",- Content: details,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- case catalog.ErrorTypeInvalidColumnTypeForDefaultValue:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: InvalidColumnDefault.Int32(),- Title: "Invalid column default value",- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- default:- res = append(res, &storepb.Advice{- Status: storepb.Advice_ERROR,- Code: Internal.Int32(),- Title: fmt.Sprintf("Failed to walk-through with code %d", walkThroughError.Type),- Content: walkThroughError.Content,- StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),- })- }-- return res, nil+ },+ }, nil}diff --git a/backend/plugin/advisor/tidb/advisor_builtin_prior_backup_check.go b/backend/plugin/advisor/tidb/advisor_builtin_prior_backup_check.goindex 15d056a952..f1690ba121 100644--- a/backend/plugin/advisor/tidb/advisor_builtin_prior_backup_check.go+++ b/backend/plugin/advisor/tidb/advisor_builtin_prior_backup_check.go@@ -14,6 +14,7 @@ import ("github.com/bytebase/bytebase/backend/common/log"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")const (@@ -72,7 +73,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: "Prior backup cannot deal with mixed DDL and DML statements",- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: common.ConvertANTLRLineToPosition(stmtNode.OriginTextPosition()),})}@@ -84,7 +85,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: fmt.Sprintf("Need database %q to do prior backup but it does not exist", databaseName),- Code: advisor.DatabaseNotExists.Int32(),+ Code: code.DatabaseNotExists.Int32(),StartPosition: nil,})}@@ -94,7 +95,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx advStatus: level,Title: title,Content: fmt.Sprintf("Prior backup is feasible only with up to %d statements that are either UPDATE or DELETE, or if all UPDATEs target the same table with a PRIMARY or UNIQUE KEY in the WHERE clause", maxMixedDMLCount),- Code: advisor.BuiltinPriorBackupCheck.Int32(),+ Code: code.BuiltinPriorBackupCheck.Int32(),StartPosition: nil,})}diff --git a/backend/plugin/advisor/tidb/advisor_charset_allowlist.go b/backend/plugin/advisor/tidb/advisor_charset_allowlist.goindex a7ed39e5c2..15ca8825fa 100644--- a/backend/plugin/advisor/tidb/advisor_charset_allowlist.go+++ b/backend/plugin/advisor/tidb/advisor_charset_allowlist.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -71,27 +72,27 @@ type charsetAllowlistChecker struct {// Enter implements the ast.Visitor interface.func (checker *charsetAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {- code := advisor.Ok+ code := advisorcode.Okvar disabledCharset stringline := checker.lineswitch node := in.(type) {case *ast.CreateDatabaseStmt:charset := getDatabaseCharset(node.Options)if _, exist := checker.allowlist[charset]; charset != "" && !exist {- code = advisor.DisabledCharset+ code = advisorcode.DisabledCharsetdisabledCharset = charset}case *ast.CreateTableStmt:charset := getTableCharset(node.Options)if _, exist := checker.allowlist[charset]; charset != "" && !exist {- code = advisor.DisabledCharset+ code = advisorcode.DisabledCharsetdisabledCharset = charsetbreak}for _, column := range node.Cols {charset := getColumnCharset(column)if _, exist := checker.allowlist[charset]; charset != "" && !exist {- code = advisor.DisabledCharset+ code = advisorcode.DisabledCharsetdisabledCharset = charsetline = column.OriginTextPosition()break@@ -100,7 +101,7 @@ func (checker *charsetAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {case *ast.AlterDatabaseStmt:charset := getDatabaseCharset(node.Options)if _, exist := checker.allowlist[charset]; charset != "" && !exist {- code = advisor.DisabledCharset+ code = advisorcode.DisabledCharsetdisabledCharset = charset}case *ast.AlterTableStmt:@@ -109,14 +110,14 @@ func (checker *charsetAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {case ast.AlterTableOption:charset := getTableCharset(spec.Options)if _, exist := checker.allowlist[charset]; charset != "" && !exist {- code = advisor.DisabledCharset+ code = advisorcode.DisabledCharsetdisabledCharset = charset}case ast.AlterTableAddColumns:for _, column := range spec.NewColumns {charset := getColumnCharset(column)if _, exist := checker.allowlist[charset]; charset != "" && !exist {- code = advisor.DisabledCharset+ code = advisorcode.DisabledCharsetdisabledCharset = charsetbreak}@@ -124,7 +125,7 @@ func (checker *charsetAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {case ast.AlterTableChangeColumn, ast.AlterTableModifyColumn:charset := getColumnCharset(spec.NewColumns[0])if _, exist := checker.allowlist[charset]; charset != "" && !exist {- code = advisor.DisabledCharset+ code = advisorcode.DisabledCharsetdisabledCharset = charset}default:@@ -132,7 +133,7 @@ func (checker *charsetAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {}}- if code != advisor.Ok {+ if code != advisorcode.Ok {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/tidb/advisor_collation_allowlist.go b/backend/plugin/advisor/tidb/advisor_collation_allowlist.goindex ab6640d9e0..7c0bd3e357 100644--- a/backend/plugin/advisor/tidb/advisor_collation_allowlist.go+++ b/backend/plugin/advisor/tidb/advisor_collation_allowlist.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -72,27 +73,27 @@ type collationAllowlistChecker struct {// Enter implements the ast.Visitor interface.func (checker *collationAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {- code := advisor.Ok+ code := advisorcode.Okvar disabledCollation stringline := checker.lineswitch node := in.(type) {case *ast.CreateDatabaseStmt:collation := getDatabaseCollation(node.Options)if _, exists := checker.allowlist[collation]; collation != "" && !exists {- code = advisor.DisabledCollation+ code = advisorcode.DisabledCollationdisabledCollation = collation}case *ast.CreateTableStmt:collation := getTableCollation(node.Options)if _, exist := checker.allowlist[collation]; collation != "" && !exist {- code = advisor.DisabledCollation+ code = advisorcode.DisabledCollationdisabledCollation = collationbreak}for _, column := range node.Cols {collation := getColumnCollation(column)if _, exist := checker.allowlist[collation]; collation != "" && !exist {- code = advisor.DisabledCollation+ code = advisorcode.DisabledCollationdisabledCollation = collationline = column.OriginTextPosition()break@@ -101,7 +102,7 @@ func (checker *collationAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {case *ast.AlterDatabaseStmt:collation := getDatabaseCollation(node.Options)if _, exist := checker.allowlist[collation]; collation != "" && !exist {- code = advisor.DisabledCollation+ code = advisorcode.DisabledCollationdisabledCollation = collation}case *ast.AlterTableStmt:@@ -110,14 +111,14 @@ func (checker *collationAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {case ast.AlterTableOption:collation := getTableCollation(spec.Options)if _, exist := checker.allowlist[collation]; collation != "" && !exist {- code = advisor.DisabledCollation+ code = advisorcode.DisabledCollationdisabledCollation = collation}case ast.AlterTableAddColumns:for _, column := range spec.NewColumns {collation := getColumnCollation(column)if _, exist := checker.allowlist[collation]; collation != "" && !exist {- code = advisor.DisabledCollation+ code = advisorcode.DisabledCollationdisabledCollation = collationbreak}@@ -125,7 +126,7 @@ func (checker *collationAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {case ast.AlterTableChangeColumn, ast.AlterTableModifyColumn:collation := getColumnCollation(spec.NewColumns[0])if _, exist := checker.allowlist[collation]; collation != "" && !exist {- code = advisor.DisabledCollation+ code = advisorcode.DisabledCollationdisabledCollation = collation}default:@@ -134,7 +135,7 @@ func (checker *collationAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {}}- if code != advisor.Ok {+ if code != advisorcode.Ok {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/tidb/advisor_column_auto_increment_initial_value.go b/backend/plugin/advisor/tidb/advisor_column_auto_increment_initial_value.goindex dc2623b30d..a328981420 100644--- a/backend/plugin/advisor/tidb/advisor_column_auto_increment_initial_value.go+++ b/backend/plugin/advisor/tidb/advisor_column_auto_increment_initial_value.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -74,7 +76,7 @@ func (checker *columnAutoIncrementInitialValueChecker) Enter(in ast.Node) (ast.Nif option.UintValue != uint64(checker.value) {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.AutoIncrementColumnInitialValueNotMatch.Int32(),+ Code: code.AutoIncrementColumnInitialValueNotMatch.Int32(),Title: checker.title,Content: fmt.Sprintf("The initial auto-increment value in table `%s` is %v, which doesn't equal %v", createTable.Table.Name.O, option.UintValue, checker.value),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_auto_increment_must_integer.go b/backend/plugin/advisor/tidb/advisor_column_auto_increment_must_integer.goindex 82b0343227..995785cfdf 100644--- a/backend/plugin/advisor/tidb/advisor_column_auto_increment_must_integer.go+++ b/backend/plugin/advisor/tidb/advisor_column_auto_increment_must_integer.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pingcap/tidb/pkg/parser/mysql""github.com/pingcap/tidb/pkg/parser/types"@@ -112,7 +114,7 @@ func (checker *columnAutoIncrementMustIntegerChecker) Enter(in ast.Node) (ast.Nofor _, column := range columnList {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.AutoIncrementColumnNotInteger.Int32(),+ Code: code.AutoIncrementColumnNotInteger.Int32(),Title: checker.title,Content: fmt.Sprintf("Auto-increment column `%s`.`%s` requires integer type", column.table, column.column),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_auto_increment_must_unsigned.go b/backend/plugin/advisor/tidb/advisor_column_auto_increment_must_unsigned.goindex 31c3f9ab7f..b986cecdfe 100644--- a/backend/plugin/advisor/tidb/advisor_column_auto_increment_must_unsigned.go+++ b/backend/plugin/advisor/tidb/advisor_column_auto_increment_must_unsigned.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pingcap/tidb/pkg/parser/mysql""github.com/pkg/errors"@@ -104,7 +106,7 @@ func (checker *columnAutoIncrementMustUnsignedChecker) Enter(in ast.Node) (ast.Nfor _, column := range columnList {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.AutoIncrementColumnSigned.Int32(),+ Code: code.AutoIncrementColumnSigned.Int32(),Title: checker.title,Content: fmt.Sprintf("Auto-increment column `%s`.`%s` is not UNSIGNED type", column.table, column.column),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_comment_convention.go b/backend/plugin/advisor/tidb/advisor_column_comment_convention.goindex d09fe9bafc..8b99617d2d 100644--- a/backend/plugin/advisor/tidb/advisor_column_comment_convention.go+++ b/backend/plugin/advisor/tidb/advisor_column_comment_convention.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -125,7 +126,7 @@ func (checker *columnCommentConventionChecker) Enter(in ast.Node) (ast.Node, booif checker.payload.Required && !column.exist {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.CommentEmpty.Int32(),+ Code: code.CommentEmpty.Int32(),Title: checker.title,Content: fmt.Sprintf("Column `%s`.`%s` requires comments", column.table, column.column),StartPosition: common.ConvertANTLRLineToPosition(column.line),@@ -134,7 +135,7 @@ func (checker *columnCommentConventionChecker) Enter(in ast.Node) (ast.Node, booif checker.payload.MaxLength >= 0 && len(column.comment) > checker.payload.MaxLength {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.CommentTooLong.Int32(),+ Code: code.CommentTooLong.Int32(),Title: checker.title,Content: fmt.Sprintf("The length of column `%s`.`%s` comment should be within %d characters", column.table, column.column, checker.payload.MaxLength),StartPosition: common.ConvertANTLRLineToPosition(column.line),@@ -144,7 +145,7 @@ func (checker *columnCommentConventionChecker) Enter(in ast.Node) (ast.Node, booif classification, _ := common.GetClassificationAndUserComment(column.comment, checker.classificationConfig); classification == "" {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.CommentMissingClassification.Int32(),+ Code: code.CommentMissingClassification.Int32(),Title: checker.title,Content: fmt.Sprintf("Column `%s`.`%s` comment requires classification", column.table, column.column),StartPosition: common.ConvertANTLRLineToPosition(column.line),@@ -169,7 +170,7 @@ func (checker *columnCommentConventionChecker) columnComment(column *ast.ColumnDcomment = ""checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for parsing column comment",Content: fmt.Sprintf("\"%q\" meet internal error %s", checker.text, err),})diff --git a/backend/plugin/advisor/tidb/advisor_column_current_time_count_limit.go b/backend/plugin/advisor/tidb/advisor_column_current_time_count_limit.goindex af40b53b14..488649cdc0 100644--- a/backend/plugin/advisor/tidb/advisor_column_current_time_count_limit.go+++ b/backend/plugin/advisor/tidb/advisor_column_current_time_count_limit.go@@ -8,6 +8,8 @@ import ("slices""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pingcap/tidb/pkg/parser/mysql""github.com/pkg/errors"@@ -95,7 +97,7 @@ func (checker *columnCurrentTimeCountLimitChecker) generateAdvice() []*storepb.Aif table.defaultCurrentTimeCount > maxDefaultCurrentTimeColumCount {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.DefaultCurrentTimeColumnCountExceedsLimit.Int32(),+ Code: code.DefaultCurrentTimeColumnCountExceedsLimit.Int32(),Title: checker.title,Content: fmt.Sprintf("Table `%s` has %d DEFAULT CURRENT_TIMESTAMP() columns. The count greater than %d.", table.tableName, table.defaultCurrentTimeCount, maxDefaultCurrentTimeColumCount),StartPosition: common.ConvertANTLRLineToPosition(table.line),@@ -104,7 +106,7 @@ func (checker *columnCurrentTimeCountLimitChecker) generateAdvice() []*storepb.Aif table.onUpdateCurrentTimeCount > maxOnUpdateCurrentTimeColumnCount {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.OnUpdateCurrentTimeColumnCountExceedsLimit.Int32(),+ Code: code.OnUpdateCurrentTimeColumnCountExceedsLimit.Int32(),Title: checker.title,Content: fmt.Sprintf("Table `%s` has %d ON UPDATE CURRENT_TIMESTAMP() columns. The count greater than %d.", table.tableName, table.onUpdateCurrentTimeCount, maxOnUpdateCurrentTimeColumnCount),StartPosition: common.ConvertANTLRLineToPosition(table.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_disallow_changing.go b/backend/plugin/advisor/tidb/advisor_column_disallow_changing.goindex 96ca35f425..6a1f519f82 100644--- a/backend/plugin/advisor/tidb/advisor_column_disallow_changing.go+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_changing.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -67,7 +69,7 @@ func (checker *columnDisallowChangingChecker) Enter(in ast.Node) (ast.Node, boolif spec.Tp == ast.AlterTableChangeColumn {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.UseChangeColumnStatement.Int32(),+ Code: code.UseChangeColumnStatement.Int32(),Title: checker.title,Content: fmt.Sprintf("\"%s\" contains CHANGE COLUMN statement", checker.text),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_disallow_changing_order.go b/backend/plugin/advisor/tidb/advisor_column_disallow_changing_order.goindex fa601d3326..52fdae909c 100644--- a/backend/plugin/advisor/tidb/advisor_column_disallow_changing_order.go+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_changing_order.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -68,7 +70,7 @@ func (checker *columnDisallowChangingOrderChecker) Enter(in ast.Node) (ast.Node,spec.Position.Tp != ast.ColumnPositionNone {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.ChangeColumnOrder.Int32(),+ Code: code.ChangeColumnOrder.Int32(),Title: checker.title,Content: fmt.Sprintf("\"%s\" changes column order", checker.text),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go b/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.goindex a060cca3d6..04a80cebde 100644--- a/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go@@ -7,6 +7,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -86,7 +88,7 @@ func (checker *columnDisallowChangingTypeChecker) Enter(in ast.Node) (ast.Node,if changeType {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.ChangeColumnType.Int32(),+ Code: code.ChangeColumnType.Int32(),Title: checker.title,Content: fmt.Sprintf("\"%s\" changes column type", checker.text),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_disallow_drop_in_index.go b/backend/plugin/advisor/tidb/advisor_column_disallow_drop_in_index.goindex 2bd39310e5..6b5290641c 100644--- a/backend/plugin/advisor/tidb/advisor_column_disallow_drop_in_index.go+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_drop_in_index.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -103,7 +105,7 @@ func (checker *columnDisallowDropInIndexChecker) dropColumn(in ast.Node) (ast.Noif !checker.canDrop(table, colName) {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.DropIndexColumn.Int32(),+ Code: code.DropIndexColumn.Int32(),Title: checker.title,Content: fmt.Sprintf("`%s`.`%s` cannot drop index column", table, colName),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_disallow_set_charset.go b/backend/plugin/advisor/tidb/advisor_column_disallow_set_charset.goindex 1dc71b5ab1..c93563f537 100644--- a/backend/plugin/advisor/tidb/advisor_column_disallow_set_charset.go+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_set_charset.go@@ -6,6 +6,8 @@ import ("context""fmt"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -62,13 +64,13 @@ type columnDisallowSetCharsetChecker struct {// Enter implements the ast.Visitor interface.func (checker *columnDisallowSetCharsetChecker) Enter(in ast.Node) (ast.Node, bool) {- code := advisor.Ok+ code := advisorcode.Okswitch node := in.(type) {case *ast.CreateTableStmt:for _, column := range node.Cols {charset := getColumnCharset(column)if !checkCharset(charset) {- code = advisor.SetColumnCharset+ code = advisorcode.SetColumnCharsetbreak}}@@ -79,27 +81,27 @@ func (checker *columnDisallowSetCharsetChecker) Enter(in ast.Node) (ast.Node, bofor _, column := range spec.NewColumns {charset := getColumnCharset(column)if !checkCharset(charset) {- code = advisor.SetColumnCharset+ code = advisorcode.SetColumnCharset}}case ast.AlterTableChangeColumn, ast.AlterTableModifyColumn:charset := getColumnCharset(spec.NewColumns[0])if !checkCharset(charset) {- code = advisor.SetColumnCharset+ code = advisorcode.SetColumnCharset}default:// Other alter table types}- if code != advisor.Ok {+ if code != advisorcode.Ok {break}}}- if code != advisor.Ok {+ if code != advisorcode.Ok {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.SetColumnCharset.Int32(),+ Code: advisorcode.SetColumnCharset.Int32(),Title: checker.title,Content: fmt.Sprintf("Disallow set column charset but \"%s\" does", checker.text),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_maximum_character_length.go b/backend/plugin/advisor/tidb/advisor_column_maximum_character_length.goindex f7727a1baf..f44e3e9a40 100644--- a/backend/plugin/advisor/tidb/advisor_column_maximum_character_length.go+++ b/backend/plugin/advisor/tidb/advisor_column_maximum_character_length.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pingcap/tidb/pkg/parser/mysql""github.com/pkg/errors"@@ -112,7 +114,7 @@ func (checker *columnMaximumCharacterLengthChecker) Enter(in ast.Node) (ast.Nodeif tableName != "" {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.CharLengthExceedsLimit.Int32(),+ Code: code.CharLengthExceedsLimit.Int32(),Title: checker.title,Content: fmt.Sprintf("The length of the CHAR column `%s` is bigger than %d, please use VARCHAR instead", columnName, checker.maximum),StartPosition: common.ConvertANTLRLineToPosition(line),diff --git a/backend/plugin/advisor/tidb/advisor_column_no_null.go b/backend/plugin/advisor/tidb/advisor_column_no_null.goindex 98c547d604..85769bdf7b 100644--- a/backend/plugin/advisor/tidb/advisor_column_no_null.go+++ b/backend/plugin/advisor/tidb/advisor_column_no_null.go@@ -12,6 +12,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -86,7 +87,7 @@ func (checker *columnNoNullChecker) generateAdvice() []*storepb.Advice {if col != nil && col.Nullable() {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.ColumnCannotNull.Int32(),+ Code: code.ColumnCannotNull.Int32(),Title: checker.title,Content: fmt.Sprintf("`%s`.`%s` cannot have NULL value", column.tableName, column.columnName),StartPosition: common.ConvertANTLRLineToPosition(column.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_require_default.go b/backend/plugin/advisor/tidb/advisor_column_require_default.goindex 5b3a28340d..b46093e017 100644--- a/backend/plugin/advisor/tidb/advisor_column_require_default.go+++ b/backend/plugin/advisor/tidb/advisor_column_require_default.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -123,7 +125,7 @@ func (checker *columRequireDefaultChecker) Enter(in ast.Node) (ast.Node, bool) {for _, column := range columnList {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.NoDefault.Int32(),+ Code: code.NoDefault.Int32(),Title: checker.title,Content: fmt.Sprintf("Column `%s`.`%s` doesn't have DEFAULT.", column.table, column.column),StartPosition: common.ConvertANTLRLineToPosition(column.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_required.go b/backend/plugin/advisor/tidb/advisor_column_required.goindex 1fda240c00..2b9f090baa 100644--- a/backend/plugin/advisor/tidb/advisor_column_required.go+++ b/backend/plugin/advisor/tidb/advisor_column_required.go@@ -6,6 +6,8 @@ import ("slices""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -133,7 +135,7 @@ func (v *columnRequirementChecker) generateAdviceList() []*storepb.Advice {slices.Sort(missingColumns)v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.NoRequiredColumn.Int32(),+ Code: code.NoRequiredColumn.Int32(),Title: v.title,Content: fmt.Sprintf("Table `%s` requires columns: %s", tableName, strings.Join(missingColumns, ", ")),StartPosition: common.ConvertANTLRLineToPosition(v.line[tableName]),diff --git a/backend/plugin/advisor/tidb/advisor_column_set_default_for_not_null.go b/backend/plugin/advisor/tidb/advisor_column_set_default_for_not_null.goindex 90273c8687..afeb98c85d 100644--- a/backend/plugin/advisor/tidb/advisor_column_set_default_for_not_null.go+++ b/backend/plugin/advisor/tidb/advisor_column_set_default_for_not_null.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -119,7 +121,7 @@ func (checker *columnSetDefaultForNotNullChecker) Enter(in ast.Node) (ast.Node,for _, column := range notNullColumnWithNoDefault {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.NotNullColumnWithNoDefault.Int32(),+ Code: code.NotNullColumnWithNoDefault.Int32(),Title: checker.title,Content: fmt.Sprintf("Column `%s`.`%s` is NOT NULL but doesn't have DEFAULT", column.tableName, column.columnName),StartPosition: common.ConvertANTLRLineToPosition(column.line),diff --git a/backend/plugin/advisor/tidb/advisor_column_type_disallow_list.go b/backend/plugin/advisor/tidb/advisor_column_type_disallow_list.goindex 7f879c3cb1..c31dceb8e6 100644--- a/backend/plugin/advisor/tidb/advisor_column_type_disallow_list.go+++ b/backend/plugin/advisor/tidb/advisor_column_type_disallow_list.go@@ -7,6 +7,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -124,7 +126,7 @@ func (checker *columnTypeDisallowListChecker) Enter(in ast.Node) (ast.Node, boolfor _, column := range columnList {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.DisabledColumnType.Int32(),+ Code: code.DisabledColumnType.Int32(),Title: checker.title,Content: fmt.Sprintf("Disallow column type %s but column `%s`.`%s` is", column.tp, column.table, column.column),StartPosition: common.ConvertANTLRLineToPosition(column.line),diff --git a/backend/plugin/advisor/tidb/advisor_database_drop_empty_db.go b/backend/plugin/advisor/tidb/advisor_database_drop_empty_db.goindex 6a3c575eb9..999469cb55 100644--- a/backend/plugin/advisor/tidb/advisor_database_drop_empty_db.go+++ b/backend/plugin/advisor/tidb/advisor_database_drop_empty_db.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -63,7 +65,7 @@ func (v *allowDropEmptyDBChecker) Enter(in ast.Node) (ast.Node, bool) {if v.originCatalog.DatabaseName() != node.Name.O {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.NotCurrentDatabase.Int32(),+ Code: code.NotCurrentDatabase.Int32(),Title: v.title,Content: fmt.Sprintf("Database `%s` that is trying to be deleted is not the current database `%s`", node.Name, v.originCatalog.DatabaseName()),StartPosition: common.ConvertANTLRLineToPosition(node.OriginTextPosition()),@@ -71,7 +73,7 @@ func (v *allowDropEmptyDBChecker) Enter(in ast.Node) (ast.Node, bool) {} else if !v.originCatalog.HasNoTable() {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.DatabaseNotEmpty.Int32(),+ Code: code.DatabaseNotEmpty.Int32(),Title: v.title,Content: fmt.Sprintf("Database `%s` is not allowed to drop if not empty", node.Name),StartPosition: common.ConvertANTLRLineToPosition(node.OriginTextPosition()),diff --git a/backend/plugin/advisor/tidb/advisor_index_key_number_limit.go b/backend/plugin/advisor/tidb/advisor_index_key_number_limit.goindex 82c9608a66..a952e9aa9a 100644--- a/backend/plugin/advisor/tidb/advisor_index_key_number_limit.go+++ b/backend/plugin/advisor/tidb/advisor_index_key_number_limit.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -108,7 +110,7 @@ func (checker *indexKeyNumberLimitChecker) Enter(in ast.Node) (ast.Node, bool) {for _, index := range indexList {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.IndexKeyNumberExceedsLimit.Int32(),+ Code: code.IndexKeyNumberExceedsLimit.Int32(),Title: checker.title,Content: fmt.Sprintf("The number of index `%s` in table `%s` should be not greater than %d", index.index, index.table, checker.max),StartPosition: common.ConvertANTLRLineToPosition(index.line),diff --git a/backend/plugin/advisor/tidb/advisor_index_no_duplicate_column.go b/backend/plugin/advisor/tidb/advisor_index_no_duplicate_column.goindex 14f781e7e8..edf536e696 100644--- a/backend/plugin/advisor/tidb/advisor_index_no_duplicate_column.go+++ b/backend/plugin/advisor/tidb/advisor_index_no_duplicate_column.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -129,7 +131,7 @@ func (checker *indexNoDuplicateColumnChecker) Enter(in ast.Node) (ast.Node, boolfor _, column := range columnList {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.DuplicateColumnInIndex.Int32(),+ Code: code.DuplicateColumnInIndex.Int32(),Title: checker.title,Content: fmt.Sprintf("%s `%s` has duplicate column `%s`.`%s`", column.tp, column.index, column.table, column.column),StartPosition: common.ConvertANTLRLineToPosition(column.line),diff --git a/backend/plugin/advisor/tidb/advisor_index_pk_type.go b/backend/plugin/advisor/tidb/advisor_index_pk_type.goindex 896acfe0ca..18e40f4a46 100644--- a/backend/plugin/advisor/tidb/advisor_index_pk_type.go+++ b/backend/plugin/advisor/tidb/advisor_index_pk_type.go@@ -6,6 +6,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pingcap/tidb/pkg/parser/mysql""github.com/pingcap/tidb/pkg/parser/types"@@ -138,7 +140,7 @@ func (v *indexPkTypeChecker) Enter(in ast.Node) (ast.Node, bool) {for _, pd := range pkDataList {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.IndexPKType.Int32(),+ Code: code.IndexPKType.Int32(),Title: v.title,Content: fmt.Sprintf("Columns in primary key must be INT/BIGINT but `%s`.`%s` is %s", pd.table, pd.column, pd.columnType),StartPosition: common.ConvertANTLRLineToPosition(pd.line),diff --git a/backend/plugin/advisor/tidb/advisor_index_primary_key_type_allowlist.go b/backend/plugin/advisor/tidb/advisor_index_primary_key_type_allowlist.goindex 1170735883..02f3654cd0 100644--- a/backend/plugin/advisor/tidb/advisor_index_primary_key_type_allowlist.go+++ b/backend/plugin/advisor/tidb/advisor_index_primary_key_type_allowlist.go@@ -7,6 +7,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -119,7 +121,7 @@ func (v *indexPrimaryKeyTypeAllowlistChecker) Enter(in ast.Node) (ast.Node, boolfor _, pd := range pkDataList {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.IndexPKType.Int32(),+ Code: code.IndexPKType.Int32(),Title: v.title,Content: fmt.Sprintf("The column `%s` in table `%s` is one of the primary key, but its type \"%s\" is not in allowlist", pd.column, pd.table, pd.columnType),StartPosition: common.ConvertANTLRLineToPosition(pd.line),diff --git a/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go b/backend/plugin/advisor/tidb/advisor_index_total_number_limit.goindex bcc1db145d..346a4efd65 100644--- a/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go+++ b/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go@@ -7,6 +7,8 @@ import ("fmt""slices"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -100,7 +102,7 @@ func (checker *indexTotalNumberLimitChecker) generateAdvice() []*storepb.Adviceif tableInfo != nil && tableInfo.CountIndex() > checker.max {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.IndexCountExceedsLimit.Int32(),+ Code: code.IndexCountExceedsLimit.Int32(),Title: checker.title,Content: fmt.Sprintf("The count of index in table `%s` should be no more than %d, but found %d", table.name, checker.max, tableInfo.CountIndex()),StartPosition: common.ConvertANTLRLineToPosition(table.line),diff --git a/backend/plugin/advisor/tidb/advisor_index_type_no_blob.go b/backend/plugin/advisor/tidb/advisor_index_type_no_blob.goindex 7d74b9e92f..a31df370bf 100644--- a/backend/plugin/advisor/tidb/advisor_index_type_no_blob.go+++ b/backend/plugin/advisor/tidb/advisor_index_type_no_blob.go@@ -7,6 +7,8 @@ import ("fmt""strings"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pingcap/tidb/pkg/parser/mysql""github.com/pingcap/tidb/pkg/parser/types"@@ -116,7 +118,7 @@ func (v *indexTypeNoBlobChecker) Enter(in ast.Node) (ast.Node, bool) {for _, pd := range pkDataList {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.IndexTypeNoBlob.Int32(),+ Code: code.IndexTypeNoBlob.Int32(),Title: v.title,Content: fmt.Sprintf("Columns in index must not be BLOB but `%s`.`%s` is %s", pd.table, pd.column, pd.columnType),StartPosition: common.ConvertANTLRLineToPosition(pd.line),diff --git a/backend/plugin/advisor/tidb/advisor_insert_disallow_order_by_rand.go b/backend/plugin/advisor/tidb/advisor_insert_disallow_order_by_rand.goindex 5f278dfa73..d6ca8291a5 100644--- a/backend/plugin/advisor/tidb/advisor_insert_disallow_order_by_rand.go+++ b/backend/plugin/advisor/tidb/advisor_insert_disallow_order_by_rand.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -62,7 +63,7 @@ type insertDisallowOrderByRandChecker struct {// Enter implements the ast.Visitor interface.func (checker *insertDisallowOrderByRandChecker) Enter(in ast.Node) (ast.Node, bool) {- code := advisor.Ok+ code := advisorcode.Okif insert, ok := in.(*ast.InsertStmt); ok {if insert.Select != nil {if selectNode, ok := insert.Select.(*ast.SelectStmt); ok {@@ -70,7 +71,7 @@ func (checker *insertDisallowOrderByRandChecker) Enter(in ast.Node) (ast.Node, bfor _, item := range selectNode.OrderBy.Items {if f, ok := item.Expr.(*ast.FuncCallExpr); ok {if f.FnName.L == ast.Rand {- code = advisor.InsertUseOrderByRand+ code = advisorcode.InsertUseOrderByRandbreak}}@@ -80,7 +81,7 @@ func (checker *insertDisallowOrderByRandChecker) Enter(in ast.Node) (ast.Node, b}}- if code != advisor.Ok {+ if code != advisorcode.Ok {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/tidb/advisor_insert_must_specify_column.go b/backend/plugin/advisor/tidb/advisor_insert_must_specify_column.goindex e10d4414c1..0406781f72 100644--- a/backend/plugin/advisor/tidb/advisor_insert_must_specify_column.go+++ b/backend/plugin/advisor/tidb/advisor_insert_must_specify_column.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -66,7 +67,7 @@ func (checker *insertMustSpecifyColumnChecker) Enter(in ast.Node) (ast.Node, booif node.Columns == nil {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.InsertNotSpecifyColumn.Int32(),+ Code: code.InsertNotSpecifyColumn.Int32(),Title: checker.title,Content: fmt.Sprintf("The INSERT statement must specify columns but \"%s\" does not", checker.text),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_migration_compatibility.go b/backend/plugin/advisor/tidb/advisor_migration_compatibility.goindex 66d9470f21..8585f0a2d0 100644--- a/backend/plugin/advisor/tidb/advisor_migration_compatibility.go+++ b/backend/plugin/advisor/tidb/advisor_migration_compatibility.go@@ -9,6 +9,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/pingcap/tidb/pkg/parser/ast")@@ -58,20 +59,20 @@ type compatibilityChecker struct {// Enter implements the ast.Visitor interface.func (v *compatibilityChecker) Enter(in ast.Node) (ast.Node, bool) {- code := advisor.Ok+ code := advisorcode.Okswitch node := in.(type) {// CREATE TABLEcase *ast.CreateTableStmt:v.lastCreateTable = node.Table.Name.O// DROP DATABASEcase *ast.DropDatabaseStmt:- code = advisor.CompatibilityDropDatabase+ code = advisorcode.CompatibilityDropDatabase// RENAME TABLEcase *ast.RenameTableStmt:- code = advisor.CompatibilityRenameTable+ code = advisorcode.CompatibilityRenameTable// DROP TABLE/VIEWcase *ast.DropTableStmt:- code = advisor.CompatibilityDropTable+ code = advisorcode.CompatibilityDropTable// ALTER TABLEcase *ast.AlterTableStmt:if node.Table.Name.O == v.lastCreateTable {@@ -80,42 +81,42 @@ func (v *compatibilityChecker) Enter(in ast.Node) (ast.Node, bool) {for _, spec := range node.Specs {// RENAME COLUMNif spec.Tp == ast.AlterTableRenameColumn {- code = advisor.CompatibilityRenameColumn+ code = advisorcode.CompatibilityRenameColumnbreak}// DROP COLUMNif spec.Tp == ast.AlterTableDropColumn {- code = advisor.CompatibilityDropColumn+ code = advisorcode.CompatibilityDropColumnbreak}// RENAME TABLEif spec.Tp == ast.AlterTableRenameTable {- code = advisor.CompatibilityRenameTable+ code = advisorcode.CompatibilityRenameTablebreak}if spec.Tp == ast.AlterTableAddConstraint {// ADD PRIMARY KEYif spec.Constraint.Tp == ast.ConstraintPrimaryKey {- code = advisor.CompatibilityAddPrimaryKey+ code = advisorcode.CompatibilityAddPrimaryKeybreak}// ADD UNIQUE/UNIQUE KEY/UNIQUE INDEXif spec.Constraint.Tp == ast.ConstraintPrimaryKey ||spec.Constraint.Tp == ast.ConstraintUniq ||spec.Constraint.Tp == ast.ConstraintUniqKey {- code = advisor.CompatibilityAddUniqueKey+ code = advisorcode.CompatibilityAddUniqueKeybreak}// ADD FOREIGN KEYif spec.Constraint.Tp == ast.ConstraintForeignKey {- code = advisor.CompatibilityAddForeignKey+ code = advisorcode.CompatibilityAddForeignKeybreak}// Check is only supported after 8.0.16 https://dev.mysql.com/doc/refman/8.0/en/create-table-check-constraints.html// ADD CHECK ENFORCEDif spec.Constraint.Tp == ast.ConstraintCheck && spec.Constraint.Enforced {- code = advisor.CompatibilityAddCheck+ code = advisorcode.CompatibilityAddCheckbreak}}@@ -124,7 +125,7 @@ func (v *compatibilityChecker) Enter(in ast.Node) (ast.Node, bool) {// ALTER CHECK ENFORCEDif spec.Tp == ast.AlterTableAlterCheck {if spec.Constraint.Enforced {- code = advisor.CompatibilityAlterCheck+ code = advisorcode.CompatibilityAlterCheckbreak}}@@ -135,7 +136,7 @@ func (v *compatibilityChecker) Enter(in ast.Node) (ast.Node, bool) {// 1. Change to a compatible data type such as INT to BIGINT// 2. Change properties such as comment, change it to NULLif spec.Tp == ast.AlterTableModifyColumn || spec.Tp == ast.AlterTableChangeColumn {- code = advisor.CompatibilityAlterColumn+ code = advisorcode.CompatibilityAlterColumnbreak}}@@ -146,11 +147,11 @@ func (v *compatibilityChecker) Enter(in ast.Node) (ast.Node, bool) {// CREATE UNIQUE INDEXcase *ast.CreateIndexStmt:if v.lastCreateTable != node.Table.Name.O && node.KeyType == ast.IndexKeyTypeUnique {- code = advisor.CompatibilityAddUniqueKey+ code = advisorcode.CompatibilityAddUniqueKey}}- if code != advisor.Ok {+ if code != advisorcode.Ok {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/tidb/advisor_naming_auto_increment_column.go b/backend/plugin/advisor/tidb/advisor_naming_auto_increment_column.goindex 0e3a402dfe..8ba217c082 100644--- a/backend/plugin/advisor/tidb/advisor_naming_auto_increment_column.go+++ b/backend/plugin/advisor/tidb/advisor_naming_auto_increment_column.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -121,7 +122,7 @@ func (checker *namingAutoIncrementColumnChecker) Enter(in ast.Node) (ast.Node, bif !checker.format.MatchString(column.name) {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.NamingAutoIncrementColumnConventionMismatch.Int32(),+ Code: code.NamingAutoIncrementColumnConventionMismatch.Int32(),Title: checker.title,Content: fmt.Sprintf("`%s`.`%s` mismatches auto_increment column naming convention, naming format should be %q", tableName, column.name, checker.format),StartPosition: common.ConvertANTLRLineToPosition(column.line),@@ -130,7 +131,7 @@ func (checker *namingAutoIncrementColumnChecker) Enter(in ast.Node) (ast.Node, bif checker.maxLength > 0 && len(column.name) > checker.maxLength {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.NamingAutoIncrementColumnConventionMismatch.Int32(),+ Code: code.NamingAutoIncrementColumnConventionMismatch.Int32(),Title: checker.title,Content: fmt.Sprintf("`%s`.`%s` mismatches auto_increment column naming convention, its length should be within %d characters", tableName, column.name, checker.maxLength),StartPosition: common.ConvertANTLRLineToPosition(column.line),diff --git a/backend/plugin/advisor/tidb/advisor_naming_column.go b/backend/plugin/advisor/tidb/advisor_naming_column.goindex 6373ee86c9..5404da72aa 100644--- a/backend/plugin/advisor/tidb/advisor_naming_column.go+++ b/backend/plugin/advisor/tidb/advisor_naming_column.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -116,7 +117,7 @@ func (v *namingColumnConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if !v.format.MatchString(column.name) {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.NamingColumnConventionMismatch.Int32(),+ Code: code.NamingColumnConventionMismatch.Int32(),Title: v.title,Content: fmt.Sprintf("`%s`.`%s` mismatches column naming convention, naming format should be %q", tableName, column.name, v.format),StartPosition: common.ConvertANTLRLineToPosition(column.line),@@ -125,7 +126,7 @@ func (v *namingColumnConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if v.maxLength > 0 && len(column.name) > v.maxLength {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.NamingColumnConventionMismatch.Int32(),+ Code: code.NamingColumnConventionMismatch.Int32(),Title: v.title,Content: fmt.Sprintf("`%s`.`%s` mismatches column naming convention, its length should be within %d characters", tableName, column.name, v.maxLength),StartPosition: common.ConvertANTLRLineToPosition(column.line),diff --git a/backend/plugin/advisor/tidb/advisor_naming_foreign_key_convention.go b/backend/plugin/advisor/tidb/advisor_naming_foreign_key_convention.goindex 3861779956..67260bce00 100644--- a/backend/plugin/advisor/tidb/advisor_naming_foreign_key_convention.go+++ b/backend/plugin/advisor/tidb/advisor_naming_foreign_key_convention.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -74,7 +75,7 @@ func (checker *namingFKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if err != nil {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for foreign key naming convention rule",Content: fmt.Sprintf("%q meet internal error %q", in.Text(), err.Error()),})@@ -83,7 +84,7 @@ func (checker *namingFKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if !regex.MatchString(indexData.indexName) {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.NamingFKConventionMismatch.Int32(),+ Code: code.NamingFKConventionMismatch.Int32(),Title: checker.title,Content: fmt.Sprintf("Foreign key in table `%s` mismatches the naming convention, expect %q but found `%s`", indexData.tableName, regex, indexData.indexName),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),@@ -92,7 +93,7 @@ func (checker *namingFKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.NamingFKConventionMismatch.Int32(),+ Code: code.NamingFKConventionMismatch.Int32(),Title: checker.title,Content: fmt.Sprintf("Foreign key `%s` in table `%s` mismatches the naming convention, its length should be within %d characters", indexData.indexName, indexData.tableName, checker.maxLength),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),diff --git a/backend/plugin/advisor/tidb/advisor_naming_index_convention.go b/backend/plugin/advisor/tidb/advisor_naming_index_convention.goindex 2173534b72..9245554c6e 100644--- a/backend/plugin/advisor/tidb/advisor_naming_index_convention.go+++ b/backend/plugin/advisor/tidb/advisor_naming_index_convention.go@@ -13,6 +13,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -78,7 +79,7 @@ func (checker *namingIndexConventionChecker) Enter(in ast.Node) (ast.Node, bool)if err != nil {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for index naming convention rule",Content: fmt.Sprintf("%q meet internal error %q", in.Text(), err.Error()),})@@ -87,7 +88,7 @@ func (checker *namingIndexConventionChecker) Enter(in ast.Node) (ast.Node, bool)if !regex.MatchString(indexData.indexName) {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.NamingIndexConventionMismatch.Int32(),+ Code: code.NamingIndexConventionMismatch.Int32(),Title: checker.title,Content: fmt.Sprintf("Index in table `%s` mismatches the naming convention, expect %q but found `%s`", indexData.tableName, regex, indexData.indexName),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),@@ -96,7 +97,7 @@ func (checker *namingIndexConventionChecker) Enter(in ast.Node) (ast.Node, bool)if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.NamingIndexConventionMismatch.Int32(),+ Code: code.NamingIndexConventionMismatch.Int32(),Title: checker.title,Content: fmt.Sprintf("Index `%s` in table `%s` mismatches the naming convention, its length should be within %d characters", indexData.indexName, indexData.tableName, checker.maxLength),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),diff --git a/backend/plugin/advisor/tidb/advisor_naming_table.go b/backend/plugin/advisor/tidb/advisor_naming_table.goindex 8f260134f3..9fa59fc191 100644--- a/backend/plugin/advisor/tidb/advisor_naming_table.go+++ b/backend/plugin/advisor/tidb/advisor_naming_table.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -89,7 +90,7 @@ func (v *namingTableConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if !v.format.MatchString(tableName) {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: v.title,Content: fmt.Sprintf("`%s` mismatches table naming convention, naming format should be %q", tableName, v.format),StartPosition: common.ConvertANTLRLineToPosition(in.OriginTextPosition()),@@ -98,7 +99,7 @@ func (v *namingTableConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if v.maxLength > 0 && len(tableName) > v.maxLength {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.NamingTableConventionMismatch.Int32(),+ Code: code.NamingTableConventionMismatch.Int32(),Title: v.title,Content: fmt.Sprintf("`%s` mismatches table naming convention, its length should be within %d characters", tableName, v.maxLength),StartPosition: common.ConvertANTLRLineToPosition(in.OriginTextPosition()),diff --git a/backend/plugin/advisor/tidb/advisor_naming_unique_key_convention.go b/backend/plugin/advisor/tidb/advisor_naming_unique_key_convention.goindex d81d2f12e1..700015d88c 100644--- a/backend/plugin/advisor/tidb/advisor_naming_unique_key_convention.go+++ b/backend/plugin/advisor/tidb/advisor_naming_unique_key_convention.go@@ -12,6 +12,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -77,7 +78,7 @@ func (checker *namingUKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if err != nil {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for unique key naming convention rule",Content: fmt.Sprintf("%q meet internal error %q", in.Text(), err.Error()),})@@ -86,7 +87,7 @@ func (checker *namingUKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if !regex.MatchString(indexData.indexName) {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.NamingUKConventionMismatch.Int32(),+ Code: code.NamingUKConventionMismatch.Int32(),Title: checker.title,Content: fmt.Sprintf("Unique key in table `%s` mismatches the naming convention, expect %q but found `%s`", indexData.tableName, regex, indexData.indexName),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),@@ -95,7 +96,7 @@ func (checker *namingUKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.NamingUKConventionMismatch.Int32(),+ Code: code.NamingUKConventionMismatch.Int32(),Title: checker.title,Content: fmt.Sprintf("Unique key `%s` in table `%s` mismatches the naming convention, its length should be within %d characters", indexData.indexName, indexData.tableName, checker.maxLength),StartPosition: common.ConvertANTLRLineToPosition(indexData.line),diff --git a/backend/plugin/advisor/tidb/advisor_statement_disallow_mix_in_ddl.go b/backend/plugin/advisor/tidb/advisor_statement_disallow_mix_in_ddl.goindex c37e103f4e..1446fa0ce1 100644--- a/backend/plugin/advisor/tidb/advisor_statement_disallow_mix_in_ddl.go+++ b/backend/plugin/advisor/tidb/advisor_statement_disallow_mix_in_ddl.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -49,7 +50,7 @@ func (*StatementDisallowMixInDDLAdvisor) Check(_ context.Context, checkCtx advisStatus: level,Title: title,Content: fmt.Sprintf("Alter schema can only run DDL, \"%s\" is not DDL", stmtNode.Text()),- Code: advisor.StatementDisallowMixDDLDML.Int32(),+ Code: code.StatementDisallowMixDDLDML.Int32(),StartPosition: common.ConvertANTLRLineToPosition(stmtNode.OriginTextPosition()),})}diff --git a/backend/plugin/advisor/tidb/advisor_statement_disallow_mix_in_dml.go b/backend/plugin/advisor/tidb/advisor_statement_disallow_mix_in_dml.goindex 6d6b466cbb..9dd8288d9e 100644--- a/backend/plugin/advisor/tidb/advisor_statement_disallow_mix_in_dml.go+++ b/backend/plugin/advisor/tidb/advisor_statement_disallow_mix_in_dml.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -49,7 +50,7 @@ func (*StatementDisallowMixInDMLAdvisor) Check(_ context.Context, checkCtx advisStatus: level,Title: title,Content: fmt.Sprintf("Data change can only run DML, \"%s\" is not DML", stmtNode.Text()),- Code: advisor.StatementDisallowMixDDLDML.Int32(),+ Code: code.StatementDisallowMixDDLDML.Int32(),StartPosition: common.ConvertANTLRLineToPosition(stmtNode.OriginTextPosition()),})}diff --git a/backend/plugin/advisor/tidb/advisor_statement_dml_dry_run.go b/backend/plugin/advisor/tidb/advisor_statement_dml_dry_run.goindex a2b979dc4d..55f33f71df 100644--- a/backend/plugin/advisor/tidb/advisor_statement_dml_dry_run.go+++ b/backend/plugin/advisor/tidb/advisor_statement_dml_dry_run.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -79,7 +80,7 @@ func (checker *statementDmlDryRunChecker) Enter(in ast.Node) (ast.Node, bool) {if _, err := advisor.Query(checker.ctx, advisor.QueryContext{}, checker.driver, storepb.Engine_TIDB, fmt.Sprintf("EXPLAIN %s", node.Text())); err != nil {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.StatementDMLDryRunFailed.Int32(),+ Code: code.StatementDMLDryRunFailed.Int32(),Title: checker.title,Content: fmt.Sprintf("\"%s\" dry runs failed: %s", node.Text(), err.Error()),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_statement_maximum_limit_value.go b/backend/plugin/advisor/tidb/advisor_statement_maximum_limit_value.goindex ef1c8382d4..afd9b0cbd8 100644--- a/backend/plugin/advisor/tidb/advisor_statement_maximum_limit_value.go+++ b/backend/plugin/advisor/tidb/advisor_statement_maximum_limit_value.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -77,7 +78,7 @@ func (checker *statementMaximumLimitValueChecker) Enter(in ast.Node) (ast.Node,if limitVal > int64(checker.limitMaxValue) {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.StatementExceedMaximumLimitValue.Int32(),+ Code: code.StatementExceedMaximumLimitValue.Int32(),Title: checker.title,Content: fmt.Sprintf("The limit value %d exceeds the maximum allowed value %d", limitVal, checker.limitMaxValue),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_statement_merge_alter_table.go b/backend/plugin/advisor/tidb/advisor_statement_merge_alter_table.goindex 3a6488fa54..d9961a2a9a 100644--- a/backend/plugin/advisor/tidb/advisor_statement_merge_alter_table.go+++ b/backend/plugin/advisor/tidb/advisor_statement_merge_alter_table.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -119,7 +120,7 @@ func (checker *statementMergeAlterTableChecker) generateAdvice() []*storepb.Adviif table.count > 1 {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.StatementRedundantAlterTable.Int32(),+ Code: code.StatementRedundantAlterTable.Int32(),Title: checker.title,Content: fmt.Sprintf("There are %d statements to modify table `%s`", table.count, table.name),StartPosition: common.ConvertANTLRLineToPosition(table.lastLine),diff --git a/backend/plugin/advisor/tidb/advisor_stmt_disallow_commit.go b/backend/plugin/advisor/tidb/advisor_stmt_disallow_commit.goindex 84db9ddbf0..50f680723e 100644--- a/backend/plugin/advisor/tidb/advisor_stmt_disallow_commit.go+++ b/backend/plugin/advisor/tidb/advisor_stmt_disallow_commit.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -65,7 +66,7 @@ func (c *statementDisallowCommitChecker) Enter(in ast.Node) (ast.Node, bool) {if _, ok := in.(*ast.CommitStmt); ok {c.adviceList = append(c.adviceList, &storepb.Advice{Status: c.level,- Code: advisor.StatementDisallowCommit.Int32(),+ Code: code.StatementDisallowCommit.Int32(),Title: c.title,Content: fmt.Sprintf("Commit is not allowed, related statement: \"%s\"", c.text),StartPosition: common.ConvertANTLRLineToPosition(c.line),diff --git a/backend/plugin/advisor/tidb/advisor_stmt_disallow_limit.go b/backend/plugin/advisor/tidb/advisor_stmt_disallow_limit.goindex 5e293602a8..5cfefe6cf1 100644--- a/backend/plugin/advisor/tidb/advisor_stmt_disallow_limit.go+++ b/backend/plugin/advisor/tidb/advisor_stmt_disallow_limit.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -62,23 +63,23 @@ type statementDisallowLimitChecker struct {// Enter implements the ast.Visitor interface.func (checker *statementDisallowLimitChecker) Enter(in ast.Node) (ast.Node, bool) {- code := advisor.Ok+ code := advisorcode.Okswitch node := in.(type) {case *ast.UpdateStmt:if node.Limit != nil {- code = advisor.UpdateUseLimit+ code = advisorcode.UpdateUseLimit}case *ast.DeleteStmt:if node.Limit != nil {- code = advisor.DeleteUseLimit+ code = advisorcode.DeleteUseLimit}case *ast.InsertStmt:if useLimit(node) {- code = advisor.InsertUseLimit+ code = advisorcode.InsertUseLimit}}- if code != advisor.Ok {+ if code != advisorcode.Ok {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/tidb/advisor_stmt_disallow_order_by.go b/backend/plugin/advisor/tidb/advisor_stmt_disallow_order_by.goindex d923c17f23..139b6b51b5 100644--- a/backend/plugin/advisor/tidb/advisor_stmt_disallow_order_by.go+++ b/backend/plugin/advisor/tidb/advisor_stmt_disallow_order_by.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -62,19 +63,19 @@ type disallowOrderByChecker struct {// Enter implements the ast.Visitor interface.func (checker *disallowOrderByChecker) Enter(in ast.Node) (ast.Node, bool) {- code := advisor.Ok+ code := advisorcode.Okswitch node := in.(type) {case *ast.UpdateStmt:if node.Order != nil {- code = advisor.UpdateUseOrderBy+ code = advisorcode.UpdateUseOrderBy}case *ast.DeleteStmt:if node.Order != nil {- code = advisor.DeleteUseOrderBy+ code = advisorcode.DeleteUseOrderBy}}- if code != advisor.Ok {+ if code != advisorcode.Ok {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/tidb/advisor_stmt_no_leading_wildcard_like.go b/backend/plugin/advisor/tidb/advisor_stmt_no_leading_wildcard_like.goindex 7ba5117d58..5004c6c181 100644--- a/backend/plugin/advisor/tidb/advisor_stmt_no_leading_wildcard_like.go+++ b/backend/plugin/advisor/tidb/advisor_stmt_no_leading_wildcard_like.go@@ -11,6 +11,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")const (@@ -51,7 +52,7 @@ func (*NoLeadingWildcardLikeAdvisor) Check(_ context.Context, checkCtx advisor.Cif checker.leadingWildcardLike {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.StatementLeadingWildcardLike.Int32(),+ Code: code.StatementLeadingWildcardLike.Int32(),Title: string(checkCtx.Rule.Type),Content: fmt.Sprintf("\"%s\" uses leading wildcard LIKE", checker.text),StartPosition: common.ConvertANTLRLineToPosition(stmtNode.OriginTextPosition()),@@ -76,7 +77,7 @@ func (v *noLeadingWildcardLikeChecker) Enter(in ast.Node) (ast.Node, bool) {if err != nil {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.Internal.Int32(),+ Code: code.Internal.Int32(),Title: "Internal error for no leading wildcard LIKE rule",Content: fmt.Sprintf("\"%s\" meet internal error %q", v.text, err.Error()),})diff --git a/backend/plugin/advisor/tidb/advisor_stmt_no_select_all.go b/backend/plugin/advisor/tidb/advisor_stmt_no_select_all.goindex 8edd7ee630..7cc606022e 100644--- a/backend/plugin/advisor/tidb/advisor_stmt_no_select_all.go+++ b/backend/plugin/advisor/tidb/advisor_stmt_no_select_all.go@@ -10,6 +10,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -64,7 +65,7 @@ func (v *noSelectAllChecker) Enter(in ast.Node) (ast.Node, bool) {if field.WildCard != nil {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.StatementSelectAll.Int32(),+ Code: code.StatementSelectAll.Int32(),Title: v.title,Content: fmt.Sprintf("\"%s\" uses SELECT all", v.text),StartPosition: common.ConvertANTLRLineToPosition(v.line),diff --git a/backend/plugin/advisor/tidb/advisor_stmt_where_required_for_select.go b/backend/plugin/advisor/tidb/advisor_stmt_where_required_for_select.goindex 44b58cdaa0..6207a634c9 100644--- a/backend/plugin/advisor/tidb/advisor_stmt_where_required_for_select.go+++ b/backend/plugin/advisor/tidb/advisor_stmt_where_required_for_select.go@@ -9,6 +9,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/pingcap/tidb/pkg/parser/ast")@@ -60,15 +61,15 @@ type whereRequirementForSelectChecker struct {// Enter implements the ast.Visitor interface.func (v *whereRequirementForSelectChecker) Enter(in ast.Node) (ast.Node, bool) {- code := advisor.Ok+ code := advisorcode.Okif node, ok := in.(*ast.SelectStmt); ok {// Allow SELECT queries without a FROM clause to proceed, e.g. SELECT 1.if node.Where == nil && node.From != nil {- code = advisor.StatementNoWhere+ code = advisorcode.StatementNoWhere}}- if code != advisor.Ok {+ if code != advisorcode.Ok {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/tidb/advisor_stmt_where_required_for_update_delete.go b/backend/plugin/advisor/tidb/advisor_stmt_where_required_for_update_delete.goindex 847d3d639f..a79bd3098d 100644--- a/backend/plugin/advisor/tidb/advisor_stmt_where_required_for_update_delete.go+++ b/backend/plugin/advisor/tidb/advisor_stmt_where_required_for_update_delete.go@@ -9,6 +9,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code""github.com/pingcap/tidb/pkg/parser/ast")@@ -60,21 +61,21 @@ type whereRequirementForUpdateDeleteChecker struct {// Enter implements the ast.Visitor interface.func (v *whereRequirementForUpdateDeleteChecker) Enter(in ast.Node) (ast.Node, bool) {- code := advisor.Ok+ code := advisorcode.Okswitch node := in.(type) {// DELETEcase *ast.DeleteStmt:if node.Where == nil {- code = advisor.StatementNoWhere+ code = advisorcode.StatementNoWhere}// UPDATEcase *ast.UpdateStmt:if node.Where == nil {- code = advisor.StatementNoWhere+ code = advisorcode.StatementNoWhere}}- if code != advisor.Ok {+ if code != advisorcode.Ok {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/tidb/advisor_table_comment_convention.go b/backend/plugin/advisor/tidb/advisor_table_comment_convention.goindex f85f720d60..a36642b32a 100644--- a/backend/plugin/advisor/tidb/advisor_table_comment_convention.go+++ b/backend/plugin/advisor/tidb/advisor_table_comment_convention.go@@ -12,6 +12,7 @@ import ("github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")var (@@ -75,7 +76,7 @@ func (checker *tableCommentConventionChecker) Enter(in ast.Node) (ast.Node, boolif checker.payload.Required && !exist {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.CommentEmpty.Int32(),+ Code: code.CommentEmpty.Int32(),Title: checker.title,Content: fmt.Sprintf("Table `%s` requires comments", node.Table.Name.O),StartPosition: common.ConvertANTLRLineToPosition(checker.line),@@ -84,7 +85,7 @@ func (checker *tableCommentConventionChecker) Enter(in ast.Node) (ast.Node, boolif checker.payload.MaxLength >= 0 && len(comment) > checker.payload.MaxLength {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.CommentTooLong.Int32(),+ Code: code.CommentTooLong.Int32(),Title: checker.title,Content: fmt.Sprintf("The length of table `%s` comment should be within %d characters", node.Table.Name.O, checker.payload.MaxLength),StartPosition: common.ConvertANTLRLineToPosition(checker.line),@@ -94,7 +95,7 @@ func (checker *tableCommentConventionChecker) Enter(in ast.Node) (ast.Node, boolif classification, _ := common.GetClassificationAndUserComment(comment, checker.classificationConfig); classification == "" {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.CommentMissingClassification.Int32(),+ Code: code.CommentMissingClassification.Int32(),Title: checker.title,Content: fmt.Sprintf("Table `%s` comment requires classification", node.Table.Name.O),StartPosition: common.ConvertANTLRLineToPosition(checker.line),diff --git a/backend/plugin/advisor/tidb/advisor_table_disallow_partition.go b/backend/plugin/advisor/tidb/advisor_table_disallow_partition.goindex 74a6c36209..5a48c3736f 100644--- a/backend/plugin/advisor/tidb/advisor_table_disallow_partition.go+++ b/backend/plugin/advisor/tidb/advisor_table_disallow_partition.go@@ -6,6 +6,8 @@ import ("context""fmt"+ advisorcode "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -62,22 +64,22 @@ type tableDisallowPartitionChecker struct {// Enter implements the ast.Visitor interface.func (checker *tableDisallowPartitionChecker) Enter(in ast.Node) (ast.Node, bool) {- code := advisor.Ok+ code := advisorcode.Okswitch node := in.(type) {case *ast.CreateTableStmt:if node.Partition != nil {- code = advisor.CreateTablePartition+ code = advisorcode.CreateTablePartition}case *ast.AlterTableStmt:for _, spec := range node.Specs {if spec.Tp == ast.AlterTablePartition {- code = advisor.CreateTablePartition+ code = advisorcode.CreateTablePartitionbreak}}}- if code != advisor.Ok {+ if code != advisorcode.Ok {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,Code: code.Int32(),diff --git a/backend/plugin/advisor/tidb/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/tidb/advisor_table_drop_naming_convention.goindex f25a87aca9..797a5bde61 100644--- a/backend/plugin/advisor/tidb/advisor_table_drop_naming_convention.go+++ b/backend/plugin/advisor/tidb/advisor_table_drop_naming_convention.go@@ -5,6 +5,8 @@ import ("fmt""regexp"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -68,7 +70,7 @@ func (v *namingDropTableConventionChecker) Enter(in ast.Node) (ast.Node, bool) {if !v.format.MatchString(table.Name.O) {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.TableDropNamingConventionMismatch.Int32(),+ Code: code.TableDropNamingConventionMismatch.Int32(),Title: v.title,Content: fmt.Sprintf("`%s` mismatches drop table naming convention, naming format should be %q", table.Name.O, v.format),StartPosition: common.ConvertANTLRLineToPosition(node.OriginTextPosition()),diff --git a/backend/plugin/advisor/tidb/advisor_table_no_fk.go b/backend/plugin/advisor/tidb/advisor_table_no_fk.goindex 75e953bf59..0c6f699f66 100644--- a/backend/plugin/advisor/tidb/advisor_table_no_fk.go+++ b/backend/plugin/advisor/tidb/advisor_table_no_fk.go@@ -4,6 +4,8 @@ import ("context""fmt"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"+"github.com/pingcap/tidb/pkg/parser/ast""github.com/pkg/errors"@@ -61,7 +63,7 @@ func (checker *tableNoFKChecker) Enter(in ast.Node) (ast.Node, bool) {if constraint.Tp == ast.ConstraintForeignKey {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.TableHasFK.Int32(),+ Code: code.TableHasFK.Int32(),Title: checker.title,Content: fmt.Sprintf("Foreign key is not allowed in the table `%s`", node.Table.Name),StartPosition: common.ConvertANTLRLineToPosition(constraint.OriginTextPosition()),@@ -73,7 +75,7 @@ func (checker *tableNoFKChecker) Enter(in ast.Node) (ast.Node, bool) {if spec.Tp == ast.AlterTableAddConstraint && spec.Constraint.Tp == ast.ConstraintForeignKey {checker.adviceList = append(checker.adviceList, &storepb.Advice{Status: checker.level,- Code: advisor.TableHasFK.Int32(),+ Code: code.TableHasFK.Int32(),Title: checker.title,Content: fmt.Sprintf("Foreign key is not allowed in the table `%s`", node.Table.Name),StartPosition: common.ConvertANTLRLineToPosition(in.OriginTextPosition()),diff --git a/backend/plugin/advisor/tidb/advisor_table_require_pk.go b/backend/plugin/advisor/tidb/advisor_table_require_pk.goindex bc9f182c60..6530280c98 100644--- a/backend/plugin/advisor/tidb/advisor_table_require_pk.go+++ b/backend/plugin/advisor/tidb/advisor_table_require_pk.go@@ -12,6 +12,7 @@ import (storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"+ "github.com/bytebase/bytebase/backend/plugin/advisor/code")const (@@ -141,7 +142,7 @@ func (v *tableRequirePKChecker) generateAdviceList() []*storepb.Advice {if len(v.tables[tableName]) == 0 {v.adviceList = append(v.adviceList, &storepb.Advice{Status: v.level,- Code: advisor.TableNoPK.Int32(),+ Code: code.TableNoPK.Int32(),Title: v.title,Content: fmt.Sprintf("Table `%s` requires PRIMARY KEY", tableName),StartPosition: common.ConvertANTLRLineToPosition(v.line[tableName]),