Skip to content

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

chore: update the db type (#2098)

ecmadaod6c6c37c416c
diff --git a/api/task_check_run.go b/api/task_check_run.go
index 1abf3c980c..b52c0bdc35 100644
--- a/api/task_check_run.go
+++ b/api/task_check_run.go
@@ -2,10 +2,10 @@ package api
import (
"encoding/json"
- "fmt"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/plugin/advisor"
+ advisorDB "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/db"
)
@@ -198,24 +198,10 @@ type TaskCheckRunStatusPatch struct {
Result string
}
-// ConvertToAdvisorDBType will convert db type into advisor db type.
-func ConvertToAdvisorDBType(dbType db.Type) (advisor.DBType, error) {
- switch dbType {
- case db.MySQL:
- return advisor.MySQL, nil
- case db.Postgres:
- return advisor.Postgres, nil
- case db.TiDB:
- return advisor.TiDB, nil
- }
-
- return "", fmt.Errorf("unsupported db type %s for advisor", dbType)
-}
-
// IsSyntaxCheckSupported checks the engine type if syntax check supports it.
func IsSyntaxCheckSupported(dbType db.Type, mode common.ReleaseMode) bool {
if mode == common.ReleaseModeDev || dbType == db.MySQL || dbType == db.TiDB {
- advisorDB, err := ConvertToAdvisorDBType(dbType)
+ advisorDB, err := advisorDB.ConvertToAdvisorDBType(string(dbType))
if err != nil {
return false
}
@@ -229,7 +215,7 @@ func IsSyntaxCheckSupported(dbType db.Type, mode common.ReleaseMode) bool {
// IsSQLReviewSupported checks the engine type if schema review supports it.
func IsSQLReviewSupported(dbType db.Type, mode common.ReleaseMode) bool {
if mode == common.ReleaseModeDev || dbType == db.MySQL || dbType == db.TiDB {
- advisorDB, err := ConvertToAdvisorDBType(dbType)
+ advisorDB, err := advisorDB.ConvertToAdvisorDBType(string(dbType))
if err != nil {
return false
}
diff --git a/docs/openapi/docs.go b/docs/openapi/docs.go
index 2655df81ce..32127661da 100644
--- a/docs/openapi/docs.go
+++ b/docs/openapi/docs.go
@@ -55,9 +55,9 @@ const docTemplate = `{
},
{
"enum": [
- "MySQL",
- "PostgreSQL",
- "TiDB"
+ "MYSQL",
+ "POSTGRES",
+ "TIDB"
],
"type": "string",
"description": "The database type. Required if the port, host and database name is not specified.",
diff --git a/docs/openapi/swagger.yaml b/docs/openapi/swagger.yaml
index 4d07df4b3b..ea88bc4fbc 100644
--- a/docs/openapi/swagger.yaml
+++ b/docs/openapi/swagger.yaml
@@ -51,9 +51,9 @@ paths:
- description: The database type. Required if the port, host and database name
is not specified.
enum:
- - MySQL
- - PostgreSQL
- - TiDB
+ - MYSQL
+ - POSTGRES
+ - TIDB
in: query
name: databaseType
type: string
diff --git a/docs/sqlservice/docs.go b/docs/sqlservice/docs.go
index 66e1b2ac49..a942c03d8e 100644
--- a/docs/sqlservice/docs.go
+++ b/docs/sqlservice/docs.go
@@ -48,9 +48,9 @@ const docTemplate = `{
},
{
"enum": [
- "MySQL",
- "PostgreSQL",
- "TiDB"
+ "MYSQL",
+ "POSTGRES",
+ "TIDB"
],
"type": "string",
"description": "The database type.",
diff --git a/docs/sqlservice/swagger.yaml b/docs/sqlservice/swagger.yaml
index a33f2fb69d..80de9cc0c9 100644
--- a/docs/sqlservice/swagger.yaml
+++ b/docs/sqlservice/swagger.yaml
@@ -45,9 +45,9 @@ paths:
type: string
- description: The database type.
enum:
- - MySQL
- - PostgreSQL
- - TiDB
+ - MYSQL
+ - POSTGRES
+ - TIDB
in: query
name: databaseType
required: true
diff --git a/plugin/advisor/advisor.go b/plugin/advisor/advisor.go
index 6967c644c5..d82586b525 100644
--- a/plugin/advisor/advisor.go
+++ b/plugin/advisor/advisor.go
@@ -7,6 +7,7 @@ import (
"sync"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"go.uber.org/zap/zapcore"
)
@@ -191,13 +192,13 @@ type Advisor interface {
var (
advisorMu sync.RWMutex
- advisors = make(map[DBType]map[Type]Advisor)
+ advisors = make(map[db.Type]map[Type]Advisor)
)
// Register makes a advisor available by the provided id.
// If Register is called twice with the same name or if advisor is nil,
// it panics.
-func Register(dbType DBType, advType Type, f Advisor) {
+func Register(dbType db.Type, advType Type, f Advisor) {
advisorMu.Lock()
defer advisorMu.Unlock()
if f == nil {
@@ -217,7 +218,7 @@ func Register(dbType DBType, advType Type, f Advisor) {
}
// Check runs the advisor and returns the advices.
-func Check(dbType DBType, advType Type, ctx Context, statement string) ([]Advice, error) {
+func Check(dbType db.Type, advType Type, ctx Context, statement string) ([]Advice, error) {
advisorMu.RLock()
dbAdvisors, ok := advisors[dbType]
defer advisorMu.RUnlock()
@@ -234,18 +235,18 @@ func Check(dbType DBType, advType Type, ctx Context, statement string) ([]Advice
}
// IsSyntaxCheckSupported checks the engine type if syntax check supports it.
-func IsSyntaxCheckSupported(dbType DBType) bool {
+func IsSyntaxCheckSupported(dbType db.Type) bool {
switch dbType {
- case MySQL, TiDB, Postgres:
+ case db.MySQL, db.TiDB, db.Postgres:
return true
}
return false
}
// IsSQLReviewSupported checks the engine type if schema review supports it.
-func IsSQLReviewSupported(dbType DBType) bool {
+func IsSQLReviewSupported(dbType db.Type) bool {
switch dbType {
- case MySQL, TiDB, Postgres:
+ case db.MySQL, db.TiDB, db.Postgres:
return true
}
return false
diff --git a/plugin/advisor/catalog/catalog.go b/plugin/advisor/catalog/catalog.go
index ee0ecd2c1e..846e325428 100644
--- a/plugin/advisor/catalog/catalog.go
+++ b/plugin/advisor/catalog/catalog.go
@@ -2,6 +2,8 @@ package catalog
import (
"context"
+
+ "github.com/bytebase/bytebase/plugin/advisor/db"
)
// Catalog is the service for catalog.
@@ -14,7 +16,7 @@ type Database struct {
Name string
CharacterSet string
Collation string
- DbType DBType
+ DbType db.Type
SchemaList []*Schema
}
@@ -125,7 +127,7 @@ type IndexFind struct {
// FindIndex finds the index.
func (d *Database) FindIndex(find *IndexFind) (string, *Index) {
// notMatchTable is used for PostgreSQL. In PostgreSQL, the index name is unique in a schema, not a table.
- notMatchTable := (d.DbType == Postgres && find.SchemaName != "" && find.TableName == "")
+ notMatchTable := (d.DbType == db.Postgres && find.SchemaName != "" && find.TableName == "")
for _, schema := range d.SchemaList {
if schema.Name != find.SchemaName {
continue
diff --git a/plugin/advisor/catalog/db.go b/plugin/advisor/catalog/db.go
deleted file mode 100644
index 56c29139f1..0000000000
--- a/plugin/advisor/catalog/db.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package catalog
-
-// DBType is the type of a database.
-type DBType string
-
-const (
- // MySQL is the database type for MYSQL.
- MySQL DBType = "MYSQL"
- // Postgres is the database type for POSTGRES.
- Postgres DBType = "POSTGRES"
- // TiDB is the database type for TiDB.
- TiDB DBType = "TIDB"
-)
diff --git a/plugin/advisor/db.go b/plugin/advisor/db.go
deleted file mode 100644
index 82ed84b2d4..0000000000
--- a/plugin/advisor/db.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package advisor
-
-// DBType is the type of a database.
-type DBType string
-
-const (
- // MySQL is the database type for MYSQL.
- MySQL DBType = "MYSQL"
- // Postgres is the database type for POSTGRES.
- Postgres DBType = "POSTGRES"
- // TiDB is the database type for TiDB.
- TiDB DBType = "TIDB"
-)
diff --git a/plugin/advisor/db/db.go b/plugin/advisor/db/db.go
new file mode 100644
index 0000000000..10d4a495ff
--- /dev/null
+++ b/plugin/advisor/db/db.go
@@ -0,0 +1,33 @@
+package db
+
+import (
+ "fmt"
+ "strings"
+)
+
+// Type is the type of a database.
+// nolint
+type Type string
+
+const (
+ // MySQL is the database type for MYSQL.
+ MySQL Type = "MYSQL"
+ // Postgres is the database type for POSTGRES.
+ Postgres Type = "POSTGRES"
+ // TiDB is the database type for TiDB.
+ TiDB Type = "TIDB"
+)
+
+// ConvertToAdvisorDBType will convert db type into advisor db type.
+func ConvertToAdvisorDBType(dbType string) (Type, error) {
+ switch strings.ToUpper(dbType) {
+ case string(MySQL):
+ return MySQL, nil
+ case string(Postgres):
+ return Postgres, nil
+ case string(TiDB):
+ return TiDB, nil
+ }
+
+ return "", fmt.Errorf("unsupported db type %s for advisor", dbType)
+}
diff --git a/plugin/advisor/fake/fake_advisor.go b/plugin/advisor/fake/fake_advisor.go
index 5bb345c41f..3789a65eb3 100644
--- a/plugin/advisor/fake/fake_advisor.go
+++ b/plugin/advisor/fake/fake_advisor.go
@@ -2,6 +2,7 @@ package fake
import (
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
)
var (
@@ -9,9 +10,9 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.Fake, &Advisor{})
- advisor.Register(advisor.Postgres, advisor.Fake, &Advisor{})
- advisor.Register(advisor.TiDB, advisor.Fake, &Advisor{})
+ advisor.Register(db.MySQL, advisor.Fake, &Advisor{})
+ advisor.Register(db.Postgres, advisor.Fake, &Advisor{})
+ advisor.Register(db.TiDB, advisor.Fake, &Advisor{})
}
// Advisor is the fake sql advisor.
diff --git a/plugin/advisor/mysql/advisor_column_no_null.go b/plugin/advisor/mysql/advisor_column_no_null.go
index 22a0334304..d27bc43748 100644
--- a/plugin/advisor/mysql/advisor_column_no_null.go
+++ b/plugin/advisor/mysql/advisor_column_no_null.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -13,8 +14,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLColumnNoNull, &ColumnNoNullAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLColumnNoNull, &ColumnNoNullAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLColumnNoNull, &ColumnNoNullAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLColumnNoNull, &ColumnNoNullAdvisor{})
}
// ColumnNoNullAdvisor is the advisor checking for column no NULL value.
diff --git a/plugin/advisor/mysql/advisor_column_required.go b/plugin/advisor/mysql/advisor_column_required.go
index 554097d5a0..2986cbafad 100644
--- a/plugin/advisor/mysql/advisor_column_required.go
+++ b/plugin/advisor/mysql/advisor_column_required.go
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -15,8 +16,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLColumnRequirement, &ColumnRequirementAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLColumnRequirement, &ColumnRequirementAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLColumnRequirement, &ColumnRequirementAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLColumnRequirement, &ColumnRequirementAdvisor{})
}
// ColumnRequirementAdvisor is the advisor checking for column requirement.
diff --git a/plugin/advisor/mysql/advisor_database_drop_empty_db.go b/plugin/advisor/mysql/advisor_database_drop_empty_db.go
index 02656ebb88..88a8674df2 100644
--- a/plugin/advisor/mysql/advisor_database_drop_empty_db.go
+++ b/plugin/advisor/mysql/advisor_database_drop_empty_db.go
@@ -5,6 +5,7 @@ import (
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -14,8 +15,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLDatabaseAllowDropIfEmpty, &DatabaseAllowDropIfEmptyAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLDatabaseAllowDropIfEmpty, &DatabaseAllowDropIfEmptyAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLDatabaseAllowDropIfEmpty, &DatabaseAllowDropIfEmptyAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLDatabaseAllowDropIfEmpty, &DatabaseAllowDropIfEmptyAdvisor{})
}
// DatabaseAllowDropIfEmptyAdvisor is the advisor checking the MySQLDatabaseAllowDropIfEmpty rule.
diff --git a/plugin/advisor/mysql/advisor_migration_compatibility.go b/plugin/advisor/mysql/advisor_migration_compatibility.go
index 3c6e688c18..19f22d03d4 100644
--- a/plugin/advisor/mysql/advisor_migration_compatibility.go
+++ b/plugin/advisor/mysql/advisor_migration_compatibility.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -14,8 +15,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLMigrationCompatibility, &CompatibilityAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLMigrationCompatibility, &CompatibilityAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLMigrationCompatibility, &CompatibilityAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLMigrationCompatibility, &CompatibilityAdvisor{})
}
// CompatibilityAdvisor is the advisor checking for schema backward compatibility.
diff --git a/plugin/advisor/mysql/advisor_naming_column.go b/plugin/advisor/mysql/advisor_naming_column.go
index 57255a9314..6bd7c725e6 100644
--- a/plugin/advisor/mysql/advisor_naming_column.go
+++ b/plugin/advisor/mysql/advisor_naming_column.go
@@ -5,6 +5,7 @@ import (
"regexp"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -14,8 +15,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLNamingColumnConvention, &NamingColumnConventionAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLNamingColumnConvention, &NamingColumnConventionAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLNamingColumnConvention, &NamingColumnConventionAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLNamingColumnConvention, &NamingColumnConventionAdvisor{})
}
// NamingColumnConventionAdvisor is the advisor checking for column naming convention.
diff --git a/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go b/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
index 3403938f7f..c86c8f7704 100644
--- a/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
+++ b/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
@@ -5,6 +5,7 @@ import (
"strings"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -14,8 +15,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLNamingFKConvention, &NamingFKConventionAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLNamingFKConvention, &NamingFKConventionAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLNamingFKConvention, &NamingFKConventionAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLNamingFKConvention, &NamingFKConventionAdvisor{})
}
// NamingFKConventionAdvisor is the advisor checking for foreign key naming convention.
diff --git a/plugin/advisor/mysql/advisor_naming_index_convention.go b/plugin/advisor/mysql/advisor_naming_index_convention.go
index d2f7281a71..a52e9b8855 100644
--- a/plugin/advisor/mysql/advisor_naming_index_convention.go
+++ b/plugin/advisor/mysql/advisor_naming_index_convention.go
@@ -7,6 +7,7 @@ import (
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -16,8 +17,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLNamingIndexConvention, &NamingIndexConventionAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLNamingIndexConvention, &NamingIndexConventionAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLNamingIndexConvention, &NamingIndexConventionAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLNamingIndexConvention, &NamingIndexConventionAdvisor{})
}
// NamingIndexConventionAdvisor is the advisor checking for index naming convention.
diff --git a/plugin/advisor/mysql/advisor_naming_table.go b/plugin/advisor/mysql/advisor_naming_table.go
index 50c353a59f..21ac5f5120 100644
--- a/plugin/advisor/mysql/advisor_naming_table.go
+++ b/plugin/advisor/mysql/advisor_naming_table.go
@@ -5,6 +5,7 @@ import (
"regexp"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -14,8 +15,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLNamingTableConvention, &NamingTableConventionAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLNamingTableConvention, &NamingTableConventionAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLNamingTableConvention, &NamingTableConventionAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLNamingTableConvention, &NamingTableConventionAdvisor{})
}
// NamingTableConventionAdvisor is the advisor checking for table naming convention.
diff --git a/plugin/advisor/mysql/advisor_naming_unique_key_convention.go b/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
index 14691f410b..c524340fb2 100644
--- a/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
+++ b/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
@@ -6,6 +6,7 @@ import (
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -15,8 +16,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLNamingUKConvention, &NamingUKConventionAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLNamingUKConvention, &NamingUKConventionAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLNamingUKConvention, &NamingUKConventionAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLNamingUKConvention, &NamingUKConventionAdvisor{})
}
// NamingUKConventionAdvisor is the advisor checking for unique key naming convention.
diff --git a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go b/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go
index 9bf4ab2aa2..8f19ae180e 100644
--- a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go
+++ b/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/format"
)
@@ -18,8 +19,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLNoLeadingWildcardLike, &NoLeadingWildcardLikeAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLNoLeadingWildcardLike, &NoLeadingWildcardLikeAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLNoLeadingWildcardLike, &NoLeadingWildcardLikeAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLNoLeadingWildcardLike, &NoLeadingWildcardLikeAdvisor{})
}
// NoLeadingWildcardLikeAdvisor is the advisor checking for no leading wildcard LIKE.
diff --git a/plugin/advisor/mysql/advisor_stmt_no_select_all.go b/plugin/advisor/mysql/advisor_stmt_no_select_all.go
index 109750105e..245302922f 100644
--- a/plugin/advisor/mysql/advisor_stmt_no_select_all.go
+++ b/plugin/advisor/mysql/advisor_stmt_no_select_all.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -13,8 +14,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLNoSelectAll, &NoSelectAllAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLNoSelectAll, &NoSelectAllAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLNoSelectAll, &NoSelectAllAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLNoSelectAll, &NoSelectAllAdvisor{})
}
// NoSelectAllAdvisor is the advisor checking for no "select *".
diff --git a/plugin/advisor/mysql/advisor_stmt_where_required.go b/plugin/advisor/mysql/advisor_stmt_where_required.go
index dc48f25842..e41647df86 100644
--- a/plugin/advisor/mysql/advisor_stmt_where_required.go
+++ b/plugin/advisor/mysql/advisor_stmt_where_required.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -14,8 +15,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLWhereRequirement, &WhereRequirementAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLWhereRequirement, &WhereRequirementAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLWhereRequirement, &WhereRequirementAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLWhereRequirement, &WhereRequirementAdvisor{})
}
// WhereRequirementAdvisor is the advisor checking for the WHERE clause requirement.
diff --git a/plugin/advisor/mysql/advisor_syntax.go b/plugin/advisor/mysql/advisor_syntax.go
index bb43355144..6f2a883a99 100644
--- a/plugin/advisor/mysql/advisor_syntax.go
+++ b/plugin/advisor/mysql/advisor_syntax.go
@@ -2,6 +2,7 @@ package mysql
import (
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
)
var (
@@ -9,8 +10,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLSyntax, &SyntaxAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLSyntax, &SyntaxAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLSyntax, &SyntaxAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLSyntax, &SyntaxAdvisor{})
}
// SyntaxAdvisor is the advisor for checking syntax.
diff --git a/plugin/advisor/mysql/advisor_table_drop_naming_convention.go b/plugin/advisor/mysql/advisor_table_drop_naming_convention.go
index 1b56609dd5..c54e6a0aaf 100644
--- a/plugin/advisor/mysql/advisor_table_drop_naming_convention.go
+++ b/plugin/advisor/mysql/advisor_table_drop_naming_convention.go
@@ -5,6 +5,7 @@ import (
"regexp"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -14,8 +15,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLTableDropNamingConvention, &TableDropNamingConventionAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLTableDropNamingConvention, &TableDropNamingConventionAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLTableDropNamingConvention, &TableDropNamingConventionAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLTableDropNamingConvention, &TableDropNamingConventionAdvisor{})
}
// TableDropNamingConventionAdvisor is the advisor checking the MySQLTableDropNamingConvention rule.
diff --git a/plugin/advisor/mysql/advisor_table_no_fk.go b/plugin/advisor/mysql/advisor_table_no_fk.go
index c977ece836..a99069927d 100644
--- a/plugin/advisor/mysql/advisor_table_no_fk.go
+++ b/plugin/advisor/mysql/advisor_table_no_fk.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -13,8 +14,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLTableNoFK, &TableNoFKAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLTableNoFK, &TableNoFKAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLTableNoFK, &TableNoFKAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLTableNoFK, &TableNoFKAdvisor{})
}
// TableNoFKAdvisor is the advisor checking table disallow foreign key.
diff --git a/plugin/advisor/mysql/advisor_table_require_pk.go b/plugin/advisor/mysql/advisor_table_require_pk.go
index 1d877ab2d0..e20e4c8de9 100644
--- a/plugin/advisor/mysql/advisor_table_require_pk.go
+++ b/plugin/advisor/mysql/advisor_table_require_pk.go
@@ -6,6 +6,7 @@ import (
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
)
@@ -19,8 +20,8 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLTableRequirePK, &TableRequirePKAdvisor{})
- advisor.Register(advisor.TiDB, advisor.MySQLTableRequirePK, &TableRequirePKAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLTableRequirePK, &TableRequirePKAdvisor{})
+ advisor.Register(db.TiDB, advisor.MySQLTableRequirePK, &TableRequirePKAdvisor{})
}
// TableRequirePKAdvisor is the advisor checking table requires PK.
diff --git a/plugin/advisor/mysql/advisor_use_innodb.go b/plugin/advisor/mysql/advisor_use_innodb.go
index 2ee2e3e905..be4884f071 100644
--- a/plugin/advisor/mysql/advisor_use_innodb.go
+++ b/plugin/advisor/mysql/advisor_use_innodb.go
@@ -5,6 +5,7 @@ import (
"strings"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/format"
)
@@ -20,7 +21,7 @@ var (
)
func init() {
- advisor.Register(advisor.MySQL, advisor.MySQLUseInnoDB, &UseInnoDBAdvisor{})
+ advisor.Register(db.MySQL, advisor.MySQLUseInnoDB, &UseInnoDBAdvisor{})
}
// UseInnoDBAdvisor is the advisor checking for using InnoDB engine.
diff --git a/plugin/advisor/pg/advisor_column_no_null.go b/plugin/advisor/pg/advisor_column_no_null.go
index ae49e4cff5..231ed97f4f 100644
--- a/plugin/advisor/pg/advisor_column_no_null.go
+++ b/plugin/advisor/pg/advisor_column_no_null.go
@@ -6,6 +6,7 @@ import (
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -15,7 +16,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLColumnNoNull, &ColumnNoNullAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLColumnNoNull, &ColumnNoNullAdvisor{})
}
// ColumnNoNullAdvisor is the advisor checking for column no NULL value.
diff --git a/plugin/advisor/pg/advisor_column_required.go b/plugin/advisor/pg/advisor_column_required.go
index 867f1f49e1..a63ecebcf0 100644
--- a/plugin/advisor/pg/advisor_column_required.go
+++ b/plugin/advisor/pg/advisor_column_required.go
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -15,7 +16,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLColumnRequirement, &ColumnRequirementAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLColumnRequirement, &ColumnRequirementAdvisor{})
}
type columnSet map[string]bool
diff --git a/plugin/advisor/pg/advisor_migration_compatibility.go b/plugin/advisor/pg/advisor_migration_compatibility.go
index 2e3ecba695..f667fd372d 100644
--- a/plugin/advisor/pg/advisor_migration_compatibility.go
+++ b/plugin/advisor/pg/advisor_migration_compatibility.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -13,7 +14,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLMigrationCompatibility, &CompatibilityAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLMigrationCompatibility, &CompatibilityAdvisor{})
}
// CompatibilityAdvisor is the advisor checking for schema backward compatibility.
diff --git a/plugin/advisor/pg/advisor_naming_column.go b/plugin/advisor/pg/advisor_naming_column.go
index f31fb77a18..96be31115a 100644
--- a/plugin/advisor/pg/advisor_naming_column.go
+++ b/plugin/advisor/pg/advisor_naming_column.go
@@ -5,6 +5,7 @@ import (
"regexp"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -14,7 +15,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLNamingColumnConvention, &NamingColumnConventionAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLNamingColumnConvention, &NamingColumnConventionAdvisor{})
}
// NamingColumnConventionAdvisor is the advisor checking for column convention.
diff --git a/plugin/advisor/pg/advisor_naming_foreign_key_convention.go b/plugin/advisor/pg/advisor_naming_foreign_key_convention.go
index fa9590cda3..12869095df 100644
--- a/plugin/advisor/pg/advisor_naming_foreign_key_convention.go
+++ b/plugin/advisor/pg/advisor_naming_foreign_key_convention.go
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -15,7 +16,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLNamingFKConvention, &NamingFKConventionAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLNamingFKConvention, &NamingFKConventionAdvisor{})
}
// NamingFKConventionAdvisor is the advisor checking for foreign key naming convention.
diff --git a/plugin/advisor/pg/advisor_naming_index_convention.go b/plugin/advisor/pg/advisor_naming_index_convention.go
index c20ec197e4..efc1a1f9e0 100644
--- a/plugin/advisor/pg/advisor_naming_index_convention.go
+++ b/plugin/advisor/pg/advisor_naming_index_convention.go
@@ -6,6 +6,7 @@ import (
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -15,7 +16,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLNamingIndexConvention, &NamingColumnConventionAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLNamingIndexConvention, &NamingColumnConventionAdvisor{})
}
// NamingIndexConventionAdvisor is the advisor checking for index naming convention.
diff --git a/plugin/advisor/pg/advisor_naming_primary_key_convention.go b/plugin/advisor/pg/advisor_naming_primary_key_convention.go
index 72125582f2..e3d56c7c5a 100644
--- a/plugin/advisor/pg/advisor_naming_primary_key_convention.go
+++ b/plugin/advisor/pg/advisor_naming_primary_key_convention.go
@@ -6,6 +6,7 @@ import (
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -15,7 +16,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLNamingPKConvention, &NamingPKConventionAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLNamingPKConvention, &NamingPKConventionAdvisor{})
}
// NamingPKConventionAdvisor is the advisor checking for primary key naming convention.
diff --git a/plugin/advisor/pg/advisor_naming_table.go b/plugin/advisor/pg/advisor_naming_table.go
index 3046fdcc92..f726f67f6a 100644
--- a/plugin/advisor/pg/advisor_naming_table.go
+++ b/plugin/advisor/pg/advisor_naming_table.go
@@ -5,6 +5,7 @@ import (
"regexp"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -14,7 +15,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLNamingTableConvention, &NamingTableConventionAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLNamingTableConvention, &NamingTableConventionAdvisor{})
}
// NamingTableConventionAdvisor is the advisor checking for table naming convention.
diff --git a/plugin/advisor/pg/advisor_naming_unique_key_convention.go b/plugin/advisor/pg/advisor_naming_unique_key_convention.go
index c50714672e..a75eb696af 100644
--- a/plugin/advisor/pg/advisor_naming_unique_key_convention.go
+++ b/plugin/advisor/pg/advisor_naming_unique_key_convention.go
@@ -6,6 +6,7 @@ import (
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -15,7 +16,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLNamingUKConvention, &NamingUKConventionAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLNamingUKConvention, &NamingUKConventionAdvisor{})
}
// NamingUKConventionAdvisor is the advisor checking for unique key naming convention.
diff --git a/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go b/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go
index d04bad607f..2bdbb965e7 100644
--- a/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go
+++ b/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -17,7 +18,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLNoLeadingWildcardLike, &NoLeadingWildcardLikeAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLNoLeadingWildcardLike, &NoLeadingWildcardLikeAdvisor{})
}
// NoLeadingWildcardLikeAdvisor is the advisor checking for no leading wildcard LIKE.
diff --git a/plugin/advisor/pg/advisor_stmt_no_select_all.go b/plugin/advisor/pg/advisor_stmt_no_select_all.go
index 302c34b2f9..f5046ab431 100644
--- a/plugin/advisor/pg/advisor_stmt_no_select_all.go
+++ b/plugin/advisor/pg/advisor_stmt_no_select_all.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -13,7 +14,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLNoSelectAll, &NoSelectAllAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLNoSelectAll, &NoSelectAllAdvisor{})
}
// NoSelectAllAdvisor is the advisor checking for no "select *".
diff --git a/plugin/advisor/pg/advisor_stmt_where_required.go b/plugin/advisor/pg/advisor_stmt_where_required.go
index feeff8f358..8f5e51a01b 100644
--- a/plugin/advisor/pg/advisor_stmt_where_required.go
+++ b/plugin/advisor/pg/advisor_stmt_where_required.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -13,7 +14,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLWhereRequirement, &WhereRequirementAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLWhereRequirement, &WhereRequirementAdvisor{})
}
// WhereRequirementAdvisor is the advisor checking for the WHERE clause requirement.
diff --git a/plugin/advisor/pg/advisor_syntax.go b/plugin/advisor/pg/advisor_syntax.go
index 007792d110..40f20d691d 100644
--- a/plugin/advisor/pg/advisor_syntax.go
+++ b/plugin/advisor/pg/advisor_syntax.go
@@ -2,6 +2,7 @@ package pg
import (
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
)
var (
@@ -9,7 +10,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLSyntax, &SyntaxAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLSyntax, &SyntaxAdvisor{})
}
// SyntaxAdvisor is the advisor for checking syntax.
diff --git a/plugin/advisor/pg/advisor_table_require_pk.go b/plugin/advisor/pg/advisor_table_require_pk.go
index 5310ef8d0a..5e665f3395 100644
--- a/plugin/advisor/pg/advisor_table_require_pk.go
+++ b/plugin/advisor/pg/advisor_table_require_pk.go
@@ -5,6 +5,7 @@ import (
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/parser/ast"
)
@@ -14,7 +15,7 @@ var (
)
func init() {
- advisor.Register(advisor.Postgres, advisor.PostgreSQLTableRequirePK, &TableRequirePKAdvisor{})
+ advisor.Register(db.Postgres, advisor.PostgreSQLTableRequirePK, &TableRequirePKAdvisor{})
}
// TableRequirePKAdvisor is the advisor checking table requires PK.
diff --git a/plugin/advisor/sql_review.go b/plugin/advisor/sql_review.go
index 3bc8f4174e..9d98e46489 100644
--- a/plugin/advisor/sql_review.go
+++ b/plugin/advisor/sql_review.go
@@ -8,11 +8,12 @@ import (
"regexp"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
)
// How to add a schema review rule:
// 1. Implement an advisor.(plugin/advisor/mysql or plugin/advisor/pg)
-// 2. Register this advisor in map[DBType][AdvisorType].(plugin/advisor.go)
+// 2. Register this advisor in map[db.Type][AdvisorType].(plugin/advisor.go)
// 3. Add advisor error code if needed(plugin/advisor/code.go).
// 4. Map SQLReviewRuleType to advisor.Type in getAdvisorTypeByRule(current file).
@@ -256,7 +257,7 @@ func UnmarshalRequiredColumnRulePayload(payload string) (*RequiredColumnRulePayl
type SQLReviewCheckContext struct {
Charset string
Collation string
- DbType DBType
+ DbType db.Type
Catalog catalog.Catalog
}
@@ -311,46 +312,46 @@ func SchemaReviewCheck(statements string, ruleList []*SQLReviewRule, checkContex
return result, nil
}
-func getAdvisorTypeByRule(ruleType SQLReviewRuleType, engine DBType) (Type, error) {
+func getAdvisorTypeByRule(ruleType SQLReviewRuleType, engine db.Type) (Type, error) {
switch ruleType {
case SchemaRuleStatementRequireWhere:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLWhereRequirement, nil
case Postgres:
return PostgreSQLWhereRequirement, nil
}
case SchemaRuleStatementNoLeadingWildcardLike:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLNoLeadingWildcardLike, nil
case Postgres:
return PostgreSQLNoLeadingWildcardLike, nil
}
case SchemaRuleStatementNoSelectAll:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLNoSelectAll, nil
case Postgres:
return PostgreSQLNoSelectAll, nil
}
case SchemaRuleSchemaBackwardCompatibility:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLMigrationCompatibility, nil
case Postgres:
return PostgreSQLMigrationCompatibility, nil
}
case SchemaRuleTableNaming:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLNamingTableConvention, nil
- case Postgres:
+ case db.Postgres:
return PostgreSQLNamingTableConvention, nil
}
case SchemaRuleIDXNaming:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLNamingIndexConvention, nil
case Postgres:
return PostgreSQLNamingIndexConvention, nil
@@ -361,63 +362,63 @@ func getAdvisorTypeByRule(ruleType SQLReviewRuleType, engine DBType) (Type, erro
}
case SchemaRuleUKNaming:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLNamingUKConvention, nil
case Postgres:
return PostgreSQLNamingUKConvention, nil
}
case SchemaRuleFKNaming:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLNamingFKConvention, nil
- case Postgres:
+ case db.Postgres:
return PostgreSQLNamingFKConvention, nil
}
case SchemaRuleColumnNaming:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLNamingColumnConvention, nil
- case Postgres:
+ case db.Postgres:
return PostgreSQLNamingColumnConvention, nil
}
case SchemaRuleRequiredColumn:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLColumnRequirement, nil
- case Postgres:
+ case db.Postgres:
return PostgreSQLColumnRequirement, nil
}
case SchemaRuleColumnNotNull:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLColumnNoNull, nil
- case Postgres:
+ case db.Postgres:
return PostgreSQLColumnNoNull, nil
}
case SchemaRuleTableRequirePK:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLTableRequirePK, nil
case Postgres:
return PostgreSQLTableRequirePK, nil
}
case SchemaRuleTableNoFK:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLTableNoFK, nil
}
case SchemaRuleTableDropNamingConvention:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLTableDropNamingConvention, nil
}
case SchemaRuleMySQLEngine:
- if engine == MySQL {
+ if engine == db.MySQL {
return MySQLUseInnoDB, nil
}
case SchemaRuleDropEmptyDatabase:
switch engine {
- case MySQL, TiDB:
+ case db.MySQL, db.TiDB:
return MySQLDatabaseAllowDropIfEmpty, nil
}
}
diff --git a/plugin/advisor/utils_for_tests.go b/plugin/advisor/utils_for_tests.go
index 273ac31eae..d866b8c6de 100644
--- a/plugin/advisor/utils_for_tests.go
+++ b/plugin/advisor/utils_for_tests.go
@@ -6,6 +6,7 @@ import (
"time"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -29,7 +30,7 @@ var (
// MockMySQLDatabase is the mock MySQL database for test.
MockMySQLDatabase = &catalog.Database{
Name: "test",
- DbType: catalog.MySQL,
+ DbType: db.MySQL,
SchemaList: []*catalog.Schema{
{
TableList: []*catalog.Table{
@@ -64,7 +65,7 @@ var (
// MockPostgreSQLDatabase is the mock PostgreSQL database for test.
MockPostgreSQLDatabase = &catalog.Database{
Name: "test",
- DbType: catalog.Postgres,
+ DbType: db.Postgres,
SchemaList: []*catalog.Schema{
{
Name: "public",
diff --git a/server/openapi.go b/server/openapi.go
index abd245e794..bb44ce5ec6 100644
--- a/server/openapi.go
+++ b/server/openapi.go
@@ -4,12 +4,11 @@ import (
"context"
"fmt"
"net/http"
- "strings"
"github.com/bytebase/bytebase/api"
metricAPI "github.com/bytebase/bytebase/metric"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
- "github.com/bytebase/bytebase/plugin/db"
+ advisorDB "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/metric"
"github.com/bytebase/bytebase/store"
"github.com/labstack/echo/v4"
@@ -40,7 +39,7 @@ func (s *Server) registerOpenAPIRoutes(g *echo.Group) {
// @Produce json
// @Param environment query string true "The environment name. Case sensitive."
// @Param statement query string true "The SQL statement."
-// @Param databaseType query string false "The database type. Required if the port, host and database name is not specified." Enums(MySQL, PostgreSQL, TiDB)
+// @Param databaseType query string false "The database type. Required if the port, host and database name is not specified." Enums(MYSQL, POSTGRES, TIDB)
// @Param host query string false "The instance host."
// @Param port query string false "The instance port."
// @Param databaseName query string false "The database name in the instance."
@@ -60,7 +59,7 @@ func (s *Server) sqlCheckController(c echo.Context) error {
}
ctx := c.Request().Context()
- var dbType db.Type
+ var databaseType string
var catalog catalog.Catalog = &catalogService{}
databaseName := c.QueryParams().Get("databaseName")
@@ -72,19 +71,19 @@ func (s *Server) sqlCheckController(c echo.Context) error {
if err != nil {
return err
}
- dbType = database.Instance.Engine
+ dbType := database.Instance.Engine
+ databaseType = string(dbType)
catalog = store.NewCatalog(&database.ID, s.store, dbType)
} else {
- databaseType := c.QueryParams().Get("databaseType")
+ databaseType = c.QueryParams().Get("databaseType")
if databaseType == "" {
return echo.NewHTTPError(http.StatusBadRequest, "Missing required database type")
}
- dbType = db.Type(strings.ToUpper(databaseType))
}
- advisorDBType, err := api.ConvertToAdvisorDBType(dbType)
+ advisorDBType, err := advisorDB.ConvertToAdvisorDBType(databaseType)
if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Database %s is not support", dbType))
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Database %s is not support", databaseType))
}
envList, err := s.store.FindEnvironment(ctx, &api.EnvironmentFind{
@@ -115,7 +114,7 @@ func (s *Server) sqlCheckController(c echo.Context) error {
Name: metricAPI.SQLAdviseAPIMetricName,
Value: 1,
Labels: map[string]string{
- "database_type": string(dbType),
+ "database_type": databaseType,
"environment": envName,
},
})
diff --git a/server/sql.go b/server/sql.go
index bd210a2866..b7ed1c54a3 100644
--- a/server/sql.go
+++ b/server/sql.go
@@ -19,6 +19,7 @@ import (
"github.com/bytebase/bytebase/common/log"
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ advisorDB "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/db"
"github.com/bytebase/bytebase/plugin/db/util"
"github.com/bytebase/bytebase/store"
@@ -179,7 +180,7 @@ func (s *Server) registerSQLRoutes(g *echo.Group) {
adviceList := []advisor.Advice{}
if s.feature(api.FeatureSQLReviewPolicy) && api.IsSQLReviewSupported(instance.Engine, s.profile.Mode) {
- dbType, err := api.ConvertToAdvisorDBType(instance.Engine)
+ dbType, err := advisorDB.ConvertToAdvisorDBType(string(instance.Engine))
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to convert db type %v into advisor db type", instance.Engine))
}
@@ -648,7 +649,7 @@ func (s *Server) createSQLEditorQueryActivity(ctx context.Context, c echo.Contex
func (s *Server) sqlCheck(
ctx context.Context,
- dbType advisor.DBType,
+ dbType advisorDB.Type,
dbCharacterSet string,
dbCollation string,
environmentID int,
diff --git a/server/task_check_executor_statement_advisor_composite.go b/server/task_check_executor_statement_advisor_composite.go
index 536ecee960..a2dd34871e 100644
--- a/server/task_check_executor_statement_advisor_composite.go
+++ b/server/task_check_executor_statement_advisor_composite.go
@@ -7,6 +7,7 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/plugin/advisor"
+ advisorDB "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/store"
)
@@ -62,7 +63,7 @@ func (*TaskCheckStatementAdvisorCompositeExecutor) Run(ctx context.Context, serv
catalog := store.NewCatalog(task.DatabaseID, server.store, payload.DbType)
- dbType, err := api.ConvertToAdvisorDBType(payload.DbType)
+ dbType, err := advisorDB.ConvertToAdvisorDBType(string(payload.DbType))
if err != nil {
return nil, err
}
diff --git a/server/task_check_executor_statement_advisor_simple.go b/server/task_check_executor_statement_advisor_simple.go
index 170b358ed0..f9d8166f10 100644
--- a/server/task_check_executor_statement_advisor_simple.go
+++ b/server/task_check_executor_statement_advisor_simple.go
@@ -7,6 +7,7 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/plugin/advisor"
+ advisorDB "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/db"
)
@@ -41,7 +42,7 @@ func (*TaskCheckStatementAdvisorSimpleExecutor) Run(_ context.Context, _ *Server
}
}
- dbType, err := api.ConvertToAdvisorDBType(payload.DbType)
+ dbType, err := advisorDB.ConvertToAdvisorDBType(string(payload.DbType))
if err != nil {
return nil, err
}
diff --git a/sql-server/advise.go b/sql-server/advise.go
index eb0bbc8b6b..fee31827ce 100644
--- a/sql-server/advise.go
+++ b/sql-server/advise.go
@@ -4,10 +4,10 @@ import (
"context"
"fmt"
"net/http"
- "strings"
"github.com/bytebase/bytebase/plugin/advisor"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ advisorDB "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/labstack/echo/v4"
"gopkg.in/yaml.v3"
)
@@ -36,7 +36,7 @@ func (s *Server) registerAdvisorRoutes(g *echo.Group) {
// @Tags Schema Review
// @Produce json
// @Param statement query string true "The SQL statement."
-// @Param databaseType query string true "The database type." Enums(MySQL, PostgreSQL, TiDB)
+// @Param databaseType query string true "The database type." Enums(MYSQL, POSTGRES, TIDB)
// @Param template query string false "The SQL check template id. Required if the config is not specified." Enums(bb.sql-review.mysql.prod, bb.sql-review.mysql.dev)
// @Param override query string false "The SQL check config override string in YAML format. Check https://github.com/bytebase/bytebase/tree/main/plugin/advisor/config/sql-review.override.yaml for example. Required if the template is not specified."
// @Success 200 {array} advisor.Advice
@@ -53,7 +53,7 @@ func (*Server) sqlCheckController(c echo.Context) error {
if databaseType == "" {
return echo.NewHTTPError(http.StatusBadRequest, "Missing required database type")
}
- advisorDBType, err := convertToAdvisorDBType(strings.ToUpper(databaseType))
+ advisorDBType, err := advisorDB.ConvertToAdvisorDBType(databaseType)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Database %s is not support", databaseType))
}
@@ -96,21 +96,8 @@ func (*Server) sqlCheckController(c echo.Context) error {
return c.JSON(http.StatusOK, adviceList)
}
-func convertToAdvisorDBType(dbType string) (advisor.DBType, error) {
- switch dbType {
- case string(advisor.MySQL):
- return advisor.MySQL, nil
- case string(advisor.Postgres):
- return advisor.Postgres, nil
- case string(advisor.TiDB):
- return advisor.TiDB, nil
- }
-
- return "", fmt.Errorf("unsupported db type %s for advisor", dbType)
-}
-
func sqlCheck(
- dbType advisor.DBType,
+ dbType advisorDB.Type,
dbCharacterSet string,
dbCollation string,
statement string,
diff --git a/store/catalog.go b/store/catalog.go
index b05eb4e4d0..8cbcb4ba38 100644
--- a/store/catalog.go
+++ b/store/catalog.go
@@ -8,6 +8,7 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/plugin/advisor/catalog"
+ advisorDB "github.com/bytebase/bytebase/plugin/advisor/db"
"github.com/bytebase/bytebase/plugin/db"
)
@@ -43,7 +44,7 @@ func (c *Catalog) GetDatabase(ctx context.Context) (*catalog.Database, error) {
return nil, nil
}
- dbType, err := convertToCatalogDBType(c.engineType)
+ dbType, err := advisorDB.ConvertToAdvisorDBType(string(c.engineType))
if err != nil {
return nil, err
}
@@ -234,16 +235,3 @@ func convertColumnList(list []*api.Column) []*catalog.Column {
}
return res
}
-
-func convertToCatalogDBType(dbType db.Type) (catalog.DBType, error) {
- switch dbType {
- case db.MySQL:
- return catalog.MySQL, nil
- case db.Postgres:
- return catalog.Postgres, nil
- case db.TiDB:
- return catalog.TiDB, nil
- }
-
- return "", fmt.Errorf("unsupported db type %s for catalog", dbType)
-}