Skip to content

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

refactor: move position help function to common package (#15822)

h3n4la3c3d3211021
diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml
index 4cd04bf881..9bc3a3a726 100644
--- a/.github/workflows/golangci-lint.yml
+++ b/.github/workflows/golangci-lint.yml
@@ -9,6 +9,7 @@ on:
- 'backend/**'
- 'go.mod'
- 'proto/**/*.go'
+ - '.golangci.yaml'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
diff --git a/.golangci.yaml b/.golangci.yaml
index fd609209a4..956bb8a3b4 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -17,9 +17,12 @@ linters:
explicit-exhaustive-switch: true
forbidigo:
forbid:
- - pattern: fmt\.Errorf(# Please use errors\.Wrap\|Wrapf\|Errorf instead)?
- - pattern: ioutil\.ReadDir(# Please use os\.ReadDir)?
+ - pattern: fmt\.Errorf
+ msg: Please use errors\.Wrap\|Wrapf\|Errorf instead
+ - pattern: ioutil\.ReadDir
+ msg: Please use os\.ReadDir instead
- pattern: protojson\.Unmarshal?
+ msg: Please use ProtojsonUnmarshaler instead
gocritic:
disabled-checks:
- ifElseChain
diff --git a/backend/common/position.go b/backend/common/position.go
index e528c619c0..14963574e3 100644
--- a/backend/common/position.go
+++ b/backend/common/position.go
@@ -6,6 +6,12 @@ import (
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
+var (
+ FirstLinePosition = &storepb.Position{
+ Line: 0,
+ }
+)
+
// ANTLRPosition is a position in a text expressed as one-based line and
// zero-based column character (code point) offset integrated with ANTLR4.
type ANTLRPosition struct {
@@ -100,3 +106,13 @@ func ConvertANTLRPositionToPosition(a *ANTLRPosition, text string) *storepb.Posi
Column: byteOffset,
}
}
+
+func ConvertANTLRLineToPosition(line int) *storepb.Position {
+ positionLine := line - 1
+ if line == 0 {
+ positionLine = 0
+ }
+ return &storepb.Position{
+ Line: int32(positionLine),
+ }
+}
diff --git a/backend/component/sheet/sheet.go b/backend/component/sheet/sheet.go
index 0d439e00d4..20094f6043 100644
--- a/backend/component/sheet/sheet.go
+++ b/backend/component/sheet/sheet.go
@@ -243,13 +243,11 @@ func syntaxCheck(dbType storepb.Engine, statement string) (any, []*storepb.Advic
}
return nil, []*storepb.Advice{
{
- Status: storepb.Advice_ERROR,
- Code: InternalErrorCode,
- Title: "Unsupported database type",
- Content: fmt.Sprintf("Unsupported database type %s", dbType),
- StartPosition: &storepb.Position{
- Line: 1,
- },
+ Status: storepb.Advice_ERROR,
+ Code: InternalErrorCode,
+ Title: "Unsupported database type",
+ Content: fmt.Sprintf("Unsupported database type %s", dbType),
+ StartPosition: common.FirstLinePosition,
},
}
}
@@ -259,13 +257,11 @@ func cockroachdbSyntaxCheck(statement string) (any, []*storepb.Advice) {
if err != nil {
return nil, []*storepb.Advice{
{
- Status: storepb.Advice_WARNING,
- Code: InternalErrorCode,
- Title: "Parse error",
- Content: err.Error(),
- StartPosition: &storepb.Position{
- Line: 1,
- },
+ Status: storepb.Advice_WARNING,
+ Code: InternalErrorCode,
+ Title: "Parse error",
+ Content: err.Error(),
+ StartPosition: common.FirstLinePosition,
},
}
}
@@ -295,13 +291,11 @@ func partiqlSyntaxCheck(statement string) (any, []*storepb.Advice) {
}
return nil, []*storepb.Advice{
{
- Status: storepb.Advice_WARNING,
- Code: InternalErrorCode,
- Title: "Parse error",
- Content: err.Error(),
- StartPosition: &storepb.Position{
- Line: 1,
- },
+ Status: storepb.Advice_WARNING,
+ Code: InternalErrorCode,
+ Title: "Parse error",
+ Content: err.Error(),
+ StartPosition: common.FirstLinePosition,
},
}
}
@@ -331,13 +325,11 @@ func mssqlSyntaxCheck(statement string) (any, []*storepb.Advice) {
}
return nil, []*storepb.Advice{
{
- Status: storepb.Advice_WARNING,
- Code: InternalErrorCode,
- Title: "Parse error",
- Content: err.Error(),
- StartPosition: &storepb.Position{
- Line: 1,
- },
+ Status: storepb.Advice_WARNING,
+ Code: InternalErrorCode,
+ Title: "Parse error",
+ Content: err.Error(),
+ StartPosition: common.FirstLinePosition,
},
}
}
@@ -367,13 +359,11 @@ func snowflakeSyntaxCheck(statement string) (any, []*storepb.Advice) {
}
return nil, []*storepb.Advice{
{
- Status: storepb.Advice_WARNING,
- Code: InternalErrorCode,
- Title: "Parse error",
- Content: err.Error(),
- StartPosition: &storepb.Position{
- Line: 1,
- },
+ Status: storepb.Advice_WARNING,
+ Code: InternalErrorCode,
+ Title: "Parse error",
+ Content: err.Error(),
+ StartPosition: common.FirstLinePosition,
},
}
}
@@ -402,13 +392,11 @@ func oracleSyntaxCheck(statement string) (any, []*storepb.Advice) {
}
return nil, []*storepb.Advice{
{
- Status: storepb.Advice_WARNING,
- Code: InternalErrorCode,
- Title: "Parse error",
- Content: err.Error(),
- StartPosition: &storepb.Position{
- Line: 1,
- },
+ Status: storepb.Advice_WARNING,
+ Code: InternalErrorCode,
+ Title: "Parse error",
+ Content: err.Error(),
+ StartPosition: common.FirstLinePosition,
},
}
}
@@ -497,13 +485,11 @@ func mysqlSyntaxCheck(statement string) (any, []*storepb.Advice) {
}
return nil, []*storepb.Advice{
{
- Status: storepb.Advice_ERROR,
- Code: InternalErrorCode,
- Title: "Parse error",
- Content: err.Error(),
- StartPosition: &storepb.Position{
- Line: 1,
- },
+ Status: storepb.Advice_ERROR,
+ Code: InternalErrorCode,
+ Title: "Parse error",
+ Content: err.Error(),
+ StartPosition: common.FirstLinePosition,
},
}
}
@@ -534,13 +520,11 @@ func tidbSyntaxCheck(statement string) (any, []*storepb.Advice) {
if err != nil {
return nil, []*storepb.Advice{
{
- Status: storepb.Advice_WARNING,
- Code: InternalErrorCode,
- Title: "Syntax error",
- Content: err.Error(),
- StartPosition: &storepb.Position{
- Line: 1,
- },
+ Status: storepb.Advice_WARNING,
+ Code: InternalErrorCode,
+ Title: "Syntax error",
+ Content: err.Error(),
+ StartPosition: common.FirstLinePosition,
},
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_builtin_prior_backup_check.go b/backend/plugin/advisor/mssql/advisor_builtin_prior_backup_check.go
index 47411ebe8e..109472d8ef 100644
--- a/backend/plugin/advisor/mssql/advisor_builtin_prior_backup_check.go
+++ b/backend/plugin/advisor/mssql/advisor_builtin_prior_backup_check.go
@@ -56,7 +56,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("The size of statements in the sheet exceeds the limit of %d", common.MaxSheetCheckSize),
Code: advisor.BuiltinPriorBackupCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(1),
+ StartPosition: common.ConvertANTLRLineToPosition(1),
})
}
@@ -67,7 +67,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Need database %q to do prior backup but it does not exist", checkCtx.PreUpdateBackupDetail.Database),
Code: advisor.DatabaseNotExists.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(1),
+ StartPosition: common.ConvertANTLRLineToPosition(1),
})
return adviceList, nil
}
@@ -81,7 +81,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: "Prior backup cannot deal with mixed DDL and DML statements",
Code: int32(advisor.BuiltinPriorBackupCheck),
- StartPosition: advisor.ConvertANTLRLineToPosition(1),
+ StartPosition: common.ConvertANTLRLineToPosition(1),
})
}
@@ -109,7 +109,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
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(),
- StartPosition: advisor.ConvertANTLRLineToPosition(1),
+ StartPosition: common.ConvertANTLRLineToPosition(1),
})
break
}
diff --git a/backend/plugin/advisor/mssql/advisor_column_maximum_varchar_length.go b/backend/plugin/advisor/mssql/advisor_column_maximum_varchar_length.go
index ff49f22018..748a63084a 100644
--- a/backend/plugin/advisor/mssql/advisor_column_maximum_varchar_length.go
+++ b/backend/plugin/advisor/mssql/advisor_column_maximum_varchar_length.go
@@ -12,6 +12,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
@@ -113,7 +114,7 @@ func (l *columnMaximumVarcharLengthChecker) EnterData_type(ctx *parser.Data_type
Code: advisor.VarcharLengthExceedsLimit.Int32(),
Title: l.title,
Content: fmt.Sprintf("The maximum varchar length is %d.", l.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_column_no_null.go b/backend/plugin/advisor/mssql/advisor_column_no_null.go
index 323d39f15e..f5f01f0067 100644
--- a/backend/plugin/advisor/mssql/advisor_column_no_null.go
+++ b/backend/plugin/advisor/mssql/advisor_column_no_null.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -96,7 +97,7 @@ func (l *columnNoNullChecker) ExitCreate_table(_ *parser.Create_tableContext) {
Code: advisor.ColumnCannotNull.Int32(),
Title: l.title,
Content: fmt.Sprintf("Column [%s] is nullable, which is not allowed.", columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.currentTableColumnIsNullableLine[columnName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.currentTableColumnIsNullableLine[columnName]),
})
}
@@ -172,7 +173,7 @@ func (l *columnNoNullChecker) ExitAlter_table(_ *parser.Alter_tableContext) {
Code: advisor.ColumnCannotNull.Int32(),
Title: l.title,
Content: fmt.Sprintf("Column [%s] is nullable, which is not allowed.", columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.currentTableColumnIsNullableLine[columnName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.currentTableColumnIsNullableLine[columnName]),
})
}
diff --git a/backend/plugin/advisor/mssql/advisor_column_require.go b/backend/plugin/advisor/mssql/advisor_column_require.go
index bda44e2c74..5d052b4fc1 100644
--- a/backend/plugin/advisor/mssql/advisor_column_require.go
+++ b/backend/plugin/advisor/mssql/advisor_column_require.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -119,7 +120,7 @@ func (l *columnRequireChecker) ExitCreate_table(ctx *parser.Create_tableContext)
Code: advisor.NoRequiredColumn.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %s missing required column %q", l.currentOriginalTableName, column),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
@@ -142,7 +143,7 @@ func (l *columnRequireChecker) EnterAlter_table(ctx *parser.Alter_tableContext)
Code: advisor.NoRequiredColumn.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %s missing required column %q", tableName, normalizedColumnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_column_type_disallow_list.go b/backend/plugin/advisor/mssql/advisor_column_type_disallow_list.go
index 60481b6855..892d6b1e80 100644
--- a/backend/plugin/advisor/mssql/advisor_column_type_disallow_list.go
+++ b/backend/plugin/advisor/mssql/advisor_column_type_disallow_list.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -72,7 +73,7 @@ func (checker *columnTypeDisallowListChecker) EnterData_type(ctx *parser.Data_ty
Code: advisor.DisabledColumnType.Int32(),
Title: checker.title,
Content: "Column type " + formatedDataType + " is disallowed",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_function_disallow_create_or_alter.go b/backend/plugin/advisor/mssql/advisor_function_disallow_create_or_alter.go
index c992f0c4ad..2e080980cd 100644
--- a/backend/plugin/advisor/mssql/advisor_function_disallow_create_or_alter.go
+++ b/backend/plugin/advisor/mssql/advisor_function_disallow_create_or_alter.go
@@ -7,6 +7,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -53,6 +54,6 @@ func (checker *FunctionDisallowCreateOrAlterChecker) EnterCreate_or_alter_functi
Code: advisor.DisallowCreateFunction.Int32(),
Title: checker.title,
Content: "Creating or altering functions is prohibited",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
diff --git a/backend/plugin/advisor/mssql/advisor_index_not_redundant.go b/backend/plugin/advisor/mssql/advisor_index_not_redundant.go
index d305d0a5a5..5f8522c9f6 100644
--- a/backend/plugin/advisor/mssql/advisor_index_not_redundant.go
+++ b/backend/plugin/advisor/mssql/advisor_index_not_redundant.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/tsql"
@@ -100,7 +101,7 @@ func (checker *IndexNotRedundantChecker) EnterCreate_index(ctx *parser.Create_in
Code: advisor.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: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_migration_compatibility.go b/backend/plugin/advisor/mssql/advisor_migration_compatibility.go
index a963a66e4f..f3a8defbe0 100644
--- a/backend/plugin/advisor/mssql/advisor_migration_compatibility.go
+++ b/backend/plugin/advisor/mssql/advisor_migration_compatibility.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -117,7 +118,7 @@ func (l *migrationCompatibilityChecker) EnterDrop_table(ctx *parser.Drop_tableCo
Code: advisor.CompatibilityDropSchema.Int32(),
Title: l.title,
Content: fmt.Sprintf("Drop table %s may cause incompatibility with the existing data and code", normalizedTableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
delete(l.normalizedNewCreateTableNameMap, normalizedTableName)
@@ -134,7 +135,7 @@ func (l *migrationCompatibilityChecker) EnterDrop_schema(ctx *parser.Drop_schema
Code: advisor.CompatibilityDropSchema.Int32(),
Title: l.title,
Content: fmt.Sprintf("Drop schema %s may cause incompatibility with the existing data and code", normalizedSchemaName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
delete(l.normalizedNewCreateSchemaNameMap, normalizedSchemaName)
@@ -149,7 +150,7 @@ func (l *migrationCompatibilityChecker) EnterDrop_database(ctx *parser.Drop_data
Code: advisor.CompatibilityDropSchema.Int32(),
Title: l.title,
Content: fmt.Sprintf("Drop database %s may cause incompatibility with the existing data and code", normalizedDatabaseName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
delete(l.normalizedNewCreateDatabaseNameMap, normalizedDatabaseName)
@@ -175,7 +176,7 @@ func (l *migrationCompatibilityChecker) EnterAlter_table(ctx *parser.Alter_table
Code: advisor.CompatibilityDropSchema.Int32(),
Title: l.title,
Content: fmt.Sprintf("Drop column %s may cause incompatibility with the existing data and code", placeholder),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.COLUMN().GetSymbol().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.COLUMN().GetSymbol().GetLine()),
})
return
}
@@ -192,7 +193,7 @@ func (l *migrationCompatibilityChecker) EnterAlter_table(ctx *parser.Alter_table
Code: advisor.CompatibilityAlterColumn.Int32(),
Title: l.title,
Content: fmt.Sprintf("Alter COLUMN %s may cause incompatibility with the existing data and code", normalizedColumnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.COLUMN().GetSymbol().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.COLUMN().GetSymbol().GetLine()),
})
return
}
@@ -222,7 +223,7 @@ func (l *migrationCompatibilityChecker) EnterAlter_table(ctx *parser.Alter_table
Code: code.Int32(),
Title: l.title,
Content: fmt.Sprintf("%s may cause incompatibility with the existing data and code", operation),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
return
@@ -234,7 +235,7 @@ func (l *migrationCompatibilityChecker) EnterAlter_table(ctx *parser.Alter_table
Code: advisor.CompatibilityAddForeignKey.Int32(),
Title: l.title,
Content: "Add FOREIGN KEY WITH NO CHECK may cause incompatibility with the existing data and code",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.FOREIGN().GetSymbol().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.FOREIGN().GetSymbol().GetLine()),
})
return
}
@@ -244,7 +245,7 @@ func (l *migrationCompatibilityChecker) EnterAlter_table(ctx *parser.Alter_table
Code: advisor.CompatibilityAddForeignKey.Int32(),
Title: l.title,
Content: "Add CHECK WITH NO CHECK may cause incompatibility with the existing data and code",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.CHECK(0).GetSymbol().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.CHECK(0).GetSymbol().GetLine()),
})
return
}
@@ -292,6 +293,6 @@ func (l *migrationCompatibilityChecker) EnterExecute_body(ctx *parser.Execute_bo
Code: advisor.CompatibilityRenameTable.Int32(),
Title: l.title,
Content: "sp_rename may cause incompatibility with the existing data and code, and break scripts and stored procedures.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
diff --git a/backend/plugin/advisor/mssql/advisor_naming_identifier_no_keyword.go b/backend/plugin/advisor/mssql/advisor_naming_identifier_no_keyword.go
index cee1c0be4b..f1744c55cb 100644
--- a/backend/plugin/advisor/mssql/advisor_naming_identifier_no_keyword.go
+++ b/backend/plugin/advisor/mssql/advisor_naming_identifier_no_keyword.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -91,7 +92,7 @@ func (l *namingIdentifierNoKeywordChecker) EnterId_(ctx *parser.Id_Context) {
Code: advisor.NameIsKeywordIdentifier.Int32(),
Title: l.title,
Content: fmt.Sprintf("Identifier [%s] is a keyword identifier and should be avoided.", normalizedID),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_naming_table.go b/backend/plugin/advisor/mssql/advisor_naming_table.go
index 4c43a05f98..5dcd27486b 100644
--- a/backend/plugin/advisor/mssql/advisor_naming_table.go
+++ b/backend/plugin/advisor/mssql/advisor_naming_table.go
@@ -12,6 +12,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -85,7 +86,7 @@ func (l *namingTableListener) EnterCreate_table(ctx *parser.Create_tableContext)
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf(`%s mismatches table naming convention, naming format should be %q`, tableName, l.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
if l.maxLength > 0 && len(tableName) > l.maxLength {
@@ -94,7 +95,7 @@ func (l *namingTableListener) EnterCreate_table(ctx *parser.Create_tableContext)
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf(`%s mismatches table naming convention, its length should be within %d characters`, tableName, l.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
@@ -168,7 +169,7 @@ func (l *namingTableListener) EnterExecute_body(ctx *parser.Execute_bodyContext)
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf(`%s mismatches table naming convention, naming format should be %q`, newTableName, l.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
if l.maxLength > 0 && len(newTableName) > l.maxLength {
@@ -177,7 +178,7 @@ func (l *namingTableListener) EnterExecute_body(ctx *parser.Execute_bodyContext)
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf(`%s mismatches table naming convention, its length should be within %d characters`, newTableName, l.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_naming_table_no_keyword.go b/backend/plugin/advisor/mssql/advisor_naming_table_no_keyword.go
index b9b733cbac..34be182ed9 100644
--- a/backend/plugin/advisor/mssql/advisor_naming_table_no_keyword.go
+++ b/backend/plugin/advisor/mssql/advisor_naming_table_no_keyword.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -73,7 +74,7 @@ func (l *namingTableNoKeywordChecker) EnterCreate_table(ctx *parser.Create_table
Code: advisor.NameIsKeywordIdentifier.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table name [%s] is a reserved keyword and should be avoided.", normalizedTableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(tableName.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(tableName.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_procedure_disallow_create_or_alter.go b/backend/plugin/advisor/mssql/advisor_procedure_disallow_create_or_alter.go
index 2fe8edd9d5..bf9522e293 100644
--- a/backend/plugin/advisor/mssql/advisor_procedure_disallow_create_or_alter.go
+++ b/backend/plugin/advisor/mssql/advisor_procedure_disallow_create_or_alter.go
@@ -7,6 +7,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -52,6 +53,6 @@ func (checker *ProcedureDisallowCreateOrAlterChecker) EnterCreate_or_alter_proce
Code: advisor.DisallowCreateProcedure.Int32(),
Title: checker.title,
Content: "Creating or altering procedures is prohibited",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
diff --git a/backend/plugin/advisor/mssql/advisor_select_no_select_all.go b/backend/plugin/advisor/mssql/advisor_select_no_select_all.go
index 8f12b12e13..3450cdb455 100644
--- a/backend/plugin/advisor/mssql/advisor_select_no_select_all.go
+++ b/backend/plugin/advisor/mssql/advisor_select_no_select_all.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -70,7 +71,7 @@ func (l *selectNoSelectAllChecker) EnterSelect_list_elem(ctx *parser.Select_list
Code: advisor.StatementSelectAll.Int32(),
Title: l.title,
Content: "Avoid using SELECT *.",
- StartPosition: advisor.ConvertANTLRLineToPosition(v.STAR().GetSymbol().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(v.STAR().GetSymbol().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_statement_disallow_cross_db_queries.go b/backend/plugin/advisor/mssql/advisor_statement_disallow_cross_db_queries.go
index 31ecef60ec..04f1f41ef2 100644
--- a/backend/plugin/advisor/mssql/advisor_statement_disallow_cross_db_queries.go
+++ b/backend/plugin/advisor/mssql/advisor_statement_disallow_cross_db_queries.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -59,7 +60,7 @@ func (checker *DisallowCrossDBQueriesChecker) EnterTable_source_item(ctx *parser
Code: advisor.StatementDisallowCrossDBQueries.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Cross database queries (target databse: '%s', current database: '%s') are prohibited", fullTblName.Database, checker.curDB),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
// Ignore internal error...
diff --git a/backend/plugin/advisor/mssql/advisor_statement_disallow_mix_in_ddl.go b/backend/plugin/advisor/mssql/advisor_statement_disallow_mix_in_ddl.go
index afe2f7a48e..2d46cae70c 100644
--- a/backend/plugin/advisor/mssql/advisor_statement_disallow_mix_in_ddl.go
+++ b/backend/plugin/advisor/mssql/advisor_statement_disallow_mix_in_ddl.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/tsql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -77,7 +78,7 @@ func (c *statementDisallowMixInDDLChecker) EnterSql_clauses(ctx *parser.Sql_clau
Title: c.title,
Content: "Alter schema can only run DDL",
Code: advisor.StatementDisallowMixDDLDML.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_statement_disallow_mix_in_dml.go b/backend/plugin/advisor/mssql/advisor_statement_disallow_mix_in_dml.go
index bf1ddd03cb..6dd582d08d 100644
--- a/backend/plugin/advisor/mssql/advisor_statement_disallow_mix_in_dml.go
+++ b/backend/plugin/advisor/mssql/advisor_statement_disallow_mix_in_dml.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/tsql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -77,7 +78,7 @@ func (c *statementDisallowMixInDMLChecker) EnterSql_clauses(ctx *parser.Sql_clau
Title: c.title,
Content: "Data change can only run DML",
Code: advisor.StatementDisallowMixDDLDML.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_statement_where_disallow_functions_and_calculations.go b/backend/plugin/advisor/mssql/advisor_statement_where_disallow_functions_and_calculations.go
index ca21e0653a..6e2d65bffb 100644
--- a/backend/plugin/advisor/mssql/advisor_statement_where_disallow_functions_and_calculations.go
+++ b/backend/plugin/advisor/mssql/advisor_statement_where_disallow_functions_and_calculations.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -70,7 +71,7 @@ func generateAdviceOnFunctionUsing(c *DisallowFuncAndCalculationsChecker, ctx an
Code: advisor.StatementDisallowFunctionsAndCalculations.Int32(),
Title: c.title,
Content: fmt.Sprintf("Calling function '%s' in 'WHERE' clause is not allowed", ctx.GetText()),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
}
}
@@ -84,7 +85,7 @@ func generateAdviceOnPerformingCalculations(c *DisallowFuncAndCalculationsChecke
Code: advisor.StatementDisallowFunctionsAndCalculations.Int32(),
Title: c.title,
Content: "Performing calculations in 'WHERE' clause is not allowed",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_statement_where_requirement_for_select.go b/backend/plugin/advisor/mssql/advisor_statement_where_requirement_for_select.go
index fe19797291..589f6f1305 100644
--- a/backend/plugin/advisor/mssql/advisor_statement_where_requirement_for_select.go
+++ b/backend/plugin/advisor/mssql/advisor_statement_where_requirement_for_select.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -70,7 +71,7 @@ func (l *whereRequirementForSelectChecker) EnterQuery_specification(ctx *parser.
Code: advisor.StatementNoWhere.Int32(),
Title: l.title,
Content: "WHERE clause is required for SELETE statement.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_statement_where_requirement_for_update_delete.go b/backend/plugin/advisor/mssql/advisor_statement_where_requirement_for_update_delete.go
index fade47ea03..346b072c7d 100644
--- a/backend/plugin/advisor/mssql/advisor_statement_where_requirement_for_update_delete.go
+++ b/backend/plugin/advisor/mssql/advisor_statement_where_requirement_for_update_delete.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -69,7 +70,7 @@ func (l *whereRequirementForUpdateDeleteChecker) EnterDelete_statement(ctx *pars
Code: advisor.StatementNoWhere.Int32(),
Title: l.title,
Content: "WHERE clause is required for DELETE statement.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
@@ -82,7 +83,7 @@ func (l *whereRequirementForUpdateDeleteChecker) EnterUpdate_statement(ctx *pars
Code: advisor.StatementNoWhere.Int32(),
Title: l.title,
Content: "WHERE clause is required for UPDATE statement.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_table_disallow_ddl.go b/backend/plugin/advisor/mssql/advisor_table_disallow_ddl.go
index 0b402c1723..f4e11fb3e4 100644
--- a/backend/plugin/advisor/mssql/advisor_table_disallow_ddl.go
+++ b/backend/plugin/advisor/mssql/advisor_table_disallow_ddl.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -106,7 +107,7 @@ func (checker *tableDisallowDDLChecker) checkTableName(normalizedTableName strin
Code: advisor.TableDisallowDDL.Int32(),
Title: checker.title,
Content: fmt.Sprintf("DDL is disallowed on table %s.", normalizedTableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
return
}
diff --git a/backend/plugin/advisor/mssql/advisor_table_disallow_dml.go b/backend/plugin/advisor/mssql/advisor_table_disallow_dml.go
index f260bc8bdb..23a604537f 100644
--- a/backend/plugin/advisor/mssql/advisor_table_disallow_dml.go
+++ b/backend/plugin/advisor/mssql/advisor_table_disallow_dml.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -113,7 +114,7 @@ func (checker *tableDisallowDMLChecker) checkTableName(normalizedTableName strin
Code: advisor.TableDisallowDML.Int32(),
Title: checker.title,
Content: fmt.Sprintf("DML is disallowed on table %s.", normalizedTableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
return
}
diff --git a/backend/plugin/advisor/mssql/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/mssql/advisor_table_drop_naming_convention.go
index 3727b070de..b6b5433d09 100644
--- a/backend/plugin/advisor/mssql/advisor_table_drop_naming_convention.go
+++ b/backend/plugin/advisor/mssql/advisor_table_drop_naming_convention.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -85,7 +86,7 @@ func (l *tableDropNamingConventionChecker) EnterDrop_table(ctx *parser.Drop_tabl
Code: advisor.TableDropNamingConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf("[%s] mismatches drop table naming convention, naming format should be %q", normalizedTableName, l.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_table_no_foreign_key.go b/backend/plugin/advisor/mssql/advisor_table_no_foreign_key.go
index 1b9038a744..17deafa98d 100644
--- a/backend/plugin/advisor/mssql/advisor_table_no_foreign_key.go
+++ b/backend/plugin/advisor/mssql/advisor_table_no_foreign_key.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -82,7 +83,7 @@ func (l *tableNoForeignKeyChecker) generateAdvice() ([]*storepb.Advice, error) {
Code: advisor.TableHasFK.Int32(),
Title: l.title,
Content: fmt.Sprintf("FOREIGN KEY is not allowed in the table %s.", l.tableOriginalName[tableName]),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.tableLine[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.tableLine[tableName]),
})
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_table_require_pk.go b/backend/plugin/advisor/mssql/advisor_table_require_pk.go
index 9f1bf5e540..ae1de5d0b9 100644
--- a/backend/plugin/advisor/mssql/advisor_table_require_pk.go
+++ b/backend/plugin/advisor/mssql/advisor_table_require_pk.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/tsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
tsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -82,7 +83,7 @@ func (l *tableRequirePkChecker) generateAdvice() ([]*storepb.Advice, error) {
Code: advisor.TableNoPK.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %s requires PRIMARY KEY.", l.tableOriginalName[tableName]),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.tableLine[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.tableLine[tableName]),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_builtin_prior_backup_check.go b/backend/plugin/advisor/mysql/advisor_builtin_prior_backup_check.go
index d567721811..474ae1b46e 100644
--- a/backend/plugin/advisor/mysql/advisor_builtin_prior_backup_check.go
+++ b/backend/plugin/advisor/mysql/advisor_builtin_prior_backup_check.go
@@ -48,7 +48,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
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(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
}
@@ -62,7 +62,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: "Prior backup cannot deal with mixed DDL and DML statements",
Code: advisor.BuiltinPriorBackupCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.BaseLine),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.BaseLine),
})
}
}
@@ -74,7 +74,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Need database %q to do prior backup but it does not exist", checkCtx.PreUpdateBackupDetail.Database),
Code: advisor.DatabaseNotExists.Int32(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
}
@@ -100,7 +100,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Prior backup cannot handle mixed DML statements on the same table %q", key),
Code: advisor.BuiltinPriorBackupCheck.Int32(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
break
}
diff --git a/backend/plugin/advisor/mysql/advisor_charset_allowlist.go b/backend/plugin/advisor/mysql/advisor_charset_allowlist.go
index c17c609b5e..1c92219c7a 100644
--- a/backend/plugin/advisor/mysql/advisor_charset_allowlist.go
+++ b/backend/plugin/advisor/mysql/advisor_charset_allowlist.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -96,7 +97,7 @@ func (checker *charsetAllowlistChecker) checkCharset(charset string, lineNumber
Code: advisor.DisabledCharset.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" used disabled charset '%s'", checker.text, charset),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_collation_allowlist.go b/backend/plugin/advisor/mysql/advisor_collation_allowlist.go
index 41d58702de..71126febbb 100644
--- a/backend/plugin/advisor/mysql/advisor_collation_allowlist.go
+++ b/backend/plugin/advisor/mysql/advisor_collation_allowlist.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -96,7 +97,7 @@ func (checker *collationAllowlistChecker) checkCollation(collation string, lineN
Code: advisor.DisabledCollation.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" used disabled collation '%s'", checker.text, collation),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_colum_require_default.go b/backend/plugin/advisor/mysql/advisor_colum_require_default.go
index 256b532bb7..b4634dc04e 100644
--- a/backend/plugin/advisor/mysql/advisor_colum_require_default.go
+++ b/backend/plugin/advisor/mysql/advisor_colum_require_default.go
@@ -8,6 +8,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -149,7 +150,7 @@ func (checker *columnRequireDefaultChecker) checkFieldDefinition(tableName, colu
Code: advisor.NoDefault.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s`.`%s` doesn't have DEFAULT.", tableName, columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go b/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go
index d8c56f01b4..7dfc9fdae1 100644
--- a/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go
+++ b/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -96,7 +97,7 @@ func (checker *columnAutoIncrementInitialValueChecker) EnterCreateTable(ctx *mys
Code: advisor.AutoIncrementColumnInitialValueNotMatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The initial auto-increment value in table `%s` is %v, which doesn't equal %v", tableName, value, checker.value),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
@@ -143,7 +144,7 @@ func (checker *columnAutoIncrementInitialValueChecker) EnterAlterTable(ctx *mysq
Code: advisor.AutoIncrementColumnInitialValueNotMatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The initial auto-increment value in table `%s` is %v, which doesn't equal %v", tableName, value, checker.value),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go
index fb61387701..6a29955881 100644
--- a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go
+++ b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -148,7 +149,7 @@ func (checker *columnAutoIncrementMustIntegerChecker) checkFieldDefinition(table
Code: advisor.AutoIncrementColumnNotInteger.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Auto-increment column `%s`.`%s` requires integer type", tableName, columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go
index a4fce2c251..2b1a08c105 100644
--- a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go
+++ b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -150,7 +151,7 @@ func (checker *columnAutoIncrementMustUnsignedChecker) checkFieldDefinition(tabl
Code: advisor.AutoIncrementColumnSigned.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Auto-increment column `%s`.`%s` is not UNSIGNED type", tableName, columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_comment_convention.go b/backend/plugin/advisor/mysql/advisor_column_comment_convention.go
index 5c8336bc40..9ad5fefb9c 100644
--- a/backend/plugin/advisor/mysql/advisor_column_comment_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_column_comment_convention.go
@@ -169,7 +169,7 @@ func (checker *columnCommentConventionChecker) checkFieldDefinition(tableName, c
Code: advisor.CommentTooLong.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The length of column `%s`.`%s` comment should be within %d characters", tableName, columnName, checker.payload.MaxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
@@ -180,7 +180,7 @@ func (checker *columnCommentConventionChecker) checkFieldDefinition(tableName, c
Code: advisor.CommentMissingClassification.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s`.`%s` comment requires classification", tableName, columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
@@ -194,7 +194,7 @@ func (checker *columnCommentConventionChecker) checkFieldDefinition(tableName, c
Code: advisor.CommentEmpty.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s`.`%s` requires comments", tableName, columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go b/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go
index de0032c4c7..5d78159ddb 100644
--- a/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -222,7 +223,7 @@ func (checker *columnCurrentTimeCountLimitChecker) generateAdvice() []*storepb.A
Code: advisor.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: advisor.ConvertANTLRLineToPosition(table.line),
+ StartPosition: common.ConvertANTLRLineToPosition(table.line),
})
}
if table.onUpdateCurrentTimeCount > maxOnUpdateCurrentTimeColumnCount {
@@ -231,7 +232,7 @@ func (checker *columnCurrentTimeCountLimitChecker) generateAdvice() []*storepb.A
Code: advisor.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: advisor.ConvertANTLRLineToPosition(table.line),
+ StartPosition: common.ConvertANTLRLineToPosition(table.line),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go b/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go
index cb7ce6fcfa..671bdd2ef9 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -94,7 +95,7 @@ func (checker *columnDisallowChangingChecker) EnterAlterTable(ctx *mysql.AlterTa
Code: advisor.UseChangeColumnStatement.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" contains CHANGE COLUMN statement", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go
index 67ccd93f3a..02fa4ad215 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -104,7 +105,7 @@ func (checker *columnDisallowChangingOrderChecker) EnterAlterTable(ctx *mysql.Al
Code: advisor.ChangeColumnOrder.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" changes column order", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go
index 17813466c7..3595a9aebb 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -154,7 +155,7 @@ func (checker *columnDisallowChangingTypeChecker) changeColumnType(tableName, co
Code: advisor.ChangeColumnType.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" changes column type", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + dataType.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + dataType.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_drop.go b/backend/plugin/advisor/mysql/advisor_column_disallow_drop.go
index db783d7c17..dc620e5e3d 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_drop.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_drop.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -88,7 +89,7 @@ func (checker *columnDisallowDropChecker) EnterAlterTable(ctx *mysql.AlterTableC
Code: advisor.DropColumn.Int32(),
Title: checker.title,
Content: fmt.Sprintf("drops column \"%s\" of table \"%s\"", columnName, tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + item.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + item.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_drop_in_index.go b/backend/plugin/advisor/mysql/advisor_column_disallow_drop_in_index.go
index 06db09e818..5060ca9763 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_drop_in_index.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_drop_in_index.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -152,7 +153,7 @@ func (checker *columnDisallowDropInIndexChecker) EnterAlterTable(ctx *mysql.Alte
Code: advisor.DropIndexColumn.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s`.`%s` cannot drop index column", tableName, columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + item.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + item.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go b/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go
index 01489ddfb1..a21b7daf43 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -93,7 +94,7 @@ func (checker *columnDisallowSetCharsetChecker) EnterCreateTable(ctx *mysql.Crea
Code: advisor.SetColumnCharset.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Disallow set column charset but \"%s\" does", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
@@ -170,7 +171,7 @@ func (checker *columnDisallowSetCharsetChecker) EnterAlterTable(ctx *mysql.Alter
Code: advisor.SetColumnCharset.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Disallow set column charset but \"%s\" does", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go b/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go
index b388dc4e22..9cbab8bd78 100644
--- a/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go
+++ b/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -98,7 +99,7 @@ func (checker *columnMaximumCharacterLengthChecker) EnterCreateTable(ctx *mysql.
Code: advisor.CharLengthExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The length of the CHAR column `%s.%s` is bigger than %d, please use VARCHAR instead", tableName, columnName, checker.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + tableElement.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + tableElement.GetStart().GetLine()),
})
}
}
@@ -184,7 +185,7 @@ func (checker *columnMaximumCharacterLengthChecker) EnterAlterTable(ctx *mysql.A
Code: advisor.CharLengthExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The length of the CHAR column `%s.%s` is bigger than %d, please use VARCHAR instead", tableName, columnName, checker.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_maximum_varchar_length.go b/backend/plugin/advisor/mysql/advisor_column_maximum_varchar_length.go
index 63912055e8..b94811491c 100644
--- a/backend/plugin/advisor/mysql/advisor_column_maximum_varchar_length.go
+++ b/backend/plugin/advisor/mysql/advisor_column_maximum_varchar_length.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -98,7 +99,7 @@ func (checker *columnMaximumVarcharLengthChecker) EnterCreateTable(ctx *mysql.Cr
Code: advisor.VarcharLengthExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The length of the VARCHAR column `%s.%s` is bigger than %d", tableName, columnName, checker.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + tableElement.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + tableElement.GetStart().GetLine()),
})
}
}
@@ -183,7 +184,7 @@ func (checker *columnMaximumVarcharLengthChecker) EnterAlterTable(ctx *mysql.Alt
Code: advisor.VarcharLengthExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The length of the VARCHAR column `%s.%s` is bigger than %d", tableName, columnName, checker.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_no_null.go b/backend/plugin/advisor/mysql/advisor_column_no_null.go
index 66b8418b3c..e92d0bb20e 100644
--- a/backend/plugin/advisor/mysql/advisor_column_no_null.go
+++ b/backend/plugin/advisor/mysql/advisor_column_no_null.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -99,7 +100,7 @@ func (checker *columnNoNullChecker) generateAdvice() []*storepb.Advice {
Code: advisor.ColumnCannotNull.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s`.`%s` cannot have NULL value", column.tableName, column.columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_require_charset.go b/backend/plugin/advisor/mysql/advisor_column_require_charset.go
index 501563a109..3345994035 100644
--- a/backend/plugin/advisor/mysql/advisor_column_require_charset.go
+++ b/backend/plugin/advisor/mysql/advisor_column_require_charset.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -85,7 +86,7 @@ func (checker *columnRequireCharsetChecker) EnterCreateTable(ctx *mysql.CreateTa
Code: advisor.NoCharset.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column %s does not have a character set specified", columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + columnDefinition.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + columnDefinition.GetStart().GetLine()),
})
}
}
@@ -111,7 +112,7 @@ func (checker *columnRequireCharsetChecker) EnterAlterTable(ctx *mysql.AlterTabl
Code: advisor.NoCharset.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column %s does not have a character set specified", columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + alterListItem.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + alterListItem.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_require_collation.go b/backend/plugin/advisor/mysql/advisor_column_require_collation.go
index 4f93b84169..3567ef0760 100644
--- a/backend/plugin/advisor/mysql/advisor_column_require_collation.go
+++ b/backend/plugin/advisor/mysql/advisor_column_require_collation.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -85,7 +86,7 @@ func (checker *columnRequireCollationChecker) EnterCreateTable(ctx *mysql.Create
Code: advisor.NoCollation.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column %s does not have a collation specified", columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + columnDefinition.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + columnDefinition.GetStart().GetLine()),
})
}
}
@@ -111,7 +112,7 @@ func (checker *columnRequireCollationChecker) EnterAlterTable(ctx *mysql.AlterTa
Code: advisor.NoCollation.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column %s does not have a collation specified", columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + alterListItem.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + alterListItem.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_required.go b/backend/plugin/advisor/mysql/advisor_column_required.go
index 125059ed2d..3c1f0e3098 100644
--- a/backend/plugin/advisor/mysql/advisor_column_required.go
+++ b/backend/plugin/advisor/mysql/advisor_column_required.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -183,7 +184,7 @@ func (checker *columnRequirementChecker) generateAdviceList() []*storepb.Advice
Code: advisor.NoRequiredColumn.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table `%s` requires columns: %s", tableName, strings.Join(missingColumns, ", ")),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line[tableName]),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go b/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go
index f9f2a816dd..aaf1b95d3c 100644
--- a/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go
+++ b/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -123,7 +124,7 @@ func (checker *columnSetDefaultForNotNullChecker) EnterCreateTable(ctx *mysql.Cr
Code: advisor.NotNullColumnWithNoDefault.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s`.`%s` is NOT NULL but doesn't have DEFAULT", tableName, columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + tableElement.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + tableElement.GetStart().GetLine()),
})
}
}
@@ -136,7 +137,7 @@ func (checker *columnSetDefaultForNotNullChecker) checkFieldDefinition(tableName
Code: advisor.NotNullColumnWithNoDefault.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s`.`%s` is NOT NULL but doesn't have DEFAULT", tableName, columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_type_disallow_list.go b/backend/plugin/advisor/mysql/advisor_column_type_disallow_list.go
index 8547c15b97..fbcb44132b 100644
--- a/backend/plugin/advisor/mysql/advisor_column_type_disallow_list.go
+++ b/backend/plugin/advisor/mysql/advisor_column_type_disallow_list.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -113,7 +114,7 @@ func (checker *columnTypeDisallowListChecker) checkFieldDefinition(tableName, co
Code: advisor.DisabledColumnType.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Disallow column type %s but column `%s`.`%s` is", columnType, tableName, columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go b/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go
index 3d9033f40d..7cc955e253 100644
--- a/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go
+++ b/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go
@@ -8,6 +8,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -80,7 +81,7 @@ func (checker *allowDropEmptyDBChecker) EnterDropDatabase(ctx *mysql.DropDatabas
Code: advisor.NotCurrentDatabase.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Database `%s` that is trying to be deleted is not the current database `%s`", dbName, checker.catalog.Origin.DatabaseName()),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
} else if !checker.catalog.Origin.HasNoTable() {
checker.adviceList = append(checker.adviceList, &storepb.Advice{
@@ -88,7 +89,7 @@ func (checker *allowDropEmptyDBChecker) EnterDropDatabase(ctx *mysql.DropDatabas
Code: advisor.DatabaseNotEmpty.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Database `%s` is not allowed to drop if not empty", dbName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_disallow_procedure.go b/backend/plugin/advisor/mysql/advisor_disallow_procedure.go
index 1532f7088a..03e9417368 100644
--- a/backend/plugin/advisor/mysql/advisor_disallow_procedure.go
+++ b/backend/plugin/advisor/mysql/advisor_disallow_procedure.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -80,7 +81,7 @@ func (checker *procedureDisallowCreateChecker) EnterCreateProcedure(ctx *mysql.C
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Procedure is forbidden, but \"%s\" creates", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_event_disallow_create.go b/backend/plugin/advisor/mysql/advisor_event_disallow_create.go
index 666cb2963e..ccb0efef5d 100644
--- a/backend/plugin/advisor/mysql/advisor_event_disallow_create.go
+++ b/backend/plugin/advisor/mysql/advisor_event_disallow_create.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -79,7 +80,7 @@ func (checker *eventDisallowCreateChecker) EnterCreateEvent(ctx *mysql.CreateEve
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Event is forbidden, but \"%s\" creates", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_function_disallow_create.go b/backend/plugin/advisor/mysql/advisor_function_disallow_create.go
index 641233e89c..a9246a04b0 100644
--- a/backend/plugin/advisor/mysql/advisor_function_disallow_create.go
+++ b/backend/plugin/advisor/mysql/advisor_function_disallow_create.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -79,7 +80,7 @@ func (checker *functionDisallowCreateChecker) EnterCreateFunction(ctx *mysql.Cre
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Function is forbidden, but \"%s\" creates", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_function_disallowed_list.go b/backend/plugin/advisor/mysql/advisor_function_disallowed_list.go
index 8bd35810b9..5f8550ea42 100644
--- a/backend/plugin/advisor/mysql/advisor_function_disallowed_list.go
+++ b/backend/plugin/advisor/mysql/advisor_function_disallowed_list.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -83,7 +84,7 @@ func (checker *functionDisallowedListChecker) EnterFunctionCall(ctx *mysql.Funct
Code: advisor.DisabledFunction.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Function \"%s\" is disallowed, but \"%s\" uses", functionName, checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go b/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go
index 6c21150a79..612a25f19b 100644
--- a/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -123,7 +124,7 @@ func (checker *indexKeyNumberLimitChecker) handleConstraintDef(tableName string,
Code: advisor.IndexKeyNumberExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The number of index `%s` in table `%s` should be not greater than %d", indexName, tableName, checker.max),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
@@ -156,7 +157,7 @@ func (checker *indexKeyNumberLimitChecker) EnterCreateIndex(ctx *mysql.CreateInd
Code: advisor.IndexKeyNumberExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The number of index `%s` in table `%s` should be not greater than %d", indexName, tableName, checker.max),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go b/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go
index b8389b94e9..2c2d322ee9 100644
--- a/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go
+++ b/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -159,7 +160,7 @@ func (checker *indexNoDuplicateColumnChecker) EnterCreateIndex(ctx *mysql.Create
Code: advisor.DuplicateColumnInIndex.Int32(),
Title: checker.title,
Content: fmt.Sprintf("%s`%s` has duplicate column `%s`.`%s`", indexType, indexName, tableName, column),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
@@ -211,7 +212,7 @@ func (checker *indexNoDuplicateColumnChecker) handleConstraintDef(tableName stri
Code: advisor.DuplicateColumnInIndex.Int32(),
Title: checker.title,
Content: fmt.Sprintf("%s`%s` has duplicate column `%s`.`%s`", indexType, indexName, tableName, column),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_pk_type.go b/backend/plugin/advisor/mysql/advisor_index_pk_type.go
index 356ed9a5e7..385b89f257 100644
--- a/backend/plugin/advisor/mysql/advisor_index_pk_type.go
+++ b/backend/plugin/advisor/mysql/advisor_index_pk_type.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -194,7 +195,7 @@ func (checker *indexPkTypeChecker) addAdvice(tableName, columnName, columnType s
Code: advisor.IndexPKType.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Columns in primary key must be INT/BIGINT but `%s`.`%s` is %s", tableName, columnName, columnType),
- StartPosition: advisor.ConvertANTLRLineToPosition(lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(lineNumber),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go b/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go
index 71c94db391..891c1e338c 100644
--- a/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go
+++ b/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -178,7 +179,7 @@ func (checker *indexPrimaryKeyTypeAllowlistChecker) checkFieldDefinition(tableNa
Code: advisor.IndexPKType.Int32(),
Title: checker.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: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
@@ -207,7 +208,7 @@ func (checker *indexPrimaryKeyTypeAllowlistChecker) checkConstraintDef(tableName
Code: advisor.IndexPKType.Int32(),
Title: checker.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: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go b/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go
index e2e847087a..a893348321 100644
--- a/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -100,7 +101,7 @@ func (checker *indexTotalNumberLimitChecker) generateAdvice() []*storepb.Advice
Code: advisor.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: advisor.ConvertANTLRLineToPosition(table.line),
+ StartPosition: common.ConvertANTLRLineToPosition(table.line),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_type_allow_list.go b/backend/plugin/advisor/mysql/advisor_index_type_allow_list.go
index 1f14196c61..a3b1c9fc64 100644
--- a/backend/plugin/advisor/mysql/advisor_index_type_allow_list.go
+++ b/backend/plugin/advisor/mysql/advisor_index_type_allow_list.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -160,6 +161,6 @@ func (checker *indexTypeAllowListChecker) validateIndexType(indexType string, li
Code: advisor.IndexTypeNotAllowed.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Index type `%s` is not allowed", indexType),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + line),
})
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go b/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go
index 2a7f9992fd..1760dc9ab7 100644
--- a/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go
+++ b/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -240,7 +241,7 @@ func (checker *indexTypeNoBlobChecker) addAdvice(tableName, columnName, columnTy
Code: advisor.IndexTypeNoBlob.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Columns in index must not be BLOB but `%s`.`%s` is %s", tableName, columnName, columnType),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go b/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go
index 29a8227555..dfa59640aa 100644
--- a/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go
+++ b/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -105,7 +106,7 @@ func (checker *insertDisallowOrderByRandChecker) EnterQueryExpression(ctx *mysql
Code: advisor.InsertUseOrderByRand.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" uses ORDER BY RAND in the INSERT statement", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go b/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go
index cf0478450f..9b23538e68 100644
--- a/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go
+++ b/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -91,7 +92,7 @@ func (checker *insertMustSpecifyColumnChecker) EnterInsertStatement(ctx *mysql.I
Code: advisor.InsertNotSpecifyColumn.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The INSERT statement must specify columns but \"%s\" does not", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
@@ -102,7 +103,7 @@ func (checker *insertMustSpecifyColumnChecker) EnterSelectItemList(ctx *mysql.Se
Code: advisor.InsertNotSpecifyColumn.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The INSERT statement must specify columns but \"%s\" does not", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_insert_row_limit.go b/backend/plugin/advisor/mysql/advisor_insert_row_limit.go
index f2e3ea2762..cc37098704 100644
--- a/backend/plugin/advisor/mysql/advisor_insert_row_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_insert_row_limit.go
@@ -113,7 +113,7 @@ func (checker *insertRowLimitChecker) handleInsertQueryExpression(ctx mysql.IIns
Code: advisor.InsertTooManyRows.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" dry runs failed: %s", checker.text, err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
return
}
@@ -124,7 +124,7 @@ func (checker *insertRowLimitChecker) handleInsertQueryExpression(ctx mysql.IIns
Code: advisor.Internal.Int32(),
Title: checker.title,
Content: fmt.Sprintf("failed to get row count for \"%s\": %s", checker.text, err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
} else if rowCount > int64(checker.maxRow) {
checker.adviceList = append(checker.adviceList, &storepb.Advice{
@@ -132,7 +132,7 @@ func (checker *insertRowLimitChecker) handleInsertQueryExpression(ctx mysql.IIns
Code: advisor.InsertTooManyRows.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" inserts %d rows. The count exceeds %d.", checker.text, rowCount, checker.maxRow),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
}
@@ -155,7 +155,7 @@ func (checker *insertRowLimitChecker) handleNoInsertQueryExpression(ctx mysql.II
Code: advisor.InsertTooManyRows.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" inserts %d rows. The count exceeds %d.", checker.text, len(allValues), checker.maxRow),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_migration_compatibility.go b/backend/plugin/advisor/mysql/advisor_migration_compatibility.go
index ee6849711d..c117ca2594 100644
--- a/backend/plugin/advisor/mysql/advisor_migration_compatibility.go
+++ b/backend/plugin/advisor/mysql/advisor_migration_compatibility.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -77,7 +78,7 @@ func (checker *compatibilityChecker) ExitQuery(ctx *mysql.QueryContext) {
Code: checker.code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" may cause incompatibility with the existing data and code", text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go b/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go
index fd234ff31f..d92add8ea1 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -167,7 +168,7 @@ func (checker *namingAutoIncrementColumnChecker) checkFieldDefinition(tableName,
Code: advisor.NamingAutoIncrementColumnConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s`.`%s` mismatches auto_increment column naming convention, naming format should be %q", tableName, columnName, checker.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
if checker.maxLength > 0 && len(columnName) > checker.maxLength {
@@ -176,7 +177,7 @@ func (checker *namingAutoIncrementColumnChecker) checkFieldDefinition(tableName,
Code: advisor.NamingAutoIncrementColumnConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s`.`%s` mismatches auto_increment column naming convention, its length should be within %d characters", tableName, columnName, checker.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_column.go b/backend/plugin/advisor/mysql/advisor_naming_column.go
index f99cb0e2f8..6840876c6d 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_column.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_column.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -161,7 +162,7 @@ func (checker *namingColumnConventionChecker) handleColumn(tableName string, col
Code: advisor.NamingColumnConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s`.`%s` mismatches column naming convention, naming format should be %q", tableName, columnName, checker.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(lineNumber),
})
}
if checker.maxLength > 0 && len(columnName) > checker.maxLength {
@@ -170,7 +171,7 @@ func (checker *namingColumnConventionChecker) handleColumn(tableName string, col
Code: advisor.NamingColumnConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s`.`%s` mismatches column naming convention, its length should be within %d characters", tableName, columnName, checker.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(lineNumber),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go b/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
index 894a55646f..cacfa607e0 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -157,7 +158,7 @@ func (checker *namingFKConventionChecker) handleIndexList(indexDataList []*index
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {
@@ -166,7 +167,7 @@ func (checker *namingFKConventionChecker) handleIndexList(indexDataList []*index
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_identifier_no_keyword.go b/backend/plugin/advisor/mysql/advisor_naming_identifier_no_keyword.go
index 11a602ba72..4da4cb87ff 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_identifier_no_keyword.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_identifier_no_keyword.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -71,7 +72,7 @@ func (checker *namingIdentifierNoKeywordChecker) EnterPureIdentifier(ctx *mysql.
identifier := trimBackTicks(textNode.GetText())
advice := checker.checkIdentifier(identifier)
if advice != nil {
- advice.StartPosition = advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine())
+ advice.StartPosition = common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine())
checker.adviceList = append(checker.adviceList, advice)
}
}
@@ -81,7 +82,7 @@ func (checker *namingIdentifierNoKeywordChecker) EnterIdentifierKeyword(ctx *mys
identifier := ctx.GetText()
advice := checker.checkIdentifier(identifier)
if advice != nil {
- advice.StartPosition = advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine())
+ advice.StartPosition = common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine())
checker.adviceList = append(checker.adviceList, advice)
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_index_convention.go b/backend/plugin/advisor/mysql/advisor_naming_index_convention.go
index a5200481cc..fd5c055cec 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_index_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_index_convention.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -236,7 +237,7 @@ func (checker *namingIndexConventionChecker) handleIndexList(indexDataList []*in
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {
@@ -245,7 +246,7 @@ func (checker *namingIndexConventionChecker) handleIndexList(indexDataList []*in
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_table.go b/backend/plugin/advisor/mysql/advisor_naming_table.go
index 679857be5b..dfe82d2da0 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_table.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_table.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -135,7 +136,7 @@ func (checker *namingTableConventionChecker) handleTableName(tableName string, l
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s` mismatches table naming convention, naming format should be %q", tableName, checker.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(lineNumber),
})
}
if checker.maxLength > 0 && len(tableName) > checker.maxLength {
@@ -144,7 +145,7 @@ func (checker *namingTableConventionChecker) handleTableName(tableName string, l
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s` mismatches table naming convention, its length should be within %d characters", tableName, checker.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(lineNumber),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go b/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
index 58e86d9add..6bf6e24de1 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -225,7 +226,7 @@ func (checker *namingUKConventionChecker) handleIndexList(indexDataList []*index
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {
@@ -234,7 +235,7 @@ func (checker *namingUKConventionChecker) handleIndexList(indexDataList []*index
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_online_migration.go b/backend/plugin/advisor/mysql/advisor_online_migration.go
index 4e7ffeeeed..9e8d4b027d 100644
--- a/backend/plugin/advisor/mysql/advisor_online_migration.go
+++ b/backend/plugin/advisor/mysql/advisor_online_migration.go
@@ -67,7 +67,7 @@ func (*OnlineMigrationAdvisor) Check(ctx context.Context, checkCtx advisor.Conte
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(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
},
}, nil
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_add_column_without_position.go b/backend/plugin/advisor/mysql/advisor_statement_add_column_without_position.go
index 359aea8cc2..9c30d8c0b1 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_add_column_without_position.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_add_column_without_position.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -115,7 +116,7 @@ func (checker *statementAddColumnWithoutPositionChecker) EnterAlterTable(ctx *my
Code: advisor.StatementAddColumnWithPosition.Int32(),
Title: checker.title,
Content: fmt.Sprintf("add column with position \"%s\"", position),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go b/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go
index f386d6a401..7372ccef4d 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go
@@ -111,7 +111,7 @@ func (checker *statementAffectedRowLimitChecker) handleStmt(lineNumber int) {
Code: advisor.StatementAffectedRowExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" dry runs failed: %s", checker.text, err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(lineNumber),
})
} else {
rowCount, err := getRows(res)
@@ -121,7 +121,7 @@ func (checker *statementAffectedRowLimitChecker) handleStmt(lineNumber int) {
Code: advisor.Internal.Int32(),
Title: checker.title,
Content: fmt.Sprintf("failed to get row count for \"%s\": %s", checker.text, err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(lineNumber),
})
} else if rowCount > int64(checker.maxRow) {
checker.adviceList = append(checker.adviceList, &storepb.Advice{
@@ -129,7 +129,7 @@ func (checker *statementAffectedRowLimitChecker) handleStmt(lineNumber int) {
Code: advisor.StatementAffectedRowExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" affected %d rows (estimated). The count exceeds %d.", checker.text, rowCount, checker.maxRow),
- StartPosition: advisor.ConvertANTLRLineToPosition(lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(lineNumber),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_in_ddl.go b/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_in_ddl.go
index b49f08ea21..2b0c88d378 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_in_ddl.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_in_ddl.go
@@ -7,6 +7,7 @@ import (
"github.com/antlr4-go/antlr/v4"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -52,7 +53,7 @@ func (*StatementDisallowMixInDDLAdvisor) Check(_ context.Context, checkCtx advis
Title: title,
Content: fmt.Sprintf("Alter schema can only run DDL, \"%s\" is not DDL", checker.Text),
Code: advisor.StatementDisallowMixDDLDML.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.BaseLine),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.BaseLine),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_in_dml.go b/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_in_dml.go
index dcf72ee3ce..a0308b2dc1 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_in_dml.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_in_dml.go
@@ -7,6 +7,7 @@ import (
"github.com/antlr4-go/antlr/v4"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -52,7 +53,7 @@ func (*StatementDisallowMixInDMLAdvisor) Check(_ context.Context, checkCtx advis
Title: title,
Content: fmt.Sprintf("Data change can only run DML, \"%s\" is not DML", checker.Text),
Code: advisor.StatementDisallowMixDDLDML.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.BaseLine),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.BaseLine),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go
index cccf96c104..48a86f26c5 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go
@@ -88,7 +88,7 @@ func (checker *disallowUsingFilesortChecker) EnterSelectStatement(ctx *mysql.Sel
Code: advisor.StatementExplainQueryFailed.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Failed to explain query: %s, with error: %s", query, err),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
} else {
hasUsingFilesort, tables, err := hasUsingFilesortInExtraColumn(res)
@@ -98,7 +98,7 @@ func (checker *disallowUsingFilesortChecker) EnterSelectStatement(ctx *mysql.Sel
Code: advisor.Internal.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Failed to check extra column: %s, with error: %s", query, err),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
} else if hasUsingFilesort {
checker.adviceList = append(checker.adviceList, &storepb.Advice{
@@ -106,7 +106,7 @@ func (checker *disallowUsingFilesortChecker) EnterSelectStatement(ctx *mysql.Sel
Code: advisor.StatementHasUsingFilesort.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Using filesort detected on table(s): %s", tables),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go
index e09ff29f36..f83c13380a 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go
@@ -88,7 +88,7 @@ func (checker *disallowUsingTemporaryChecker) EnterSelectStatement(ctx *mysql.Se
Code: advisor.StatementExplainQueryFailed.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Failed to explain query: %s, with error: %s", query, err),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
} else {
hasUsingTemporary, tables, err := hasUsingTemporaryInExtraColumn(res)
@@ -98,7 +98,7 @@ func (checker *disallowUsingTemporaryChecker) EnterSelectStatement(ctx *mysql.Se
Code: advisor.Internal.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Failed to check extra column: %s, with error: %s", query, err),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
} else if hasUsingTemporary {
checker.adviceList = append(checker.adviceList, &storepb.Advice{
@@ -106,7 +106,7 @@ func (checker *disallowUsingTemporaryChecker) EnterSelectStatement(ctx *mysql.Se
Code: advisor.StatementHasUsingTemporary.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Using temporary detected on table(s): %s", tables),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go b/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go
index d2a233be4a..5baae8e4df 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go
@@ -109,7 +109,7 @@ func (checker *statementDmlDryRunChecker) handleStmt(text string, lineNumber int
Code: advisor.StatementDMLDryRunFailed.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" dry runs failed: %s", text, err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line + lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line + lineNumber),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_join_strict_column_attrs.go b/backend/plugin/advisor/mysql/advisor_statement_join_strict_column_attrs.go
index b5b4a61ae9..6a92714803 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_join_strict_column_attrs.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_join_strict_column_attrs.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
"github.com/bytebase/bytebase/backend/store/model"
@@ -204,7 +205,7 @@ func (checker *statementJoinStrictColumnAttrsChecker) checkColumnAttrs(leftColum
Code: advisor.StatementJoinColumnAttrsNotMatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("%s.%s and %s.%s column fields do not match", leftColumnAttr.Table, leftColumnAttr.Column, rightColumnAttr.Table, rightColumnAttr.Column),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_maximum_join_table_count.go b/backend/plugin/advisor/mysql/advisor_statement_maximum_join_table_count.go
index d58d5de81f..5ac9f97f2c 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_maximum_join_table_count.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_maximum_join_table_count.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -78,7 +79,7 @@ func (checker *statementMaximumJoinTableCountChecker) EnterJoinedTable(ctx *mysq
Code: advisor.StatementMaximumJoinTableCount.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" exceeds the maximum number of joins %d.", checker.text, checker.limitMaxValue),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_maximum_limit_value.go b/backend/plugin/advisor/mysql/advisor_statement_maximum_limit_value.go
index 3273181093..a8c4f68191 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_maximum_limit_value.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_maximum_limit_value.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -108,7 +109,7 @@ func (checker *statementMaximumLimitValueChecker) EnterLimitClause(ctx *mysql.Li
Code: advisor.StatementExceedMaximumLimitValue.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The limit value %d exceeds the maximum allowed value %d", limitValue, checker.limitMaxValue),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go b/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go
index a8a22e189a..7fc7a4f195 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -131,7 +132,7 @@ func (checker *statementMergeAlterTableChecker) generateAdvice() []*storepb.Advi
Code: advisor.StatementRedundantAlterTable.Int32(),
Title: checker.title,
Content: fmt.Sprintf("There are %d statements to modify table `%s`", table.count, table.name),
- StartPosition: advisor.ConvertANTLRLineToPosition(table.lastLine),
+ StartPosition: common.ConvertANTLRLineToPosition(table.lastLine),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go b/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go
index 8cb1cc7287..e0d5587de0 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go
@@ -149,7 +149,7 @@ func (checker *statementQueryMinumumPlanLevelChecker) EnterSelectStatement(ctx *
Code: advisor.StatementExplainQueryFailed.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Failed to explain query: %s, with error: %s", query, err),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
} else {
explainTypes, err := getQueryExplainTypes(res)
@@ -159,7 +159,7 @@ func (checker *statementQueryMinumumPlanLevelChecker) EnterSelectStatement(ctx *
Code: advisor.Internal.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Failed to check explain type column: %s, with error: %s", query, err),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
} else if len(explainTypes) > 0 {
overused, overusedType := false, ExplainTypeAll
@@ -176,7 +176,7 @@ func (checker *statementQueryMinumumPlanLevelChecker) EnterSelectStatement(ctx *
Code: advisor.StatementUnwantedQueryPlanLevel.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Overused query plan level detected %s, minimum plan level: %s", overusedType.String(), checker.explainType.String()),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go b/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go
index f79f4cbbf1..d391b008e7 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go
@@ -89,7 +89,7 @@ func (checker *statementSelectFullTableScanChecker) EnterSelectStatement(ctx *my
Code: advisor.StatementCheckSelectFullTableScanFailed.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Failed to check full table scan: %s, with error: %s", query, err),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
} else {
hasFullScan, tables, err := hasTableFullScan(res)
@@ -99,7 +99,7 @@ func (checker *statementSelectFullTableScanChecker) EnterSelectStatement(ctx *my
Code: advisor.Internal.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Failed to check full table scan: %s, with error: %s", query, err),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
} else if hasFullScan {
checker.adviceList = append(checker.adviceList, &storepb.Advice{
@@ -107,7 +107,7 @@ func (checker *statementSelectFullTableScanChecker) EnterSelectStatement(ctx *my
Code: advisor.StatementHasTableFullScan.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Full table scan detected on table(s): %s", tables),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_where_disallow_using_function.go b/backend/plugin/advisor/mysql/advisor_statement_where_disallow_using_function.go
index 540a4823c8..2f27e1aea7 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_where_disallow_using_function.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_where_disallow_using_function.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -92,7 +93,7 @@ func (checker *statementWhereDisallowUsingFunctionChecker) EnterFunctionCall(ctx
Code: advisor.DisabledFunction.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Function is disallowed in where clause, but \"%s\" uses", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_where_maximum_logical_operator_count.go b/backend/plugin/advisor/mysql/advisor_statement_where_maximum_logical_operator_count.go
index 635087e762..bfdd496119 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_where_maximum_logical_operator_count.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_where_maximum_logical_operator_count.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -55,7 +56,7 @@ func (*StatementWhereMaximumLogicalOperatorCountAdvisor) Check(_ context.Context
Code: advisor.StatementWhereMaximumLogicalOperatorCount.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Number of tokens (%d) in the OR predicate operation exceeds limit (%d) in statement %q.", checker.maxOrCount, checker.maximum, checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.maxOrCountLine),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.maxOrCountLine),
})
}
}
@@ -106,7 +107,7 @@ func (checker *statementWhereMaximumLogicalOperatorCountChecker) EnterExprList(c
Code: advisor.StatementWhereMaximumLogicalOperatorCount.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Number of tokens (%d) in IN predicate operation exceeds limit (%d) in statement %q.", count, checker.maximum, checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_where_no_equal_null.go b/backend/plugin/advisor/mysql/advisor_statement_where_no_equal_null.go
index d7f56a6a07..69331a3f90 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_where_no_equal_null.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_where_no_equal_null.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -87,7 +88,7 @@ func (checker *statementWhereNoEqualNullChecker) EnterPrimaryExprCompare(ctx *my
Code: advisor.StatementWhereNoEqualNull.Int32(),
Title: checker.title,
Content: fmt.Sprintf("WHERE clause contains equal null: %s", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go b/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go
index 0b47376f52..494e89b220 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -81,6 +82,6 @@ func (checker *statementDisallowCommitChecker) EnterTransactionStatement(ctx *my
Code: advisor.StatementDisallowCommit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Commit is not allowed, related statement: \"%s\"", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_disallow_limit.go b/backend/plugin/advisor/mysql/advisor_stmt_disallow_limit.go
index 6e128f6bfe..ae698bc445 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_disallow_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_disallow_limit.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -109,6 +110,6 @@ func (checker *statementDisallowLimitChecker) handleLimitClause(code advisor.Cod
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but \"%s\" uses", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line + lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line + lineNumber),
})
}
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_disallow_order_by.go b/backend/plugin/advisor/mysql/advisor_stmt_disallow_order_by.go
index 40940410a3..08edf92c0d 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_disallow_order_by.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_disallow_order_by.go
@@ -11,6 +11,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -89,6 +90,6 @@ func (checker *disallowOrderByChecker) handleOrderByClause(code advisor.Code, li
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("ORDER BY clause is forbidden in DELETE and UPDATE statements, but \"%s\" uses", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line + lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line + lineNumber),
})
}
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go b/backend/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go
index 1253145a5b..eca7ac9a31 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -81,7 +82,7 @@ func (checker *noLeadingWildcardLikeChecker) EnterPredicateExprLike(ctx *mysql.P
Code: advisor.StatementLeadingWildcardLike.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" uses leading wildcard LIKE", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_no_select_all.go b/backend/plugin/advisor/mysql/advisor_stmt_no_select_all.go
index 7fd545220a..d246552b97 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_no_select_all.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_no_select_all.go
@@ -8,6 +8,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -71,7 +72,7 @@ func (checker *noSelectAllChecker) EnterSelectItemList(ctx *mysql.SelectItemList
Code: advisor.StatementSelectAll.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" uses SELECT all", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_require_algorithm_or_lock_options.go b/backend/plugin/advisor/mysql/advisor_stmt_require_algorithm_or_lock_options.go
index aabeecb141..4eacc5de56 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_require_algorithm_or_lock_options.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_require_algorithm_or_lock_options.go
@@ -7,6 +7,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -86,7 +87,7 @@ func (checker *RequireAlgorithmOptionChecker) ExitAlterTable(*mysql.AlterTableCo
Code: int32(checker.errorCode),
Title: checker.title,
Content: "ALTER TABLE statement should include " + checker.requiredOption + " option",
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + checker.line),
})
}
checker.inAlterTableStatement = false
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_where_required.go b/backend/plugin/advisor/mysql/advisor_stmt_where_required.go
index 87bcc72583..bf994c35d3 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_where_required.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_where_required.go
@@ -8,6 +8,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -100,6 +101,6 @@ func (checker *whereRequirementChecker) handleWhereClause(lineNumber int) {
Code: advisor.StatementNoWhere.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" requires WHERE clause", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
})
}
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_where_requirement_for_select.go b/backend/plugin/advisor/mysql/advisor_stmt_where_requirement_for_select.go
index 90e404ca92..df5da0938d 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_where_requirement_for_select.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_where_requirement_for_select.go
@@ -8,6 +8,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -80,6 +81,6 @@ func (checker *whereRequirementForSelectChecker) handleWhereClause(lineNumber in
Code: advisor.StatementNoWhere.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" requires WHERE clause", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
})
}
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_where_requirement_for_update_delete.go b/backend/plugin/advisor/mysql/advisor_stmt_where_requirement_for_update_delete.go
index a5cb8464a9..6da126d2a8 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_where_requirement_for_update_delete.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_where_requirement_for_update_delete.go
@@ -8,6 +8,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -90,6 +91,6 @@ func (checker *whereRequirementForUpdateDeleteChecker) handleWhereClause(lineNum
Code: advisor.StatementNoWhere.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" requires WHERE clause", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + lineNumber),
})
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_comment_convention.go b/backend/plugin/advisor/mysql/advisor_table_comment_convention.go
index 5bdeb778a8..39c851928e 100644
--- a/backend/plugin/advisor/mysql/advisor_table_comment_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_table_comment_convention.go
@@ -89,7 +89,7 @@ func (checker *tableCommentConventionChecker) EnterCreateTable(ctx *mysql.Create
Code: advisor.CommentEmpty.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table `%s` requires comments", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
if checker.payload.MaxLength >= 0 && len(comment) > checker.payload.MaxLength {
@@ -98,7 +98,7 @@ func (checker *tableCommentConventionChecker) EnterCreateTable(ctx *mysql.Create
Code: advisor.CommentTooLong.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The length of table `%s` comment should be within %d characters", tableName, checker.payload.MaxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
if checker.payload.RequiredClassification {
@@ -108,7 +108,7 @@ func (checker *tableCommentConventionChecker) EnterCreateTable(ctx *mysql.Create
Code: advisor.CommentMissingClassification.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table `%s` comment requires classification", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_disallow_ddl.go b/backend/plugin/advisor/mysql/advisor_table_disallow_ddl.go
index 97fa5ad367..6559f76f3b 100644
--- a/backend/plugin/advisor/mysql/advisor_table_disallow_ddl.go
+++ b/backend/plugin/advisor/mysql/advisor_table_disallow_ddl.go
@@ -8,6 +8,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -115,7 +116,7 @@ func (checker *tableDisallowDDLChecker) checkTableName(tableName string, line in
Code: advisor.TableDisallowDDL.Int32(),
Title: checker.title,
Content: fmt.Sprintf("DDL is disallowed on table %s.", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_disallow_dml.go b/backend/plugin/advisor/mysql/advisor_table_disallow_dml.go
index b1f0f80da5..ad1209000b 100644
--- a/backend/plugin/advisor/mysql/advisor_table_disallow_dml.go
+++ b/backend/plugin/advisor/mysql/advisor_table_disallow_dml.go
@@ -8,6 +8,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -109,7 +110,7 @@ func (checker *tableDisallowDMLChecker) checkTableName(tableName string, line in
Code: advisor.TableDisallowDML.Int32(),
Title: checker.title,
Content: fmt.Sprintf("DML is disallowed on table %s.", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go b/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go
index 1581af9e67..9293c80305 100644
--- a/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go
+++ b/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -82,7 +83,7 @@ func (checker *tableDisallowPartitionChecker) EnterCreateTable(ctx *mysql.Create
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table partition is forbidden, but \"%s\" creates", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
@@ -102,7 +103,7 @@ func (checker *tableDisallowPartitionChecker) EnterAlterTable(ctx *mysql.AlterTa
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table partition is forbidden, but \"%s\" creates", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_disallow_set_charset.go b/backend/plugin/advisor/mysql/advisor_table_disallow_set_charset.go
index 04ae7515e9..777832e953 100644
--- a/backend/plugin/advisor/mysql/advisor_table_disallow_set_charset.go
+++ b/backend/plugin/advisor/mysql/advisor_table_disallow_set_charset.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -74,7 +75,7 @@ func (checker *tableDisallowSetCharsetChecker) EnterCreateTable(ctx *mysql.Creat
Code: advisor.DisallowSetCharset.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Set charset on tables is disallowed, but \"%s\" uses", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
@@ -104,7 +105,7 @@ func (checker *tableDisallowSetCharsetChecker) EnterAlterTable(ctx *mysql.AlterT
Code: advisor.DisallowSetCharset.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Set charset on tables is disallowed, but \"%s\" uses", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_disallow_trigger.go b/backend/plugin/advisor/mysql/advisor_table_disallow_trigger.go
index a5ba5720cc..ff67a30c6e 100644
--- a/backend/plugin/advisor/mysql/advisor_table_disallow_trigger.go
+++ b/backend/plugin/advisor/mysql/advisor_table_disallow_trigger.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -80,7 +81,7 @@ func (checker *tableDisallowTriggerChecker) EnterCreateTrigger(ctx *mysql.Create
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Trigger is forbidden, but \"%s\" creates", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go
index 3f5501f08a..5c72183234 100644
--- a/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -84,7 +85,7 @@ func (checker *namingDropTableConventionChecker) EnterDropTable(ctx *mysql.DropT
Code: advisor.TableDropNamingConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s` mismatches drop table naming convention, naming format should be %q", tableName, checker.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_limit_size.go b/backend/plugin/advisor/mysql/advisor_table_limit_size.go
index 70df95a7d6..ccce684133 100644
--- a/backend/plugin/advisor/mysql/advisor_table_limit_size.go
+++ b/backend/plugin/advisor/mysql/advisor_table_limit_size.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -71,7 +72,7 @@ func (*MaximumTableSizeAdvisor) Check(_ context.Context, checkCtx advisor.Contex
Code: advisor.TableExceedLimitSize.Int32(),
Title: checkCtx.Rule.Type,
Content: fmt.Sprintf("Apply DDL on large table '%s' ( %d rows ) will lock table for a long time", tabName, tableRows),
- StartPosition: advisor.ConvertANTLRLineToPosition(statementBaseLine + tableSizeChecker.baseLine),
+ StartPosition: common.ConvertANTLRLineToPosition(statementBaseLine + tableSizeChecker.baseLine),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_no_duplicate_index.go b/backend/plugin/advisor/mysql/advisor_table_no_duplicate_index.go
index 4207a04636..f76ba519c9 100644
--- a/backend/plugin/advisor/mysql/advisor_table_no_duplicate_index.go
+++ b/backend/plugin/advisor/mysql/advisor_table_no_duplicate_index.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -103,7 +104,7 @@ func (checker *tableNoDuplicateIndexChecker) EnterCreateTable(ctx *mysql.CreateT
Code: advisor.DuplicateIndexInTable.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s` has duplicate index `%s`", tableName, index.indexName),
- StartPosition: advisor.ConvertANTLRLineToPosition(index.line),
+ StartPosition: common.ConvertANTLRLineToPosition(index.line),
})
}
}
@@ -134,7 +135,7 @@ func (checker *tableNoDuplicateIndexChecker) EnterAlterTable(ctx *mysql.AlterTab
Code: advisor.DuplicateIndexInTable.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s` has duplicate index `%s`", tableName, index.indexName),
- StartPosition: advisor.ConvertANTLRLineToPosition(index.line),
+ StartPosition: common.ConvertANTLRLineToPosition(index.line),
})
}
}
@@ -216,7 +217,7 @@ func (checker *tableNoDuplicateIndexChecker) EnterCreateIndex(ctx *mysql.CreateI
Code: advisor.DuplicateIndexInTable.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s` has duplicate index `%s`", tableName, index.indexName),
- StartPosition: advisor.ConvertANTLRLineToPosition(index.line),
+ StartPosition: common.ConvertANTLRLineToPosition(index.line),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_no_fk.go b/backend/plugin/advisor/mysql/advisor_table_no_fk.go
index d7cae6a69d..2b034bef4a 100644
--- a/backend/plugin/advisor/mysql/advisor_table_no_fk.go
+++ b/backend/plugin/advisor/mysql/advisor_table_no_fk.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -115,7 +116,7 @@ func (checker *tableNoFKChecker) handleTableConstraintDef(tableName string, ctx
Code: advisor.TableHasFK.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Foreign key is not allowed in the table `%s`", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
default:
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_require_charset.go b/backend/plugin/advisor/mysql/advisor_table_require_charset.go
index 188a442257..100f907d6d 100644
--- a/backend/plugin/advisor/mysql/advisor_table_require_charset.go
+++ b/backend/plugin/advisor/mysql/advisor_table_require_charset.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -82,7 +83,7 @@ func (checker *tableRequireCharsetChecker) EnterCreateTable(ctx *mysql.CreateTab
Code: advisor.NoCharset.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table %s does not have a character set specified", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_require_collation.go b/backend/plugin/advisor/mysql/advisor_table_require_collation.go
index ae7d173584..b346047741 100644
--- a/backend/plugin/advisor/mysql/advisor_table_require_collation.go
+++ b/backend/plugin/advisor/mysql/advisor_table_require_collation.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -82,7 +83,7 @@ func (checker *tableRequireCollationChecker) EnterCreateTable(ctx *mysql.CreateT
Code: advisor.NoCollation.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table %s does not have a collation specified", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_require_pk.go b/backend/plugin/advisor/mysql/advisor_table_require_pk.go
index fa6818ef82..95c53667b9 100644
--- a/backend/plugin/advisor/mysql/advisor_table_require_pk.go
+++ b/backend/plugin/advisor/mysql/advisor_table_require_pk.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -206,7 +207,7 @@ func (checker *tableRequirePKChecker) generateAdviceList() []*storepb.Advice {
Code: advisor.TableNoPK.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table `%s` requires PRIMARY KEY", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line[tableName]),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_text_fields_total_length.go b/backend/plugin/advisor/mysql/advisor_table_text_fields_total_length.go
index bd23542598..905782d443 100644
--- a/backend/plugin/advisor/mysql/advisor_table_text_fields_total_length.go
+++ b/backend/plugin/advisor/mysql/advisor_table_text_fields_total_length.go
@@ -12,6 +12,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -92,7 +93,7 @@ func (checker *tableFieldsMaximumVarcharLengthChecker) EnterCreateTable(ctx *mys
Code: advisor.IndexCountExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table %q total text column length (%d) exceeds the limit (%d).", tableName, total, checker.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
@@ -126,7 +127,7 @@ func (checker *tableFieldsMaximumVarcharLengthChecker) EnterAlterTable(ctx *mysq
Code: advisor.TotalTextLengthExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table %q total text column length (%d) exceeds the limit (%d).", tableName, total, checker.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_use_innodb.go b/backend/plugin/advisor/mysql/advisor_use_innodb.go
index 62a2d78b74..f0693ae55f 100644
--- a/backend/plugin/advisor/mysql/advisor_use_innodb.go
+++ b/backend/plugin/advisor/mysql/advisor_use_innodb.go
@@ -10,6 +10,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -164,6 +165,6 @@ func (c *useInnoDBChecker) addAdvice(content string, lineNumber int) {
Code: advisor.NotInnoDBEngine.Int32(),
Title: c.title,
Content: fmt.Sprintf("\"%s;\" doesn't use InnoDB engine", content),
- StartPosition: advisor.ConvertANTLRLineToPosition(lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(lineNumber),
})
}
diff --git a/backend/plugin/advisor/mysql/advisor_view_disallow_create.go b/backend/plugin/advisor/mysql/advisor_view_disallow_create.go
index e0b62e97f8..f19422b480 100644
--- a/backend/plugin/advisor/mysql/advisor_view_disallow_create.go
+++ b/backend/plugin/advisor/mysql/advisor_view_disallow_create.go
@@ -9,6 +9,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -79,7 +80,7 @@ func (checker *viewDisallowCreateChecker) EnterCreateView(ctx *mysql.CreateViewC
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("View is forbidden, but \"%s\" creates", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oceanbase/advisor_disallow_offline_ddl.go b/backend/plugin/advisor/oceanbase/advisor_disallow_offline_ddl.go
index 2f217d0e6e..ac83f12cf1 100644
--- a/backend/plugin/advisor/oceanbase/advisor_disallow_offline_ddl.go
+++ b/backend/plugin/advisor/oceanbase/advisor_disallow_offline_ddl.go
@@ -13,6 +13,7 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -246,6 +247,6 @@ func (checker *disallowOfflineDdlChecker) advice(ctx antlr.ParserRuleContext, op
Code: advisor.StatementOfflineDDL.Int32(),
Title: checker.title,
Content: fmt.Sprintf("%s is an offline DDL operation.", operation),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.baseLine + ctx.GetStart().GetLine()),
})
}
diff --git a/backend/plugin/advisor/oracle/advisor_builtin_prior_backup_check.go b/backend/plugin/advisor/oracle/advisor_builtin_prior_backup_check.go
index b9c3421874..18df712ee1 100644
--- a/backend/plugin/advisor/oracle/advisor_builtin_prior_backup_check.go
+++ b/backend/plugin/advisor/oracle/advisor_builtin_prior_backup_check.go
@@ -50,7 +50,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
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(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
}
@@ -61,7 +61,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Need database %q to do prior backup but it does not exist", checkCtx.PreUpdateBackupDetail.Database),
Code: advisor.DatabaseNotExists.Int32(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
return adviceList, nil
}
@@ -75,7 +75,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: "Prior backup cannot deal with mixed DDL and DML statements",
Code: int32(advisor.BuiltinPriorBackupCheck),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
}
@@ -103,7 +103,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Prior backup cannot handle mixed DML statements on the same table %q", key),
Code: advisor.BuiltinPriorBackupCheck.Int32(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
break
}
diff --git a/backend/plugin/advisor/oracle/advisor_column_add_not_null_column_require_default.go b/backend/plugin/advisor/oracle/advisor_column_add_not_null_column_require_default.go
index 3ac52e416c..54862eb035 100644
--- a/backend/plugin/advisor/oracle/advisor_column_add_not_null_column_require_default.go
+++ b/backend/plugin/advisor/oracle/advisor_column_add_not_null_column_require_default.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -100,7 +101,7 @@ func (l *columnAddNotNullColumnRequireDefaultListener) ExitColumn_definition(ctx
Code: advisor.NotNullColumnWithNoDefault.Int32(),
Title: l.title,
Content: fmt.Sprintf("Adding not null column %q requires default.", normalizeIdentifier(ctx.Column_name(), l.currentDatabase)),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_column_comment_convention.go b/backend/plugin/advisor/oracle/advisor_column_comment_convention.go
index 8cea56f5b6..029126ac61 100644
--- a/backend/plugin/advisor/oracle/advisor_column_comment_convention.go
+++ b/backend/plugin/advisor/oracle/advisor_column_comment_convention.go
@@ -124,7 +124,7 @@ func (l *columnCommentConventionListener) generateAdvices() ([]*storepb.Advice,
Code: advisor.CommentEmpty.Int32(),
Title: l.title,
Content: fmt.Sprintf("Comment is required for column %s", normalizeIdentifierName(columnName)),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.columnLine[columnName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.columnLine[columnName]),
})
}
} else {
@@ -134,7 +134,7 @@ func (l *columnCommentConventionListener) generateAdvices() ([]*storepb.Advice,
Code: advisor.CommentTooLong.Int32(),
Title: l.title,
Content: fmt.Sprintf("Column %s comment is too long. The length of comment should be within %d characters", normalizeIdentifierName(columnName), l.payload.MaxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.columnLine[columnName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.columnLine[columnName]),
})
}
if l.payload.RequiredClassification {
@@ -144,7 +144,7 @@ func (l *columnCommentConventionListener) generateAdvices() ([]*storepb.Advice,
Code: advisor.CommentMissingClassification.Int32(),
Title: l.title,
Content: fmt.Sprintf("Column %s comment requires classification", normalizeIdentifierName(columnName)),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.columnLine[columnName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.columnLine[columnName]),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_column_maximum_character_length.go b/backend/plugin/advisor/oracle/advisor_column_maximum_character_length.go
index 02415fd6ea..bcc1678f6d 100644
--- a/backend/plugin/advisor/oracle/advisor_column_maximum_character_length.go
+++ b/backend/plugin/advisor/oracle/advisor_column_maximum_character_length.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -98,6 +99,6 @@ func (l *columnMaximumCharacterLengthListener) EnterDatatype(ctx *parser.Datatyp
Code: advisor.CharLengthExceedsLimit.Int32(),
Title: l.title,
Content: fmt.Sprintf("The maximum character length is %d.", l.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
diff --git a/backend/plugin/advisor/oracle/advisor_column_maximum_varchar_length.go b/backend/plugin/advisor/oracle/advisor_column_maximum_varchar_length.go
index 1c555ec1b5..572c23891f 100644
--- a/backend/plugin/advisor/oracle/advisor_column_maximum_varchar_length.go
+++ b/backend/plugin/advisor/oracle/advisor_column_maximum_varchar_length.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -98,6 +99,6 @@ func (l *columnMaximumVarcharLengthListener) EnterDatatype(ctx *parser.DatatypeC
Code: advisor.VarcharLengthExceedsLimit.Int32(),
Title: l.title,
Content: fmt.Sprintf("The maximum varchar length is %d.", l.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
diff --git a/backend/plugin/advisor/oracle/advisor_column_no_null.go b/backend/plugin/advisor/oracle/advisor_column_no_null.go
index 0ac7fd64b8..67e746ef6c 100644
--- a/backend/plugin/advisor/oracle/advisor_column_no_null.go
+++ b/backend/plugin/advisor/oracle/advisor_column_no_null.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -81,7 +82,7 @@ func (l *columnNoNullListener) generateAdvice() ([]*storepb.Advice, error) {
Code: advisor.ColumnCannotNull.Int32(),
Title: l.title,
Content: fmt.Sprintf("Column %q is nullable, which is not allowed.", lastIdentifier(columnID)),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
}
diff --git a/backend/plugin/advisor/oracle/advisor_column_require.go b/backend/plugin/advisor/oracle/advisor_column_require.go
index 8a797f80c1..85c5f7ba18 100644
--- a/backend/plugin/advisor/oracle/advisor_column_require.go
+++ b/backend/plugin/advisor/oracle/advisor_column_require.go
@@ -11,6 +11,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -106,7 +107,7 @@ func (l *columnRequireListener) ExitCreate_table(ctx *parser.Create_tableContext
Code: advisor.NoRequiredColumn.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %q requires columns: %s", tableName, strings.Join(missingColumns, ", ")),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStop().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStop().GetLine()),
})
}
@@ -143,7 +144,7 @@ func (l *columnRequireListener) ExitAlter_table(ctx *parser.Alter_tableContext)
Code: advisor.NoRequiredColumn.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %q requires columns: %s", tableName, strings.Join(missingColumns, ", ")),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStop().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStop().GetLine()),
})
}
diff --git a/backend/plugin/advisor/oracle/advisor_column_require_default.go b/backend/plugin/advisor/oracle/advisor_column_require_default.go
index 0457af706a..b6da61305f 100644
--- a/backend/plugin/advisor/oracle/advisor_column_require_default.go
+++ b/backend/plugin/advisor/oracle/advisor_column_require_default.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -78,7 +79,7 @@ func (l *columnRequireDefaultListener) generateAdvice() ([]*storepb.Advice, erro
Code: advisor.NoDefault.Int32(),
Title: l.title,
Content: fmt.Sprintf("Column %q doesn't have default value", lastIdentifier(columnID)),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
}
diff --git a/backend/plugin/advisor/oracle/advisor_column_type_disallow_list.go b/backend/plugin/advisor/oracle/advisor_column_type_disallow_list.go
index b7eb4084b9..41d5fc942c 100644
--- a/backend/plugin/advisor/oracle/advisor_column_type_disallow_list.go
+++ b/backend/plugin/advisor/oracle/advisor_column_type_disallow_list.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -91,7 +92,7 @@ func (l *columnTypeDisallowListListener) EnterColumn_definition(ctx *parser.Colu
Code: advisor.DisabledColumnType.Int32(),
Title: l.title,
Content: fmt.Sprintf("Disallow column type %s but column \"%s\" is", ctx.Datatype().GetText(), normalizeIdentifier(ctx.Column_name(), l.currentDatabase)),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.Datatype().GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.Datatype().GetStart().GetLine()),
})
}
if ctx.Regular_id() != nil {
@@ -102,7 +103,7 @@ func (l *columnTypeDisallowListListener) EnterColumn_definition(ctx *parser.Colu
Code: advisor.DisabledColumnType.Int32(),
Title: l.title,
Content: fmt.Sprintf("Disallow column type %s but column \"%s\" is", ctx.Regular_id().GetText(), normalizeIdentifier(ctx.Column_name(), l.currentDatabase)),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.Regular_id().GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.Regular_id().GetStart().GetLine()),
})
break
}
@@ -118,7 +119,7 @@ func (l *columnTypeDisallowListListener) EnterModify_col_properties(ctx *parser.
Code: advisor.DisabledColumnType.Int32(),
Title: l.title,
Content: fmt.Sprintf("Disallow column type %s but column \"%s\" is", ctx.Datatype().GetText(), normalizeIdentifier(ctx.Column_name(), l.currentDatabase)),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.Datatype().GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.Datatype().GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_index_key_number_limit.go b/backend/plugin/advisor/oracle/advisor_index_key_number_limit.go
index 43de56cc06..64d1165020 100644
--- a/backend/plugin/advisor/oracle/advisor_index_key_number_limit.go
+++ b/backend/plugin/advisor/oracle/advisor_index_key_number_limit.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -81,7 +82,7 @@ func (l *indexKeyNumberLimitListener) EnterTable_index_clause(ctx *parser.Table_
Code: advisor.IndexKeyNumberExceedsLimit.Int32(),
Title: l.title,
Content: fmt.Sprintf("Index key number should be less than or equal to %d", l.max),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
@@ -95,7 +96,7 @@ func (l *indexKeyNumberLimitListener) EnterOut_of_line_constraint(ctx *parser.Ou
Code: advisor.IndexKeyNumberExceedsLimit.Int32(),
Title: l.title,
Content: fmt.Sprintf("Index key number should be less than or equal to %d", l.max),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_insert_must_specify_column.go b/backend/plugin/advisor/oracle/advisor_insert_must_specify_column.go
index f97ed2509c..2f2f791eb5 100644
--- a/backend/plugin/advisor/oracle/advisor_insert_must_specify_column.go
+++ b/backend/plugin/advisor/oracle/advisor_insert_must_specify_column.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -71,7 +72,7 @@ func (l *insertMustSpecifyColumnListener) EnterInsert_into_clause(ctx *parser.In
Code: advisor.InsertNotSpecifyColumn.Int32(),
Title: l.title,
Content: "INSERT statement should specify column name.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go b/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go
index a2a6fd60f3..ada182e4dc 100644
--- a/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go
+++ b/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -81,7 +82,7 @@ func (l *namingIdentifierCaseListener) EnterId_expression(ctx *parser.Id_express
Code: advisor.NamingCaseMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf("Identifier %q should be upper case", identifier),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
} else {
@@ -91,7 +92,7 @@ func (l *namingIdentifierCaseListener) EnterId_expression(ctx *parser.Id_express
Code: advisor.NamingCaseMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf("Identifier %q should be lower case", identifier),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_naming_identifier_no_keyword.go b/backend/plugin/advisor/oracle/advisor_naming_identifier_no_keyword.go
index 4dab539400..f6c5f8178d 100644
--- a/backend/plugin/advisor/oracle/advisor_naming_identifier_no_keyword.go
+++ b/backend/plugin/advisor/oracle/advisor_naming_identifier_no_keyword.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -74,7 +75,7 @@ func (l *namingIdentifierNoKeywordListener) EnterId_expression(ctx *parser.Id_ex
Code: advisor.NameIsKeywordIdentifier.Int32(),
Title: l.title,
Content: fmt.Sprintf("Identifier %q is a keyword and should be avoided", identifier),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_naming_table.go b/backend/plugin/advisor/oracle/advisor_naming_table.go
index 037d51eee7..4ff9c5788e 100644
--- a/backend/plugin/advisor/oracle/advisor_naming_table.go
+++ b/backend/plugin/advisor/oracle/advisor_naming_table.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -83,7 +84,7 @@ func (l *namingTableListener) EnterCreate_table(ctx *parser.Create_tableContext)
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf(`"%s" mismatches table naming convention, naming format should be %q`, tableName, l.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
if l.maxLength > 0 && len(tableName) > l.maxLength {
@@ -92,7 +93,7 @@ func (l *namingTableListener) EnterCreate_table(ctx *parser.Create_tableContext)
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf("\"%s\" mismatches table naming convention, its length should be within %d characters", tableName, l.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
@@ -112,7 +113,7 @@ func (l *namingTableListener) EnterAlter_table_properties(ctx *parser.Alter_tabl
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf(`"%s" mismatches table naming convention, naming format should be %q`, tableName, l.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
if l.maxLength > 0 && len(tableName) > l.maxLength {
@@ -121,7 +122,7 @@ func (l *namingTableListener) EnterAlter_table_properties(ctx *parser.Alter_tabl
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf("\"%s\" mismatches table naming convention, its length should be within %d characters", tableName, l.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_naming_table_no_keyword.go b/backend/plugin/advisor/oracle/advisor_naming_table_no_keyword.go
index 43c10483c7..9bee3df118 100644
--- a/backend/plugin/advisor/oracle/advisor_naming_table_no_keyword.go
+++ b/backend/plugin/advisor/oracle/advisor_naming_table_no_keyword.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
plsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/plsql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -74,7 +75,7 @@ func (l *namingTableNoKeywordListener) EnterCreate_table(ctx *parser.Create_tabl
Code: advisor.NameIsKeywordIdentifier.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table name %q is a keyword identifier and should be avoided.", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
@@ -91,7 +92,7 @@ func (l *namingTableNoKeywordListener) EnterAlter_table_properties(ctx *parser.A
Code: advisor.NameIsKeywordIdentifier.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table name %q is a keyword identifier and should be avoided.", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_select_no_select_all.go b/backend/plugin/advisor/oracle/advisor_select_no_select_all.go
index f14b6cce66..174c658f58 100644
--- a/backend/plugin/advisor/oracle/advisor_select_no_select_all.go
+++ b/backend/plugin/advisor/oracle/advisor_select_no_select_all.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -71,7 +72,7 @@ func (l *selectNoSelectAllListener) EnterSelected_list(ctx *parser.Selected_list
Code: advisor.StatementSelectAll.Int32(),
Title: l.title,
Content: "Avoid using SELECT *.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_statement_disallow_mix_in_ddl.go b/backend/plugin/advisor/oracle/advisor_statement_disallow_mix_in_ddl.go
index 61b01e3fc9..c60a816f1f 100644
--- a/backend/plugin/advisor/oracle/advisor_statement_disallow_mix_in_ddl.go
+++ b/backend/plugin/advisor/oracle/advisor_statement_disallow_mix_in_ddl.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/plsql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -51,7 +52,7 @@ func (*StatementDisallowMixInDDLAdvisor) Check(_ context.Context, checkCtx advis
Title: title,
Content: "Alter schema can only run DDL",
Code: advisor.StatementDisallowMixDDLDML.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_statement_disallow_mix_in_dml.go b/backend/plugin/advisor/oracle/advisor_statement_disallow_mix_in_dml.go
index 2648002c0e..6c285f2f59 100644
--- a/backend/plugin/advisor/oracle/advisor_statement_disallow_mix_in_dml.go
+++ b/backend/plugin/advisor/oracle/advisor_statement_disallow_mix_in_dml.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/plsql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -52,7 +53,7 @@ func (*StatementDisallowMixInDMLAdvisor) Check(_ context.Context, checkCtx advis
Title: title,
Content: "Data change can only run DML",
Code: advisor.StatementDisallowMixDDLDML.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_statement_dml_dry_run.go b/backend/plugin/advisor/oracle/advisor_statement_dml_dry_run.go
index 3317663e9a..9fc873bad0 100644
--- a/backend/plugin/advisor/oracle/advisor_statement_dml_dry_run.go
+++ b/backend/plugin/advisor/oracle/advisor_statement_dml_dry_run.go
@@ -98,7 +98,7 @@ func (s *statementDmlDryRunChecker) handleStmt(text string, lineNumber int) {
Code: advisor.StatementDMLDryRunFailed.Int32(),
Title: s.title,
Content: fmt.Sprintf("Failed to dry run statement at line %d: %v", lineNumber, err),
- StartPosition: advisor.ConvertANTLRLineToPosition(lineNumber),
+ StartPosition: common.ConvertANTLRLineToPosition(lineNumber),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_table_comment_convention.go b/backend/plugin/advisor/oracle/advisor_table_comment_convention.go
index 4f45159e5f..7430983795 100644
--- a/backend/plugin/advisor/oracle/advisor_table_comment_convention.go
+++ b/backend/plugin/advisor/oracle/advisor_table_comment_convention.go
@@ -105,7 +105,7 @@ func (l *tableCommentConventionListener) generateAdvices() ([]*storepb.Advice, e
Code: advisor.CommentEmpty.Int32(),
Title: l.title,
Content: fmt.Sprintf("Comment is required for table %s", normalizeIdentifierName(tableName)),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.tableLine[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.tableLine[tableName]),
})
}
} else {
@@ -115,7 +115,7 @@ func (l *tableCommentConventionListener) generateAdvices() ([]*storepb.Advice, e
Code: advisor.CommentTooLong.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %s comment is too long. The length of comment should be within %d characters", normalizeIdentifierName(tableName), l.payload.MaxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.tableLine[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.tableLine[tableName]),
})
}
if l.payload.RequiredClassification {
@@ -125,7 +125,7 @@ func (l *tableCommentConventionListener) generateAdvices() ([]*storepb.Advice, e
Code: advisor.CommentMissingClassification.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %s comment requires classification", normalizeIdentifierName(tableName)),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.tableLine[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.tableLine[tableName]),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_table_no_foreign_key.go b/backend/plugin/advisor/oracle/advisor_table_no_foreign_key.go
index 0ff070af3e..e3ca602c04 100644
--- a/backend/plugin/advisor/oracle/advisor_table_no_foreign_key.go
+++ b/backend/plugin/advisor/oracle/advisor_table_no_foreign_key.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -73,7 +74,7 @@ func (l *tableNoForeignKeyListener) generateAdvice() ([]*storepb.Advice, error)
Code: advisor.TableHasFK.Int32(),
Title: l.title,
Content: fmt.Sprintf("Foreign key is not allowed in the table %s.", normalizeIdentifierName(tableName)),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.tableLine[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.tableLine[tableName]),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_table_require_pk.go b/backend/plugin/advisor/oracle/advisor_table_require_pk.go
index 965826a0cc..6f254f8da9 100644
--- a/backend/plugin/advisor/oracle/advisor_table_require_pk.go
+++ b/backend/plugin/advisor/oracle/advisor_table_require_pk.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -73,7 +74,7 @@ func (l *TableRequirePKListener) generateAdvice() ([]*storepb.Advice, error) {
Code: advisor.TableNoPK.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %s requires PRIMARY KEY.", normalizeIdentifierName(tableName)),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.tableLine[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.tableLine[tableName]),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_where_no_leading_wildcard_like.go b/backend/plugin/advisor/oracle/advisor_where_no_leading_wildcard_like.go
index 85049d336e..17b415225e 100644
--- a/backend/plugin/advisor/oracle/advisor_where_no_leading_wildcard_like.go
+++ b/backend/plugin/advisor/oracle/advisor_where_no_leading_wildcard_like.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -81,7 +82,7 @@ func (l *whereNoLeadingWildcardLikeListener) EnterCompound_expression(ctx *parse
Code: advisor.StatementLeadingWildcardLike.Int32(),
Title: l.title,
Content: "Avoid using leading wildcard LIKE.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_where_require_for_select.go b/backend/plugin/advisor/oracle/advisor_where_require_for_select.go
index a0f2fc5241..ee4cc66f27 100644
--- a/backend/plugin/advisor/oracle/advisor_where_require_for_select.go
+++ b/backend/plugin/advisor/oracle/advisor_where_require_for_select.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -79,7 +80,7 @@ func (l *whereRequireForSelectListener) EnterQuery_block(ctx *parser.Query_block
Code: advisor.StatementNoWhere.Int32(),
Title: l.title,
Content: "WHERE clause is required for SELECT statement.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStop().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStop().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/oracle/advisor_where_require_for_update_delete.go b/backend/plugin/advisor/oracle/advisor_where_require_for_update_delete.go
index a0cc394189..598c107974 100644
--- a/backend/plugin/advisor/oracle/advisor_where_require_for_update_delete.go
+++ b/backend/plugin/advisor/oracle/advisor_where_require_for_update_delete.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/plsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -71,7 +72,7 @@ func (l *whereRequireForUpdateDeleteListener) EnterUpdate_statement(ctx *parser.
Code: advisor.StatementNoWhere.Int32(),
Title: l.title,
Content: "WHERE clause is required for UPDATE statement.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStop().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStop().GetLine()),
})
}
}
@@ -84,7 +85,7 @@ func (l *whereRequireForUpdateDeleteListener) EnterDelete_statement(ctx *parser.
Code: advisor.StatementNoWhere.Int32(),
Title: l.title,
Content: "WHERE clause is required for DELETE statement.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStop().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(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.go
index 8aa4c3eb93..47b976c778 100644
--- a/backend/plugin/advisor/pg/advisor_builtin_prior_backup_check.go
+++ b/backend/plugin/advisor/pg/advisor_builtin_prior_backup_check.go
@@ -13,6 +13,7 @@ import (
parser "github.com/bytebase/postgresql-parser"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/pg"
@@ -60,7 +61,7 @@ func (*BuiltinPriorBackupCheckAdvisor) Check(_ context.Context, checkCtx advisor
Title: title,
Content: fmt.Sprintf("Data change can only run DML, \"%s\" is not DML", stmt.Text()),
Code: advisor.BuiltinPriorBackupCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
@@ -72,7 +73,7 @@ func (*BuiltinPriorBackupCheckAdvisor) Check(_ context.Context, checkCtx advisor
Title: title,
Content: fmt.Sprintf("Need schema %q to do prior backup but it does not exist", name),
Code: advisor.SchemaNotExists.Int32(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
}
@@ -100,7 +101,7 @@ func (*BuiltinPriorBackupCheckAdvisor) Check(_ context.Context, checkCtx advisor
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(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
break
}
diff --git a/backend/plugin/advisor/pg/advisor_collation_allowlist.go b/backend/plugin/advisor/pg/advisor_collation_allowlist.go
index 5eb434c19c..7cfae3f0cf 100644
--- a/backend/plugin/advisor/pg/advisor_collation_allowlist.go
+++ b/backend/plugin/advisor/pg/advisor_collation_allowlist.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -120,7 +121,7 @@ func (checker *collationAllowlistChecker) Visit(in ast.Node) ast.Visitor {
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Use disabled collation \"%s\", related statement \"%s\"", disabledCollation, checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_column_comment_convention.go b/backend/plugin/advisor/pg/advisor_column_comment_convention.go
index 24ffef6a13..e4811b2cce 100644
--- a/backend/plugin/advisor/pg/advisor_column_comment_convention.go
+++ b/backend/plugin/advisor/pg/advisor_column_comment_convention.go
@@ -69,7 +69,7 @@ func (*ColumnCommentConventionAdvisor) Check(_ context.Context, checkCtx advisor
Code: advisor.CommentEmpty.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Comment is required for column `%s`", stringifyColumnNameDef(columnName)),
- StartPosition: advisor.ConvertANTLRLineToPosition(columnName.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(columnName.LastLine()),
})
}
} else {
@@ -80,7 +80,7 @@ func (*ColumnCommentConventionAdvisor) Check(_ context.Context, checkCtx advisor
Code: advisor.CommentTooLong.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s` comment is too long. The length of comment should be within %d characters", stringifyColumnNameDef(columnName), checker.payload.MaxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(commentStmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(commentStmt.LastLine()),
})
}
if checker.payload.RequiredClassification {
@@ -90,7 +90,7 @@ func (*ColumnCommentConventionAdvisor) Check(_ context.Context, checkCtx advisor
Code: advisor.CommentMissingClassification.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s` comment requires classification", stringifyColumnNameDef(columnName)),
- StartPosition: advisor.ConvertANTLRLineToPosition(commentStmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(commentStmt.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_column_default_disallow_volatile.go b/backend/plugin/advisor/pg/advisor_column_default_disallow_volatile.go
index 71b3f3dadf..c0bb3d6fa0 100644
--- a/backend/plugin/advisor/pg/advisor_column_default_disallow_volatile.go
+++ b/backend/plugin/advisor/pg/advisor_column_default_disallow_volatile.go
@@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -78,7 +79,7 @@ func (checker *columnDefaultDisallowVolatileChecker) generateAdvice() []*storepb
Code: advisor.NoDefault.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column %q.%q in schema %q has volatile DEFAULT", column.table, column.name, column.schema),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.go b/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.go
index 133fb94a37..09a484f475 100644
--- a/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.go
+++ b/backend/plugin/advisor/pg/advisor_column_disallow_changing_type.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -72,7 +73,7 @@ func (checker *columnDisallowChangingTypeChecker) Visit(in ast.Node) ast.Visitor
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The statement \"%s\" changes column type", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_column_maximum_character_length.go b/backend/plugin/advisor/pg/advisor_column_maximum_character_length.go
index b1eacaa62a..2fa37ae6ea 100644
--- a/backend/plugin/advisor/pg/advisor_column_maximum_character_length.go
+++ b/backend/plugin/advisor/pg/advisor_column_maximum_character_length.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -111,7 +112,7 @@ func (checker *columnMaximumCharacterLengthChecker) Visit(in ast.Node) ast.Visit
Code: advisor.CharLengthExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf(`The length of the CHAR column %q in table %s is bigger than %d, please use VARCHAR instead`, columnName, tableName, checker.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_column_no_null.go b/backend/plugin/advisor/pg/advisor_column_no_null.go
index d706e39012..255e73a7c0 100644
--- a/backend/plugin/advisor/pg/advisor_column_no_null.go
+++ b/backend/plugin/advisor/pg/advisor_column_no_null.go
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -83,7 +84,7 @@ func (checker *columnNoNullChecker) generateAdviceList() []*storepb.Advice {
Code: advisor.ColumnCannotNull.Int32(),
Title: checker.title,
Content: fmt.Sprintf(`Column "%s" in %s cannot have NULL value`, column.column, column.normalizeTableName()),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.nullableColumns[column]),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.nullableColumns[column]),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_column_require_default.go b/backend/plugin/advisor/pg/advisor_column_require_default.go
index 1d7f513d1c..819b84dc4e 100644
--- a/backend/plugin/advisor/pg/advisor_column_require_default.go
+++ b/backend/plugin/advisor/pg/advisor_column_require_default.go
@@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -91,7 +92,7 @@ func (checker *columnRequireDefaultChecker) generateAdvice() []*storepb.Advice {
Code: advisor.NoDefault.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column %q.%q in schema %q doesn't have DEFAULT", column.table, column.name, column.schema),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_column_required.go b/backend/plugin/advisor/pg/advisor_column_required.go
index 883b9a70d6..4a49758d47 100644
--- a/backend/plugin/advisor/pg/advisor_column_required.go
+++ b/backend/plugin/advisor/pg/advisor_column_required.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -106,7 +107,7 @@ func (checker *columnRequirementChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.NoRequiredColumn.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table %q requires columns: %s", table.Name, strings.Join(missingColumns, ", ")),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_column_type_disallow_list.go b/backend/plugin/advisor/pg/advisor_column_type_disallow_list.go
index 7cad696442..c246b19755 100644
--- a/backend/plugin/advisor/pg/advisor_column_type_disallow_list.go
+++ b/backend/plugin/advisor/pg/advisor_column_type_disallow_list.go
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -141,7 +142,7 @@ func (checker *columnTypeDisallowListChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.DisabledColumnType.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Disallow column type %s but column \"%s\".\"%s\" is", column.tp, column.table, column.column),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
return checker
diff --git a/backend/plugin/advisor/pg/advisor_comment_convention.go b/backend/plugin/advisor/pg/advisor_comment_convention.go
index 426f9c1cbd..56a177334c 100644
--- a/backend/plugin/advisor/pg/advisor_comment_convention.go
+++ b/backend/plugin/advisor/pg/advisor_comment_convention.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -82,7 +83,7 @@ func (checker *commentConventionChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.CommentTooLong.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The length of comment should be within %d characters", checker.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(comment.line),
+ StartPosition: common.ConvertANTLRLineToPosition(comment.line),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_encoding_allowlist.go b/backend/plugin/advisor/pg/advisor_encoding_allowlist.go
index 0a17292007..696054a45e 100644
--- a/backend/plugin/advisor/pg/advisor_encoding_allowlist.go
+++ b/backend/plugin/advisor/pg/advisor_encoding_allowlist.go
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -89,7 +90,7 @@ func (checker *encodingAllowlistChecker) Visit(in ast.Node) ast.Visitor {
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" used disabled encoding '%s'", checker.text, disabledEncoding),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_index_create_concurrently.go b/backend/plugin/advisor/pg/advisor_index_create_concurrently.go
index 39b3c2e3dd..0b89d86589 100644
--- a/backend/plugin/advisor/pg/advisor_index_create_concurrently.go
+++ b/backend/plugin/advisor/pg/advisor_index_create_concurrently.go
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -64,7 +65,7 @@ func (checker *indexCreateConcurrentlyChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.CreateIndexUnconcurrently.Int32(),
Title: checker.title,
Content: "Creating indexes will block writes on the table, unless use CONCURRENTLY",
- StartPosition: advisor.ConvertANTLRLineToPosition(in.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(in.LastLine()),
})
}
case *ast.DropIndexStmt:
@@ -74,7 +75,7 @@ func (checker *indexCreateConcurrentlyChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.DropIndexUnconcurrently.Int32(),
Title: checker.title,
Content: "Droping indexes will block writes on the table, unless use CONCURRENTLY",
- StartPosition: advisor.ConvertANTLRLineToPosition(in.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(in.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_index_key_number_limit.go b/backend/plugin/advisor/pg/advisor_index_key_number_limit.go
index edf3e950c9..1e5d8817bb 100644
--- a/backend/plugin/advisor/pg/advisor_index_key_number_limit.go
+++ b/backend/plugin/advisor/pg/advisor_index_key_number_limit.go
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -104,7 +105,7 @@ func (checker *indexKeyNumberLimitChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.IndexKeyNumberExceedsLimit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The number of keys of index %q in table %q should be not greater than %d", index.indexName, index.tableName, checker.max),
- StartPosition: advisor.ConvertANTLRLineToPosition(index.line),
+ StartPosition: common.ConvertANTLRLineToPosition(index.line),
})
}
return checker
diff --git a/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.go b/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.go
index 3f81e87b68..7a661fe2b2 100644
--- a/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.go
+++ b/backend/plugin/advisor/pg/advisor_index_no_duplicate_column.go
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -124,7 +125,7 @@ func (checker *indexNoDuplicateColumnChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.DuplicateColumnInIndex.Int32(),
Title: checker.title,
Content: fmt.Sprintf("%s \"%s\" has duplicate column \"%s\".\"%s\"", column.constraintType, column.index, column.table, column.column),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
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.go
index d90fd75079..4df5dcc839 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
@@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
pgrawparser "github.com/bytebase/bytebase/backend/plugin/parser/sql/engine/pg"
@@ -99,7 +100,7 @@ func (checker *indexPrimaryKeyTypeAllowlistChecker) Visit(in ast.Node) ast.Visit
Code: advisor.IndexPKType.Int32(),
Title: checker.title,
Content: fmt.Sprintf(`The column "%s" is one of the primary key, but its type "%s" is not in allowlist`, column.ColumnName, typeText),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(column.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_index_total_number_limit.go b/backend/plugin/advisor/pg/advisor_index_total_number_limit.go
index 32998a5f5e..0a4884c197 100644
--- a/backend/plugin/advisor/pg/advisor_index_total_number_limit.go
+++ b/backend/plugin/advisor/pg/advisor_index_total_number_limit.go
@@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -108,7 +109,7 @@ func (checker *indexTotalNumberLimitChecker) generateAdvice() []*storepb.Advice
Code: advisor.IndexCountExceedsLimit.Int32(),
Title: checker.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, checker.max, tableInfo.CountIndex()),
- StartPosition: advisor.ConvertANTLRLineToPosition(table.line),
+ StartPosition: common.ConvertANTLRLineToPosition(table.line),
})
}
}
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.go
index 10fe545f5f..10d115de57 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
@@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -77,7 +78,7 @@ func (checker *insertDisallowOrderByRandChecker) Visit(in ast.Node) ast.Visitor
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The INSERT statement uses ORDER BY random() or random_between(), related statement \"%s\"", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(in.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(in.LastLine()),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_insert_must_specify_column.go b/backend/plugin/advisor/pg/advisor_insert_must_specify_column.go
index b35511babb..7e0c4302ab 100644
--- a/backend/plugin/advisor/pg/advisor_insert_must_specify_column.go
+++ b/backend/plugin/advisor/pg/advisor_insert_must_specify_column.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -65,7 +66,7 @@ func (checker *insertMustSpecifyColumnChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.InsertNotSpecifyColumn.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The INSERT statement must specify columns but \"%s\" does not", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_insert_row_limit.go b/backend/plugin/advisor/pg/advisor_insert_row_limit.go
index ea3e3cb867..6d177b5610 100644
--- a/backend/plugin/advisor/pg/advisor_insert_row_limit.go
+++ b/backend/plugin/advisor/pg/advisor_insert_row_limit.go
@@ -110,7 +110,7 @@ func (checker *insertRowLimitChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.InsertTooManyRows.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" dry runs failed: %s", checker.text, err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
} else {
rowCount, err := getAffectedRows(res)
@@ -120,7 +120,7 @@ func (checker *insertRowLimitChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.Internal.Int32(),
Title: checker.title,
Content: fmt.Sprintf("failed to get row count for \"%s\": %s", checker.text, err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
} else if rowCount > int64(checker.maxRow) {
code = advisor.InsertTooManyRows
@@ -136,7 +136,7 @@ func (checker *insertRowLimitChecker) Visit(node ast.Node) ast.Visitor {
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The statement \"%s\" inserts %d rows. The count exceeds %d.", checker.text, rows, checker.maxRow),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
return checker
diff --git a/backend/plugin/advisor/pg/advisor_migration_compatibility.go b/backend/plugin/advisor/pg/advisor_migration_compatibility.go
index 873917a696..3e03d75418 100644
--- a/backend/plugin/advisor/pg/advisor_migration_compatibility.go
+++ b/backend/plugin/advisor/pg/advisor_migration_compatibility.go
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -121,7 +122,7 @@ func (checker *compatibilityChecker) Visit(node ast.Node) ast.Visitor {
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" may cause incompatibility with the existing data and code", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
return checker
diff --git a/backend/plugin/advisor/pg/advisor_naming_column.go b/backend/plugin/advisor/pg/advisor_naming_column.go
index 1aaa72be82..71e9181b96 100644
--- a/backend/plugin/advisor/pg/advisor_naming_column.go
+++ b/backend/plugin/advisor/pg/advisor_naming_column.go
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -107,7 +108,7 @@ func (checker *namingColumnConventionChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.NamingColumnConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\".\"%s\" mismatches column naming convention, naming format should be %q", tableName, column.name, checker.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
@@ -117,7 +118,7 @@ func (checker *namingColumnConventionChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.NamingColumnConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\".\"%s\" mismatches column naming convention, its length should be within %d characters", tableName, column.name, checker.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.go
index ec92743996..4bf74db83d 100644
--- a/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.go
+++ b/backend/plugin/advisor/pg/advisor_naming_foreign_key_convention.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -95,7 +96,7 @@ func (checker *namingFKConventionChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {
@@ -104,7 +105,7 @@ func (checker *namingFKConventionChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_naming_fully_qualified.go b/backend/plugin/advisor/pg/advisor_naming_fully_qualified.go
index ddb834f76e..c6cf03c8d4 100644
--- a/backend/plugin/advisor/pg/advisor_naming_fully_qualified.go
+++ b/backend/plugin/advisor/pg/advisor_naming_fully_qualified.go
@@ -10,6 +10,7 @@ import (
pgquery "github.com/pganalyze/pg_query_go/v6"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/base"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -169,7 +170,7 @@ func (checker *FullyQualifiedObjectNameChecker) appendAdviceByObjName(objName st
Code: advisor.NamingNotFullyQualifiedName,
Title: checker.title,
Content: fmt.Sprintf("unqualified object name: '%s'", objName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_naming_index_convention.go b/backend/plugin/advisor/pg/advisor_naming_index_convention.go
index 0f24daf3db..0e196963e2 100644
--- a/backend/plugin/advisor/pg/advisor_naming_index_convention.go
+++ b/backend/plugin/advisor/pg/advisor_naming_index_convention.go
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -89,7 +90,7 @@ func (checker *namingIndexConventionChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.NamingIndexConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Index in table %q mismatches the naming convention, expect %q but found %q", indexData.tableName, regex, indexData.indexName),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {
@@ -98,7 +99,7 @@ func (checker *namingIndexConventionChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.NamingIndexConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Index %q in table %q mismatches the naming convention, its length should be within %d characters", indexData.indexName, indexData.tableName, checker.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go
index ed07bb5f84..2fd512445e 100644
--- a/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go
+++ b/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -90,7 +91,7 @@ func (checker *namingPKConventionChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.NamingPKConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf(`Primary key in table "%s" mismatches the naming convention, expect %q but found "%s"`, indexData.tableName, regex, indexData.indexName),
- StartPosition: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {
@@ -99,7 +100,7 @@ func (checker *namingPKConventionChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.NamingPKConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf(`Primary key "%s" in table "%s" mismatches the naming convention, its length should be within %d characters`, indexData.indexName, indexData.tableName, checker.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_naming_table.go b/backend/plugin/advisor/pg/advisor_naming_table.go
index b4bccf0181..22431c75f7 100644
--- a/backend/plugin/advisor/pg/advisor_naming_table.go
+++ b/backend/plugin/advisor/pg/advisor_naming_table.go
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -83,7 +84,7 @@ func (checker *namingTableConventionChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf(`"%s" mismatches table naming convention, naming format should be %q`, tableName, checker.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
if checker.maxLength > 0 && len(tableName) > checker.maxLength {
@@ -92,7 +93,7 @@ func (checker *namingTableConventionChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" mismatches table naming convention, its length should be within %d characters", tableName, checker.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go
index 63d0c8fbc5..e0abe8e70b 100644
--- a/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go
+++ b/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -90,7 +91,7 @@ func (checker *namingUKConventionChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {
@@ -99,7 +100,7 @@ func (checker *namingUKConventionChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
}
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.go
index 0d2074e1a7..c9e197f5f0 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
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -65,7 +66,7 @@ func (checker *statementAddCheckNotValidChecker) Visit(in ast.Node) ast.Visitor
Code: advisor.StatementAddCheckWithValidation.Int32(),
Title: checker.title,
Content: "Adding check constraints with validation will block reads and writes. You can add check constraints not valid and then validate separately",
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
}
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.go
index 442e295b69..3086c418e4 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
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -65,7 +66,7 @@ func (checker *statementAddFKNotValidChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.StatementAddFKWithValidation.Int32(),
Title: checker.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: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.go b/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.go
index 9d9e348979..f3d5c6e281 100644
--- a/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.go
+++ b/backend/plugin/advisor/pg/advisor_statement_affected_row_limit.go
@@ -99,7 +99,7 @@ func (checker *statementAffectedRowLimitChecker) Visit(in ast.Node) ast.Visitor
Code: advisor.InsertTooManyRows.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" dry runs failed: %s", checker.text, err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
} else {
rowCount, err := getAffectedRows(res)
@@ -109,7 +109,7 @@ func (checker *statementAffectedRowLimitChecker) Visit(in ast.Node) ast.Visitor
Code: advisor.Internal.Int32(),
Title: checker.title,
Content: fmt.Sprintf("failed to get row count for \"%s\": %s", checker.text, err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
} else if rowCount > int64(checker.maxRow) {
code = advisor.StatementAffectedRowExceedsLimit
@@ -124,7 +124,7 @@ func (checker *statementAffectedRowLimitChecker) Visit(in ast.Node) ast.Visitor
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The statement \"%s\" affected %d rows (estimated). The count exceeds %d.", checker.text, rows, checker.maxRow),
- StartPosition: advisor.ConvertANTLRLineToPosition(in.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(in.LastLine()),
})
}
return checker
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.go
index 5a992ee761..e3a6911ffc 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
@@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -53,7 +54,7 @@ func (*StatementCheckSetRoleVariable) Check(_ context.Context, checkCtx advisor.
Code: advisor.StatementCheckSetRoleVariable.Int32(),
Title: string(checkCtx.Rule.Type),
Content: "No SET ROLE statement found.",
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
}}, nil
}
diff --git a/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.go b/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.go
index 73a2fc863e..64c705982c 100644
--- a/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.go
+++ b/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.go
@@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -59,7 +60,7 @@ func (c *statementCreateSpecifySchemaChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.StatementCreateWithoutSchemaName.Int32(),
Title: c.title,
Content: "Table schema should be specified.",
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
case *ast.CreateExtensionStmt:
@@ -69,7 +70,7 @@ func (c *statementCreateSpecifySchemaChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.StatementCreateWithoutSchemaName.Int32(),
Title: c.title,
Content: "Extension schema should be specified.",
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
case *ast.CreateFunctionStmt:
@@ -79,7 +80,7 @@ func (c *statementCreateSpecifySchemaChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.StatementCreateWithoutSchemaName.Int32(),
Title: c.title,
Content: "Function schema should be specified.",
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
case *ast.CreateIndexStmt:
@@ -89,7 +90,7 @@ func (c *statementCreateSpecifySchemaChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.StatementCreateWithoutSchemaName.Int32(),
Title: c.title,
Content: "Table schema for index should be specified.",
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
case *ast.CreateSequenceStmt:
@@ -99,7 +100,7 @@ func (c *statementCreateSpecifySchemaChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.StatementCreateWithoutSchemaName.Int32(),
Title: c.title,
Content: "Sequence schema should be specified.",
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
case *ast.CreateTriggerStmt:
@@ -109,7 +110,7 @@ func (c *statementCreateSpecifySchemaChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.StatementCreateWithoutSchemaName.Int32(),
Title: c.title,
Content: "Table schema for trigger should be specified.",
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
}
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.go
index 75509ee0e6..968ca0c3e5 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
@@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -66,7 +67,7 @@ func (checker *statementDisallowAddColumnWithDefaultChecker) Visit(in ast.Node)
Code: advisor.StatementAddColumnWithDefault.Int32(),
Title: checker.title,
Content: "Adding column with DEFAULT will locked the whole table and rewriting each rows",
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
}
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.go
index 7a39c7ef82..2d3c62f839 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
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -65,7 +66,7 @@ func (checker *statementDisallowAddNotNullChecker) Visit(in ast.Node) ast.Visito
Code: advisor.StatementAddNotNull.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Setting NOT NULL will block reads and writes. You can use CHECK (%q IS NOT NULL) instead", node.ColumnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_statement_disallow_commit.go b/backend/plugin/advisor/pg/advisor_statement_disallow_commit.go
index ffe83b16bf..6f98417808 100644
--- a/backend/plugin/advisor/pg/advisor_statement_disallow_commit.go
+++ b/backend/plugin/advisor/pg/advisor_statement_disallow_commit.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -63,7 +64,7 @@ func (checker *statementDisallowCommitChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.StatementDisallowCommit.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Commit is not allowed, related statement: \"%s\"", in.Text()),
- StartPosition: advisor.ConvertANTLRLineToPosition(in.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(in.LastLine()),
})
}
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.go
index 654e57f49a..ca89f849ee 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 (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -51,7 +52,7 @@ func (*StatementDisallowMixInDDLAdvisor) Check(_ context.Context, checkCtx advis
Title: title,
Content: fmt.Sprintf("Alter schema can only run DDL, \"%s\" is not DDL", stmt.Text()),
Code: advisor.StatementDisallowMixDDLDML.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
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.go
index 014b4f3cab..930360715e 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
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -51,7 +52,7 @@ func (*StatementDisallowMixInDMLAdvisor) Check(_ context.Context, checkCtx advis
Title: title,
Content: fmt.Sprintf("Data change can only run DML, \"%s\" is not DML", stmt.Text()),
Code: advisor.StatementDisallowMixDDLDML.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.go b/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.go
index cafb4884da..7a9b6e5e57 100644
--- a/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.go
+++ b/backend/plugin/advisor/pg/advisor_statement_dml_dry_run.go
@@ -88,7 +88,7 @@ func (checker *statementDmlDryRunChecker) Visit(in ast.Node) ast.Visitor {
Code: advisor.StatementDMLDryRunFailed.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" dry runs failed: %s", node.Text(), err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_statement_maximum_limit_value.go b/backend/plugin/advisor/pg/advisor_statement_maximum_limit_value.go
index 19a2530a37..39b9b53e16 100644
--- a/backend/plugin/advisor/pg/advisor_statement_maximum_limit_value.go
+++ b/backend/plugin/advisor/pg/advisor_statement_maximum_limit_value.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -72,7 +73,7 @@ func (checker *statementMaximumLimitValueChecker) Visit(in ast.Node) ast.Visitor
Code: advisor.StatementExceedMaximumLimitValue.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The limit value %d exceeds the maximum allowed value %d", *node.Limit, checker.limitMaxValue),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.go b/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.go
index d7ec868feb..6896120b93 100644
--- a/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.go
+++ b/backend/plugin/advisor/pg/advisor_statement_merge_alter_table.go
@@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -66,7 +67,7 @@ func (checker *statementMergeAlterTableChecker) generateAdvice() []*storepb.Advi
Code: advisor.StatementRedundantAlterTable.Int32(),
Title: checker.title,
Content: fmt.Sprintf("There are %d statements to modify table `%s`", table.count, table.name),
- StartPosition: advisor.ConvertANTLRLineToPosition(table.line),
+ StartPosition: common.ConvertANTLRLineToPosition(table.line),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_statement_non_transactional.go b/backend/plugin/advisor/pg/advisor_statement_non_transactional.go
index 3a56a94039..4fbf4f8793 100644
--- a/backend/plugin/advisor/pg/advisor_statement_non_transactional.go
+++ b/backend/plugin/advisor/pg/advisor_statement_non_transactional.go
@@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/db/pg"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -46,7 +47,7 @@ func (*NonTransactionalAdvisor) Check(_ context.Context, checkCtx advisor.Contex
Code: advisor.StatementNonTransactional.Int32(),
Title: checker.title,
Content: "This statement is non-transactional",
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go b/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go
index a01761bac2..28813bd580 100644
--- a/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go
+++ b/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -83,7 +84,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Sequence \"%s\" is owned by \"%s\", but the current role is \"%s\".", n.Name.Name, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.AlterTableStmt:
@@ -112,7 +113,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Table \"%s\" is owned by \"%s\", but the current role is \"%s\".", n.Table.Name, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.AlterTypeStmt:
@@ -138,7 +139,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Type \"%s\" is owned by \"%s\", but the current role is \"%s\".", n.Type.Name, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.CreateExtensionStmt:
@@ -160,7 +161,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.CreateFunctionStmt:
@@ -185,7 +186,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.CreateIndexStmt:
@@ -210,7 +211,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.CreateSchemaStmt:
@@ -221,7 +222,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Database \"%s\" is owned by \"%s\", but the current role is \"%s\".", dbMetadata.GetName(), owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.CreateSequenceStmt:
@@ -246,7 +247,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.CreateTableStmt:
@@ -271,7 +272,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.CreateTriggerStmt:
@@ -296,7 +297,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.CreateTypeStmt:
@@ -321,7 +322,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.CreateViewStmt:
@@ -346,7 +347,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.DropFunctionStmt:
@@ -372,7 +373,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
@@ -399,7 +400,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
@@ -419,7 +420,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
@@ -446,7 +447,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
@@ -479,7 +480,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Table \"%s\" is owned by \"%s\", but the current role is \"%s\".", table.Name, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
default:
@@ -494,7 +495,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
@@ -521,7 +522,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.DropTypeStmt:
@@ -547,7 +548,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
@@ -570,7 +571,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
case *ast.RenameSchemaStmt:
@@ -588,7 +589,7 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", n.Schema, owner, currentRole),
Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go b/backend/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go
index 8059255885..2072e31445 100644
--- a/backend/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go
+++ b/backend/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like.go
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -56,7 +57,7 @@ func (*NoLeadingWildcardLikeAdvisor) Check(_ context.Context, checkCtx advisor.C
Code: advisor.StatementLeadingWildcardLike.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" uses leading wildcard LIKE", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmt.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_stmt_no_select_all.go b/backend/plugin/advisor/pg/advisor_stmt_no_select_all.go
index c0d933e3f2..3a6e267813 100644
--- a/backend/plugin/advisor/pg/advisor_stmt_no_select_all.go
+++ b/backend/plugin/advisor/pg/advisor_stmt_no_select_all.go
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -67,7 +68,7 @@ func (checker *noSelectAllChecker) Visit(node ast.Node) ast.Visitor {
Code: advisor.StatementSelectAll.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" uses SELECT all", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
break
}
diff --git a/backend/plugin/advisor/pg/advisor_stmt_where_required_select.go b/backend/plugin/advisor/pg/advisor_stmt_where_required_select.go
index 9efdc56204..85e0c45bfa 100644
--- a/backend/plugin/advisor/pg/advisor_stmt_where_required_select.go
+++ b/backend/plugin/advisor/pg/advisor_stmt_where_required_select.go
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -73,7 +74,7 @@ func (checker *whereRequirementForSelectChecker) Visit(node ast.Node) ast.Visito
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" requires WHERE clause", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
return checker
diff --git a/backend/plugin/advisor/pg/advisor_stmt_where_required_update_delete.go b/backend/plugin/advisor/pg/advisor_stmt_where_required_update_delete.go
index 565252e6aa..0f076bd104 100644
--- a/backend/plugin/advisor/pg/advisor_stmt_where_required_update_delete.go
+++ b/backend/plugin/advisor/pg/advisor_stmt_where_required_update_delete.go
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -79,7 +80,7 @@ func (checker *whereRequirementForUpdateDeleteChecker) Visit(node ast.Node) ast.
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" requires WHERE clause", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
return checker
diff --git a/backend/plugin/advisor/pg/advisor_table_comment_convention.go b/backend/plugin/advisor/pg/advisor_table_comment_convention.go
index 73803e3250..a33784418f 100644
--- a/backend/plugin/advisor/pg/advisor_table_comment_convention.go
+++ b/backend/plugin/advisor/pg/advisor_table_comment_convention.go
@@ -69,7 +69,7 @@ func (*TableCommentConventionAdvisor) Check(_ context.Context, checkCtx advisor.
Code: advisor.CommentEmpty.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Comment is required for table `%s`", stringifyTableDef(createTableStmt.Name)),
- StartPosition: advisor.ConvertANTLRLineToPosition(createTableStmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(createTableStmt.LastLine()),
})
}
} else {
@@ -80,7 +80,7 @@ func (*TableCommentConventionAdvisor) Check(_ context.Context, checkCtx advisor.
Code: advisor.CommentTooLong.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table `%s` comment is too long. The length of comment should be within %d characters", stringifyTableDef(createTableStmt.Name), checker.payload.MaxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(commentStmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(commentStmt.LastLine()),
})
}
if checker.payload.RequiredClassification {
@@ -90,7 +90,7 @@ func (*TableCommentConventionAdvisor) Check(_ context.Context, checkCtx advisor.
Code: advisor.CommentMissingClassification.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table `%s` comment requires classification", stringifyTableDef(createTableStmt.Name)),
- StartPosition: advisor.ConvertANTLRLineToPosition(commentStmt.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(commentStmt.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_table_disallow_partition.go b/backend/plugin/advisor/pg/advisor_table_disallow_partition.go
index c6ecae7d4a..cd68b7931e 100644
--- a/backend/plugin/advisor/pg/advisor_table_disallow_partition.go
+++ b/backend/plugin/advisor/pg/advisor_table_disallow_partition.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -78,7 +79,7 @@ func (checker *tableDisallowPartitionChecker) Visit(in ast.Node) ast.Visitor {
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table partition is forbidden, but \"%s\" creates", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.go
index b616f6f5ef..5aeb5d6739 100644
--- a/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.go
+++ b/backend/plugin/advisor/pg/advisor_table_drop_naming_convention.go
@@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -73,7 +74,7 @@ func (checker *tableDropNamingConventionChecker) Visit(in ast.Node) ast.Visitor
Code: advisor.TableDropNamingConventionMismatch.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s` mismatches drop table naming convention, naming format should be %q", table.Name, checker.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
}
diff --git a/backend/plugin/advisor/pg/advisor_table_no_fk.go b/backend/plugin/advisor/pg/advisor_table_no_fk.go
index 5bb806d733..c88005bb34 100644
--- a/backend/plugin/advisor/pg/advisor_table_no_fk.go
+++ b/backend/plugin/advisor/pg/advisor_table_no_fk.go
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -88,7 +89,7 @@ func (checker *tableNoFKChecker) Visit(node ast.Node) ast.Visitor {
tableHasFK.Name,
checker.text,
),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
diff --git a/backend/plugin/advisor/pg/advisor_table_require_pk.go b/backend/plugin/advisor/pg/advisor_table_require_pk.go
index a019a966c0..4b054393fb 100644
--- a/backend/plugin/advisor/pg/advisor_table_require_pk.go
+++ b/backend/plugin/advisor/pg/advisor_table_require_pk.go
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
@@ -112,7 +113,7 @@ func (checker *tableRequirePKChecker) Visit(node ast.Node) ast.Visitor {
missingPK.Name,
checker.text,
),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.LastLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.LastLine()),
})
}
diff --git a/backend/plugin/advisor/snowflake/advisor_column_maximum_varchar_length.go b/backend/plugin/advisor/snowflake/advisor_column_maximum_varchar_length.go
index d75414ed31..0bef854bb3 100644
--- a/backend/plugin/advisor/snowflake/advisor_column_maximum_varchar_length.go
+++ b/backend/plugin/advisor/snowflake/advisor_column_maximum_varchar_length.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -98,7 +99,7 @@ func (l *columnMaximumVarcharLengthChecker) EnterData_type(ctx *parser.Data_type
Code: advisor.VarcharLengthExceedsLimit.Int32(),
Title: l.title,
Content: fmt.Sprintf("The maximum varchar length is %d.", l.maximum),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/snowflake/advisor_column_no_null.go b/backend/plugin/advisor/snowflake/advisor_column_no_null.go
index 89cb0ade2c..def3933d2d 100644
--- a/backend/plugin/advisor/snowflake/advisor_column_no_null.go
+++ b/backend/plugin/advisor/snowflake/advisor_column_no_null.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake"
"github.com/bytebase/bytebase/backend/plugin/advisor"
@@ -84,7 +85,7 @@ func (l *columnNoNullChecker) ExitCreate_table(*parser.Create_tableContext) {
Code: advisor.ColumnCannotNull.Int32(),
Title: l.title,
Content: fmt.Sprintf("Column %s is nullable, which is not allowed.", normalizedColumnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(columnNullableLine),
+ StartPosition: common.ConvertANTLRLineToPosition(columnNullableLine),
})
}
l.currentOriginalTableName = ""
@@ -140,7 +141,7 @@ func (l *columnNoNullChecker) ExitAlter_table(*parser.Alter_tableContext) {
Code: advisor.ColumnCannotNull.Int32(),
Title: l.title,
Content: fmt.Sprintf("Column %s is nullable, which is not allowed.", normalizedColumnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(columnNullableLine),
+ StartPosition: common.ConvertANTLRLineToPosition(columnNullableLine),
})
}
l.currentOriginalTableName = ""
@@ -185,7 +186,7 @@ func (l *columnNoNullChecker) ExitAlter_table_alter_column(*parser.Alter_table_a
Code: advisor.ColumnCannotNull.Int32(),
Title: l.title,
Content: fmt.Sprintf("After dropping NOT NULL of column %s, it will be nullable, which is not allowed.", normalizedColumnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(columnNullableLine),
+ StartPosition: common.ConvertANTLRLineToPosition(columnNullableLine),
})
}
l.currentOriginalTableName = ""
diff --git a/backend/plugin/advisor/snowflake/advisor_column_require.go b/backend/plugin/advisor/snowflake/advisor_column_require.go
index 557b81c35d..9375a24173 100644
--- a/backend/plugin/advisor/snowflake/advisor_column_require.go
+++ b/backend/plugin/advisor/snowflake/advisor_column_require.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -125,7 +126,7 @@ func (l *columnRequireChecker) ExitCreate_table(ctx *parser.Create_tableContext)
Code: advisor.NoRequiredColumn.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %s missing required column %q", l.currentOriginalTableName, column),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.Column_decl_item_list().GetStop().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.Column_decl_item_list().GetStop().GetLine()),
})
}
l.currentOriginalTableName = ""
@@ -171,7 +172,7 @@ func (l *columnRequireChecker) ExitAlter_table(ctx *parser.Alter_tableContext) {
Code: advisor.NoRequiredColumn.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %s missing required column %q", l.currentOriginalTableName, column),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.Table_column_action().GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.Table_column_action().GetStart().GetLine()),
})
}
l.currentOriginalTableName = ""
diff --git a/backend/plugin/advisor/snowflake/advisor_migration_compatibility.go b/backend/plugin/advisor/snowflake/advisor_migration_compatibility.go
index e645d82c99..6b78f38dcf 100644
--- a/backend/plugin/advisor/snowflake/advisor_migration_compatibility.go
+++ b/backend/plugin/advisor/snowflake/advisor_migration_compatibility.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -118,7 +119,7 @@ func (l *migrationCompatibilityChecker) EnterDrop_table(ctx *parser.Drop_tableCo
Code: advisor.CompatibilityDropTable.Int32(),
Title: l.title,
Content: fmt.Sprintf("Drop table %q may cause incompatibility with the existing data and code", normalizedFullDropTableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
@@ -138,7 +139,7 @@ func (l *migrationCompatibilityChecker) EnterDrop_schema(ctx *parser.Drop_schema
Code: advisor.CompatibilityDropSchema.Int32(),
Title: l.title,
Content: fmt.Sprintf("Drop schema %q may cause incompatibility with the existing data and code", normalizedFullDropSchemaName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
@@ -158,7 +159,7 @@ func (l *migrationCompatibilityChecker) EnterDrop_database(ctx *parser.Drop_data
Code: advisor.CompatibilityDropDatabase.Int32(),
Title: l.title,
Content: fmt.Sprintf("Drop database %q may cause incompatibility with the existing data and code", normalizedFullDropDatabaseName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
@@ -182,6 +183,6 @@ func (l *migrationCompatibilityChecker) EnterAlter_table(ctx *parser.Alter_table
Code: advisor.CompatibilityDropColumn.Int32(),
Title: l.title,
Content: fmt.Sprintf("Drop column %s may cause incompatibility with the existing data and code", strings.Join(normalizedAllColumnNames, ",")),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
diff --git a/backend/plugin/advisor/snowflake/advisor_naming_identifier_case.go b/backend/plugin/advisor/snowflake/advisor_naming_identifier_case.go
index fdcceca1b2..a72cc5b54e 100644
--- a/backend/plugin/advisor/snowflake/advisor_naming_identifier_case.go
+++ b/backend/plugin/advisor/snowflake/advisor_naming_identifier_case.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -109,7 +110,7 @@ func (l *namingIdentifierCaseChecker) EnterColumn_decl_item_list(ctx *parser.Col
Code: advisor.NamingCaseMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf("Identifier %q should be upper case", originalColName),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
@@ -130,7 +131,7 @@ func (l *namingIdentifierCaseChecker) EnterAlter_table(ctx *parser.Alter_tableCo
Code: advisor.NamingCaseMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf("Identifier %q should be upper case", renameToColName),
- StartPosition: advisor.ConvertANTLRLineToPosition(renameToID.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(renameToID.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/snowflake/advisor_naming_identifier_no_keyword.go b/backend/plugin/advisor/snowflake/advisor_naming_identifier_no_keyword.go
index 2ea37a006b..bda187b9e8 100644
--- a/backend/plugin/advisor/snowflake/advisor_naming_identifier_no_keyword.go
+++ b/backend/plugin/advisor/snowflake/advisor_naming_identifier_no_keyword.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -107,7 +108,7 @@ func (l *namingIdentifierNoKeywordChecker) EnterColumn_decl_item_list(ctx *parse
Code: advisor.NameIsKeywordIdentifier.Int32(),
Title: l.title,
Content: fmt.Sprintf("Identifier %s is a keyword and should be avoided", originalID.GetText()),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
@@ -128,7 +129,7 @@ func (l *namingIdentifierNoKeywordChecker) EnterAlter_table(ctx *parser.Alter_ta
Code: advisor.NameIsKeywordIdentifier.Int32(),
Title: l.title,
Content: fmt.Sprintf("Identifier %s is a keyword and should be avoided", renameToID.GetText()),
- StartPosition: advisor.ConvertANTLRLineToPosition(renameToID.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(renameToID.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/snowflake/advisor_naming_table.go b/backend/plugin/advisor/snowflake/advisor_naming_table.go
index 168465e531..1200f24ec9 100644
--- a/backend/plugin/advisor/snowflake/advisor_naming_table.go
+++ b/backend/plugin/advisor/snowflake/advisor_naming_table.go
@@ -12,6 +12,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -83,7 +84,7 @@ func (l *namingTableListener) EnterCreate_table(ctx *parser.Create_tableContext)
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf(`"%s" mismatches table naming convention, naming format should be %q`, tableName, l.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
if l.maxLength > 0 && len(tableName) > l.maxLength {
@@ -92,7 +93,7 @@ func (l *namingTableListener) EnterCreate_table(ctx *parser.Create_tableContext)
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf("\"%s\" mismatches table naming convention, its length should be within %d characters", tableName, l.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
@@ -118,7 +119,7 @@ func (l *namingTableListener) EnterAlter_table(ctx *parser.Alter_tableContext) {
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf(`"%s" mismatches table naming convention, naming format should be %q`, tableName, l.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
if l.maxLength > 0 && len(tableName) > l.maxLength {
@@ -127,7 +128,7 @@ func (l *namingTableListener) EnterAlter_table(ctx *parser.Alter_tableContext) {
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf("\"%s\" mismatches table naming convention, its length should be within %d characters", tableName, l.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/snowflake/advisor_select_no_select_all.go b/backend/plugin/advisor/snowflake/advisor_select_no_select_all.go
index 46feb9e40b..cc59ca51bd 100644
--- a/backend/plugin/advisor/snowflake/advisor_select_no_select_all.go
+++ b/backend/plugin/advisor/snowflake/advisor_select_no_select_all.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -70,7 +71,7 @@ func (l *selectNoSelectAllChecker) EnterSelect_list_elem(ctx *parser.Select_list
Code: advisor.StatementSelectAll.Int32(),
Title: l.title,
Content: "Avoid using SELECT *.",
- StartPosition: advisor.ConvertANTLRLineToPosition(v.STAR().GetSymbol().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(v.STAR().GetSymbol().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/snowflake/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/snowflake/advisor_table_drop_naming_convention.go
index c7161e20fa..2eedcd0c87 100644
--- a/backend/plugin/advisor/snowflake/advisor_table_drop_naming_convention.go
+++ b/backend/plugin/advisor/snowflake/advisor_table_drop_naming_convention.go
@@ -10,6 +10,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -79,7 +80,7 @@ func (l *tableDropNamingConventionChecker) EnterDrop_table(ctx *parser.Drop_tabl
Code: advisor.TableDropNamingConventionMismatch.Int32(),
Title: l.title,
Content: fmt.Sprintf("%q mismatches drop table naming convention, naming format should be %q", normalizedObjectName, l.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.Object_name().GetO().GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.Object_name().GetO().GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/snowflake/advisor_table_no_foreign_key.go b/backend/plugin/advisor/snowflake/advisor_table_no_foreign_key.go
index 082bcae077..7c3cf3ed43 100644
--- a/backend/plugin/advisor/snowflake/advisor_table_no_foreign_key.go
+++ b/backend/plugin/advisor/snowflake/advisor_table_no_foreign_key.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -87,7 +88,7 @@ func (l *tableNoForeignKeyChecker) generateAdvice() ([]*storepb.Advice, error) {
Code: advisor.TableHasFK.Int32(),
Title: l.title,
Content: fmt.Sprintf("FOREIGN KEY is not allowed in the table %s.", l.tableOriginalName[tableName]),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.tableLine[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.tableLine[tableName]),
})
}
}
diff --git a/backend/plugin/advisor/snowflake/advisor_table_require_pk.go b/backend/plugin/advisor/snowflake/advisor_table_require_pk.go
index 0705a1d1f7..62de838c48 100644
--- a/backend/plugin/advisor/snowflake/advisor_table_require_pk.go
+++ b/backend/plugin/advisor/snowflake/advisor_table_require_pk.go
@@ -9,6 +9,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
snowsqlparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -87,7 +88,7 @@ func (l *tableRequirePkChecker) generateAdvice() ([]*storepb.Advice, error) {
Code: advisor.TableNoPK.Int32(),
Title: l.title,
Content: fmt.Sprintf("Table %s requires PRIMARY KEY.", l.tableOriginalName[tableName]),
- StartPosition: advisor.ConvertANTLRLineToPosition(l.tableLine[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(l.tableLine[tableName]),
})
}
}
diff --git a/backend/plugin/advisor/snowflake/advisor_where_require_select.go b/backend/plugin/advisor/snowflake/advisor_where_require_select.go
index 67aa3bf2ff..7255f60edc 100644
--- a/backend/plugin/advisor/snowflake/advisor_where_require_select.go
+++ b/backend/plugin/advisor/snowflake/advisor_where_require_select.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -77,7 +78,7 @@ func (l *whereRequireForSelectChecker) EnterQuery_statement(ctx *parser.Query_st
Code: advisor.StatementNoWhere.Int32(),
Title: l.title,
Content: "WHERE clause is required for SELECT statement.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/snowflake/advisor_where_require_update_delete.go b/backend/plugin/advisor/snowflake/advisor_where_require_update_delete.go
index c0fffbc272..47ab884753 100644
--- a/backend/plugin/advisor/snowflake/advisor_where_require_update_delete.go
+++ b/backend/plugin/advisor/snowflake/advisor_where_require_update_delete.go
@@ -8,6 +8,7 @@ import (
parser "github.com/bytebase/snowsql-parser"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -69,7 +70,7 @@ func (l *whereRequireForUpdateDeleteChecker) EnterUpdate_statement(ctx *parser.U
Code: advisor.StatementNoWhere.Int32(),
Title: l.title,
Content: "WHERE clause is required for UPDATE statement.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
@@ -82,7 +83,7 @@ func (l *whereRequireForUpdateDeleteChecker) EnterDelete_statement(ctx *parser.D
Code: advisor.StatementNoWhere.Int32(),
Title: l.title,
Content: "WHERE clause is required for DELETE statement.",
- StartPosition: advisor.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
+ StartPosition: common.ConvertANTLRLineToPosition(ctx.GetStart().GetLine()),
})
}
}
diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.go
index 5589de1526..475a57f3a4 100644
--- a/backend/plugin/advisor/sql_review.go
+++ b/backend/plugin/advisor/sql_review.go
@@ -634,7 +634,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: Unsupported.Int32(),
Title: walkThroughError.Content,
Content: "",
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeParseError:
res = append(res, &storepb.Advice{
@@ -649,7 +649,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: Internal.Int32(),
Title: "Internal error for walk-through",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeAccessOtherDatabase:
res = append(res, &storepb.Advice{
@@ -657,7 +657,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: NotCurrentDatabase.Int32(),
Title: "Access other database",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeDatabaseIsDeleted:
res = append(res, &storepb.Advice{
@@ -665,7 +665,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: DatabaseIsDeleted.Int32(),
Title: "Access deleted database",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeTableExists:
res = append(res, &storepb.Advice{
@@ -673,7 +673,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: TableExists.Int32(),
Title: "Table already exists",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeTableNotExists:
res = append(res, &storepb.Advice{
@@ -681,7 +681,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: TableNotExists.Int32(),
Title: "Table does not exist",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeColumnExists:
res = append(res, &storepb.Advice{
@@ -689,7 +689,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: ColumnExists.Int32(),
Title: "Column already exists",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeColumnNotExists:
res = append(res, &storepb.Advice{
@@ -697,7 +697,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: ColumnNotExists.Int32(),
Title: "Column does not exist",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeDropAllColumns:
res = append(res, &storepb.Advice{
@@ -705,7 +705,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: DropAllColumns.Int32(),
Title: "Drop all columns",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypePrimaryKeyExists:
res = append(res, &storepb.Advice{
@@ -713,7 +713,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: PrimaryKeyExists.Int32(),
Title: "Primary key exists",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeIndexExists:
res = append(res, &storepb.Advice{
@@ -721,7 +721,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: IndexExists.Int32(),
Title: "Index exists",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeIndexEmptyKeys:
res = append(res, &storepb.Advice{
@@ -729,7 +729,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: IndexEmptyKeys.Int32(),
Title: "Index empty keys",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypePrimaryKeyNotExists:
res = append(res, &storepb.Advice{
@@ -737,7 +737,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: PrimaryKeyNotExists.Int32(),
Title: "Primary key does not exist",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeIndexNotExists:
res = append(res, &storepb.Advice{
@@ -745,7 +745,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: IndexNotExists.Int32(),
Title: "Index does not exist",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeIncorrectIndexName:
res = append(res, &storepb.Advice{
@@ -753,7 +753,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: IncorrectIndexName.Int32(),
Title: "Incorrect index name",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeSpatialIndexKeyNullable:
res = append(res, &storepb.Advice{
@@ -761,7 +761,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: SpatialIndexKeyNullable.Int32(),
Title: "Spatial index key must be NOT NULL",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeColumnIsReferencedByView:
details := walkThroughError.Content
@@ -770,7 +770,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: ColumnIsReferencedByView.Int32(),
Title: "Column is referenced by view",
Content: details,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeTableIsReferencedByView:
details := walkThroughError.Content
@@ -779,7 +779,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: TableIsReferencedByView.Int32(),
Title: "Table is referenced by view",
Content: details,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
case catalog.ErrorTypeInvalidColumnTypeForDefaultValue:
res = append(res, &storepb.Advice{
@@ -787,7 +787,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: InvalidColumnDefault.Int32(),
Title: "Invalid column default value",
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
default:
res = append(res, &storepb.Advice{
@@ -795,7 +795,7 @@ func convertWalkThroughErrorToAdvice(err error) ([]*storepb.Advice, error) {
Code: Internal.Int32(),
Title: fmt.Sprintf("Failed to walk-through with code %d", walkThroughError.Type),
Content: walkThroughError.Content,
- StartPosition: ConvertANTLRLineToPosition(walkThroughError.Line),
+ StartPosition: common.ConvertANTLRLineToPosition(walkThroughError.Line),
})
}
diff --git a/backend/plugin/advisor/tidb/advisor_builtin_prior_backup_check.go b/backend/plugin/advisor/tidb/advisor_builtin_prior_backup_check.go
index e231ff57a1..0f0016f639 100644
--- a/backend/plugin/advisor/tidb/advisor_builtin_prior_backup_check.go
+++ b/backend/plugin/advisor/tidb/advisor_builtin_prior_backup_check.go
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/opcode"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -72,7 +73,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: "Prior backup cannot deal with mixed DDL and DML statements",
Code: advisor.BuiltinPriorBackupCheck.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmtNode.OriginTextPosition()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmtNode.OriginTextPosition()),
})
}
}
@@ -83,7 +84,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
Title: title,
Content: fmt.Sprintf("Need database %q to do prior backup but it does not exist", checkCtx.PreUpdateBackupDetail.Database),
Code: advisor.DatabaseNotExists.Int32(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
}
@@ -93,7 +94,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx context.Context, checkCtx adv
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(),
- StartPosition: advisor.DefaultPosition,
+ StartPosition: common.FirstLinePosition,
})
}
diff --git a/backend/plugin/advisor/tidb/advisor_charset_allowlist.go b/backend/plugin/advisor/tidb/advisor_charset_allowlist.go
index 2e66db9f24..325aa60b2a 100644
--- a/backend/plugin/advisor/tidb/advisor_charset_allowlist.go
+++ b/backend/plugin/advisor/tidb/advisor_charset_allowlist.go
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -136,7 +137,7 @@ func (checker *charsetAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" used disabled charset '%s'", checker.text, disabledCharset),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
}
diff --git a/backend/plugin/advisor/tidb/advisor_collation_allowlist.go b/backend/plugin/advisor/tidb/advisor_collation_allowlist.go
index 98b7be8cd5..443d2a2a57 100644
--- a/backend/plugin/advisor/tidb/advisor_collation_allowlist.go
+++ b/backend/plugin/advisor/tidb/advisor_collation_allowlist.go
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -137,7 +138,7 @@ func (checker *collationAllowlistChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" used disabled collation '%s'", checker.text, disabledCollation),
- StartPosition: advisor.ConvertANTLRLineToPosition(line),
+ StartPosition: common.ConvertANTLRLineToPosition(line),
})
}
diff --git a/backend/plugin/advisor/tidb/advisor_colum_require_default.go b/backend/plugin/advisor/tidb/advisor_colum_require_default.go
index 2369a08afd..29e4a7bbe3 100644
--- a/backend/plugin/advisor/tidb/advisor_colum_require_default.go
+++ b/backend/plugin/advisor/tidb/advisor_colum_require_default.go
@@ -11,6 +11,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/types"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -109,7 +110,7 @@ func (checker *columRequireDefaultChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.NoDefault.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s`.`%s` doesn't have DEFAULT.", column.table, column.column),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
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.go
index cf2fbb3fba..af7651113c 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
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -76,7 +77,7 @@ func (checker *columnAutoIncrementInitialValueChecker) Enter(in ast.Node) (ast.N
Code: advisor.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: advisor.ConvertANTLRLineToPosition(checker.line),
+ 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.go
index c9f5c53158..4bd0cd7f0b 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
@@ -11,6 +11,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/types"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -112,7 +113,7 @@ func (checker *columnAutoIncrementMustIntegerChecker) Enter(in ast.Node) (ast.No
Code: advisor.AutoIncrementColumnNotInteger.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Auto-increment column `%s`.`%s` requires integer type", column.table, column.column),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ 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.go
index ca70682f29..2ee4731f63 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
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -105,7 +106,7 @@ func (checker *columnAutoIncrementMustUnsignedChecker) Enter(in ast.Node) (ast.N
Code: advisor.AutoIncrementColumnSigned.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Auto-increment column `%s`.`%s` is not UNSIGNED type", column.table, column.column),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ 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.go
index 3f7e6f0808..1508e9b2a1 100644
--- a/backend/plugin/advisor/tidb/advisor_column_comment_convention.go
+++ b/backend/plugin/advisor/tidb/advisor_column_comment_convention.go
@@ -127,7 +127,7 @@ func (checker *columnCommentConventionChecker) Enter(in ast.Node) (ast.Node, boo
Code: advisor.CommentEmpty.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s`.`%s` requires comments", column.table, column.column),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
if checker.payload.MaxLength >= 0 && len(column.comment) > checker.payload.MaxLength {
@@ -136,7 +136,7 @@ func (checker *columnCommentConventionChecker) Enter(in ast.Node) (ast.Node, boo
Code: advisor.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: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
if checker.payload.RequiredClassification {
@@ -146,7 +146,7 @@ func (checker *columnCommentConventionChecker) Enter(in ast.Node) (ast.Node, boo
Code: advisor.CommentMissingClassification.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s`.`%s` comment requires classification", column.table, column.column),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
}
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.go
index 95c3f0c413..288ad7a6fe 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
@@ -12,6 +12,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -91,7 +92,7 @@ func (checker *columnCurrentTimeCountLimitChecker) generateAdvice() []*storepb.A
Code: advisor.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: advisor.ConvertANTLRLineToPosition(table.line),
+ StartPosition: common.ConvertANTLRLineToPosition(table.line),
})
}
if table.onUpdateCurrentTimeCount > maxOnUpdateCurrentTimeColumnCount {
@@ -100,7 +101,7 @@ func (checker *columnCurrentTimeCountLimitChecker) generateAdvice() []*storepb.A
Code: advisor.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: advisor.ConvertANTLRLineToPosition(table.line),
+ 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.go
index 9627ecc9ea..e2eaff3a72 100644
--- a/backend/plugin/advisor/tidb/advisor_column_disallow_changing.go
+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_changing.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -69,7 +70,7 @@ func (checker *columnDisallowChangingChecker) Enter(in ast.Node) (ast.Node, bool
Code: advisor.UseChangeColumnStatement.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" contains CHANGE COLUMN statement", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
break
}
diff --git a/backend/plugin/advisor/tidb/advisor_column_disallow_changing_order.go b/backend/plugin/advisor/tidb/advisor_column_disallow_changing_order.go
index d9f84756bd..bccebe870f 100644
--- a/backend/plugin/advisor/tidb/advisor_column_disallow_changing_order.go
+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_changing_order.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -70,7 +71,7 @@ func (checker *columnDisallowChangingOrderChecker) Enter(in ast.Node) (ast.Node,
Code: advisor.ChangeColumnOrder.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" changes column order", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
break
}
diff --git a/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go b/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go
index 3f70d0f209..1f2b8cdc71 100644
--- a/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go
+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -86,7 +87,7 @@ func (checker *columnDisallowChangingTypeChecker) Enter(in ast.Node) (ast.Node,
Code: advisor.ChangeColumnType.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" changes column type", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ 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.go
index 34525d845d..cfc5b1b167 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
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -109,7 +110,7 @@ func (checker *columnDisallowDropInIndexChecker) dropColumn(in ast.Node) (ast.No
Code: advisor.DropIndexColumn.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s`.`%s` cannot drop index column", table, colName),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ 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.go
index 9624d8149c..5bc4190a52 100644
--- a/backend/plugin/advisor/tidb/advisor_column_disallow_set_charset.go
+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_set_charset.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -99,7 +100,7 @@ func (checker *columnDisallowSetCharsetChecker) Enter(in ast.Node) (ast.Node, bo
Code: advisor.SetColumnCharset.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Disallow set column charset but \"%s\" does", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ 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.go
index 6c28396347..9f0606b59b 100644
--- a/backend/plugin/advisor/tidb/advisor_column_maximum_character_length.go
+++ b/backend/plugin/advisor/tidb/advisor_column_maximum_character_length.go
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -113,7 +114,7 @@ func (checker *columnMaximumCharacterLengthChecker) Enter(in ast.Node) (ast.Node
Code: advisor.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: advisor.ConvertANTLRLineToPosition(line),
+ 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.go
index 8b85e203b7..fd33f4c689 100644
--- a/backend/plugin/advisor/tidb/advisor_column_no_null.go
+++ b/backend/plugin/advisor/tidb/advisor_column_no_null.go
@@ -8,6 +8,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -82,7 +83,7 @@ func (checker *columnNoNullChecker) generateAdvice() []*storepb.Advice {
Code: advisor.ColumnCannotNull.Int32(),
Title: checker.title,
Content: fmt.Sprintf("`%s`.`%s` cannot have NULL value", column.tableName, column.columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
}
diff --git a/backend/plugin/advisor/tidb/advisor_column_required.go b/backend/plugin/advisor/tidb/advisor_column_required.go
index 4617eb6dad..2e3e7e4492 100644
--- a/backend/plugin/advisor/tidb/advisor_column_required.go
+++ b/backend/plugin/advisor/tidb/advisor_column_required.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -134,7 +135,7 @@ func (v *columnRequirementChecker) generateAdviceList() []*storepb.Advice {
Code: advisor.NoRequiredColumn.Int32(),
Title: v.title,
Content: fmt.Sprintf("Table `%s` requires columns: %s", tableName, strings.Join(missingColumns, ", ")),
- StartPosition: advisor.ConvertANTLRLineToPosition(v.line[tableName]),
+ 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.go
index f68d180d36..d3199296fe 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
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -119,7 +120,7 @@ func (checker *columnSetDefaultForNotNullChecker) Enter(in ast.Node) (ast.Node,
Code: advisor.NotNullColumnWithNoDefault.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Column `%s`.`%s` is NOT NULL but doesn't have DEFAULT", column.tableName, column.columnName),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ 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.go
index 405ff6e308..d49a61c5b0 100644
--- a/backend/plugin/advisor/tidb/advisor_column_type_disallow_list.go
+++ b/backend/plugin/advisor/tidb/advisor_column_type_disallow_list.go
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -125,7 +126,7 @@ func (checker *columnTypeDisallowListChecker) Enter(in ast.Node) (ast.Node, bool
Code: advisor.DisabledColumnType.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Disallow column type %s but column `%s`.`%s` is", column.tp, column.table, column.column),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ 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.go
index 9c3a8c1c74..dd25288c84 100644
--- a/backend/plugin/advisor/tidb/advisor_database_drop_empty_db.go
+++ b/backend/plugin/advisor/tidb/advisor_database_drop_empty_db.go
@@ -7,6 +7,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -65,7 +66,7 @@ func (v *allowDropEmptyDBChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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.catalog.Origin.DatabaseName()),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.OriginTextPosition()),
+ StartPosition: common.ConvertANTLRLineToPosition(node.OriginTextPosition()),
})
} else if !v.catalog.Origin.HasNoTable() {
v.adviceList = append(v.adviceList, &storepb.Advice{
@@ -73,7 +74,7 @@ func (v *allowDropEmptyDBChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.DatabaseNotEmpty.Int32(),
Title: v.title,
Content: fmt.Sprintf("Database `%s` is not allowed to drop if not empty", node.Name),
- StartPosition: advisor.ConvertANTLRLineToPosition(node.OriginTextPosition()),
+ 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.go
index a31f7b10de..aa9052886b 100644
--- a/backend/plugin/advisor/tidb/advisor_index_key_number_limit.go
+++ b/backend/plugin/advisor/tidb/advisor_index_key_number_limit.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -110,7 +111,7 @@ func (checker *indexKeyNumberLimitChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(index.line),
+ 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.go
index 847115ae0c..3c39bc766e 100644
--- a/backend/plugin/advisor/tidb/advisor_index_no_duplicate_column.go
+++ b/backend/plugin/advisor/tidb/advisor_index_no_duplicate_column.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -128,7 +129,7 @@ func (checker *indexNoDuplicateColumnChecker) Enter(in ast.Node) (ast.Node, bool
Code: advisor.DuplicateColumnInIndex.Int32(),
Title: checker.title,
Content: fmt.Sprintf("%s `%s` has duplicate column `%s`.`%s`", column.tp, column.index, column.table, column.column),
- StartPosition: advisor.ConvertANTLRLineToPosition(column.line),
+ 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.go
index 230c1c8d87..4f1d59639e 100644
--- a/backend/plugin/advisor/tidb/advisor_index_pk_type.go
+++ b/backend/plugin/advisor/tidb/advisor_index_pk_type.go
@@ -11,6 +11,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/types"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -139,7 +140,7 @@ func (v *indexPkTypeChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(pd.line),
+ StartPosition: common.ConvertANTLRLineToPosition(pd.line),
})
}
return in, false
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.go
index 9767978bd9..5d61663095 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
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
tidbparser "github.com/bytebase/bytebase/backend/plugin/parser/tidb"
@@ -119,7 +120,7 @@ func (v *indexPrimaryKeyTypeAllowlistChecker) Enter(in ast.Node) (ast.Node, bool
Code: advisor.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: advisor.ConvertANTLRLineToPosition(pd.line),
+ StartPosition: common.ConvertANTLRLineToPosition(pd.line),
})
}
return in, false
diff --git a/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go b/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go
index e8d5a6cd52..01468e02ed 100644
--- a/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go
+++ b/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -96,7 +97,7 @@ func (checker *indexTotalNumberLimitChecker) generateAdvice() []*storepb.Advice
Code: advisor.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: advisor.ConvertANTLRLineToPosition(table.line),
+ 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.go
index 64111a6a55..e069d111a2 100644
--- a/backend/plugin/advisor/tidb/advisor_index_type_no_blob.go
+++ b/backend/plugin/advisor/tidb/advisor_index_type_no_blob.go
@@ -12,6 +12,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/types"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -116,7 +117,7 @@ func (v *indexTypeNoBlobChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(pd.line),
+ StartPosition: common.ConvertANTLRLineToPosition(pd.line),
})
}
return in, false
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.go
index 44aeab21eb..d5fa0e8419 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
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -85,7 +86,7 @@ func (checker *insertDisallowOrderByRandChecker) Enter(in ast.Node) (ast.Node, b
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" uses ORDER BY RAND in the INSERT statement", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
diff --git a/backend/plugin/advisor/tidb/advisor_insert_must_specify_column.go b/backend/plugin/advisor/tidb/advisor_insert_must_specify_column.go
index dba2cb6aac..64a7b36874 100644
--- a/backend/plugin/advisor/tidb/advisor_insert_must_specify_column.go
+++ b/backend/plugin/advisor/tidb/advisor_insert_must_specify_column.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -68,7 +69,7 @@ func (checker *insertMustSpecifyColumnChecker) Enter(in ast.Node) (ast.Node, boo
Code: advisor.InsertNotSpecifyColumn.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The INSERT statement must specify columns but \"%s\" does not", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
}
diff --git a/backend/plugin/advisor/tidb/advisor_migration_compatibility.go b/backend/plugin/advisor/tidb/advisor_migration_compatibility.go
index 710720bff3..3b7028c567 100644
--- a/backend/plugin/advisor/tidb/advisor_migration_compatibility.go
+++ b/backend/plugin/advisor/tidb/advisor_migration_compatibility.go
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -155,7 +156,7 @@ func (v *compatibilityChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: code.Int32(),
Title: v.title,
Content: fmt.Sprintf("\"%s\" may cause incompatibility with the existing data and code", in.Text()),
- StartPosition: advisor.ConvertANTLRLineToPosition(in.OriginTextPosition()),
+ StartPosition: common.ConvertANTLRLineToPosition(in.OriginTextPosition()),
})
}
return in, false
diff --git a/backend/plugin/advisor/tidb/advisor_naming_auto_increment_column.go b/backend/plugin/advisor/tidb/advisor_naming_auto_increment_column.go
index 86fa1a57b1..2b8e20470f 100644
--- a/backend/plugin/advisor/tidb/advisor_naming_auto_increment_column.go
+++ b/backend/plugin/advisor/tidb/advisor_naming_auto_increment_column.go
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -122,7 +123,7 @@ func (checker *namingAutoIncrementColumnChecker) Enter(in ast.Node) (ast.Node, b
Code: advisor.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: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
if checker.maxLength > 0 && len(column.name) > checker.maxLength {
@@ -131,7 +132,7 @@ func (checker *namingAutoIncrementColumnChecker) Enter(in ast.Node) (ast.Node, b
Code: advisor.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: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
}
diff --git a/backend/plugin/advisor/tidb/advisor_naming_column.go b/backend/plugin/advisor/tidb/advisor_naming_column.go
index 6190c4dd36..5c6f5233b2 100644
--- a/backend/plugin/advisor/tidb/advisor_naming_column.go
+++ b/backend/plugin/advisor/tidb/advisor_naming_column.go
@@ -8,6 +8,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -118,7 +119,7 @@ func (v *namingColumnConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(column.line),
+ StartPosition: common.ConvertANTLRLineToPosition(column.line),
})
}
if v.maxLength > 0 && len(column.name) > v.maxLength {
@@ -127,7 +128,7 @@ func (v *namingColumnConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(column.line),
+ 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.go
index 9b67fcbb10..5f92c3f05b 100644
--- a/backend/plugin/advisor/tidb/advisor_naming_foreign_key_convention.go
+++ b/backend/plugin/advisor/tidb/advisor_naming_foreign_key_convention.go
@@ -8,6 +8,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -85,7 +86,7 @@ func (checker *namingFKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {
@@ -94,7 +95,7 @@ func (checker *namingFKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ 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.go
index be5c766e14..abace8c853 100644
--- a/backend/plugin/advisor/tidb/advisor_naming_index_convention.go
+++ b/backend/plugin/advisor/tidb/advisor_naming_index_convention.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -89,7 +90,7 @@ func (checker *namingIndexConventionChecker) Enter(in ast.Node) (ast.Node, bool)
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {
@@ -98,7 +99,7 @@ func (checker *namingIndexConventionChecker) Enter(in ast.Node) (ast.Node, bool)
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
}
diff --git a/backend/plugin/advisor/tidb/advisor_naming_table.go b/backend/plugin/advisor/tidb/advisor_naming_table.go
index bc51b96cae..7e32e56379 100644
--- a/backend/plugin/advisor/tidb/advisor_naming_table.go
+++ b/backend/plugin/advisor/tidb/advisor_naming_table.go
@@ -8,6 +8,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -91,7 +92,7 @@ func (v *namingTableConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: v.title,
Content: fmt.Sprintf("`%s` mismatches table naming convention, naming format should be %q", tableName, v.format),
- StartPosition: advisor.ConvertANTLRLineToPosition(in.OriginTextPosition()),
+ StartPosition: common.ConvertANTLRLineToPosition(in.OriginTextPosition()),
})
}
if v.maxLength > 0 && len(tableName) > v.maxLength {
@@ -100,7 +101,7 @@ func (v *namingTableConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.NamingTableConventionMismatch.Int32(),
Title: v.title,
Content: fmt.Sprintf("`%s` mismatches table naming convention, its length should be within %d characters", tableName, v.maxLength),
- StartPosition: advisor.ConvertANTLRLineToPosition(in.OriginTextPosition()),
+ 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.go
index 17c8832653..badc885410 100644
--- a/backend/plugin/advisor/tidb/advisor_naming_unique_key_convention.go
+++ b/backend/plugin/advisor/tidb/advisor_naming_unique_key_convention.go
@@ -8,6 +8,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -88,7 +89,7 @@ func (checker *namingUKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ StartPosition: common.ConvertANTLRLineToPosition(indexData.line),
})
}
if checker.maxLength > 0 && len(indexData.indexName) > checker.maxLength {
@@ -97,7 +98,7 @@ func (checker *namingUKConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(indexData.line),
+ 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.go
index 56eb88717f..61b2cc1ae2 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
@@ -7,6 +7,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -49,7 +50,7 @@ func (*StatementDisallowMixInDDLAdvisor) Check(_ context.Context, checkCtx advis
Title: title,
Content: fmt.Sprintf("Alter schema can only run DDL, \"%s\" is not DDL", stmtNode.Text()),
Code: advisor.StatementDisallowMixDDLDML.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmtNode.OriginTextPosition()),
+ 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.go
index 4163713c8b..dd8b8ac229 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
@@ -7,6 +7,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -49,7 +50,7 @@ func (*StatementDisallowMixInDMLAdvisor) Check(_ context.Context, checkCtx advis
Title: title,
Content: fmt.Sprintf("Data change can only run DML, \"%s\" is not DML", stmtNode.Text()),
Code: advisor.StatementDisallowMixDDLDML.Int32(),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmtNode.OriginTextPosition()),
+ 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.go
index 85eac674af..78e76d34b7 100644
--- a/backend/plugin/advisor/tidb/advisor_statement_dml_dry_run.go
+++ b/backend/plugin/advisor/tidb/advisor_statement_dml_dry_run.go
@@ -82,7 +82,7 @@ func (checker *statementDmlDryRunChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.StatementDMLDryRunFailed.Int32(),
Title: checker.title,
Content: fmt.Sprintf("\"%s\" dry runs failed: %s", node.Text(), err.Error()),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ 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.go
index 8ebb5a5a5b..683678126d 100644
--- a/backend/plugin/advisor/tidb/advisor_statement_maximum_limit_value.go
+++ b/backend/plugin/advisor/tidb/advisor_statement_maximum_limit_value.go
@@ -10,6 +10,7 @@ import (
driver "github.com/pingcap/tidb/pkg/types/parser_driver"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -79,7 +80,7 @@ func (checker *statementMaximumLimitValueChecker) Enter(in ast.Node) (ast.Node,
Code: advisor.StatementExceedMaximumLimitValue.Int32(),
Title: checker.title,
Content: fmt.Sprintf("The limit value %d exceeds the maximum allowed value %d", limitVal, checker.limitMaxValue),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ 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.go
index 6ec3d607f7..f9275c8f49 100644
--- a/backend/plugin/advisor/tidb/advisor_statement_merge_alter_table.go
+++ b/backend/plugin/advisor/tidb/advisor_statement_merge_alter_table.go
@@ -10,6 +10,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -115,7 +116,7 @@ func (checker *statementMergeAlterTableChecker) generateAdvice() []*storepb.Advi
Code: advisor.StatementRedundantAlterTable.Int32(),
Title: checker.title,
Content: fmt.Sprintf("There are %d statements to modify table `%s`", table.count, table.name),
- StartPosition: advisor.ConvertANTLRLineToPosition(table.lastLine),
+ 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.go
index baa6e886de..ec0605f28e 100644
--- a/backend/plugin/advisor/tidb/advisor_stmt_disallow_commit.go
+++ b/backend/plugin/advisor/tidb/advisor_stmt_disallow_commit.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -67,7 +68,7 @@ func (c *statementDisallowCommitChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.StatementDisallowCommit.Int32(),
Title: c.title,
Content: fmt.Sprintf("Commit is not allowed, related statement: \"%s\"", c.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(c.line),
+ 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.go
index fa1a6fc288..08ce08e77e 100644
--- a/backend/plugin/advisor/tidb/advisor_stmt_disallow_limit.go
+++ b/backend/plugin/advisor/tidb/advisor_stmt_disallow_limit.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -83,7 +84,7 @@ func (checker *statementDisallowLimitChecker) Enter(in ast.Node) (ast.Node, bool
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but \"%s\" uses", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
diff --git a/backend/plugin/advisor/tidb/advisor_stmt_disallow_order_by.go b/backend/plugin/advisor/tidb/advisor_stmt_disallow_order_by.go
index 4b8fea6eec..90c61b4f80 100644
--- a/backend/plugin/advisor/tidb/advisor_stmt_disallow_order_by.go
+++ b/backend/plugin/advisor/tidb/advisor_stmt_disallow_order_by.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -79,7 +80,7 @@ func (checker *disallowOrderByChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("ORDER BY clause is forbidden in DELETE and UPDATE statements, but \"%s\" uses", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
return in, false
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.go
index 02649e255a..4f085dcf87 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
@@ -8,6 +8,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/format"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -53,7 +54,7 @@ func (*NoLeadingWildcardLikeAdvisor) Check(_ context.Context, checkCtx advisor.C
Code: advisor.StatementLeadingWildcardLike.Int32(),
Title: string(checkCtx.Rule.Type),
Content: fmt.Sprintf("\"%s\" uses leading wildcard LIKE", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(stmtNode.OriginTextPosition()),
+ StartPosition: common.ConvertANTLRLineToPosition(stmtNode.OriginTextPosition()),
})
}
}
diff --git a/backend/plugin/advisor/tidb/advisor_stmt_no_select_all.go b/backend/plugin/advisor/tidb/advisor_stmt_no_select_all.go
index 9f12d91ab0..d943486908 100644
--- a/backend/plugin/advisor/tidb/advisor_stmt_no_select_all.go
+++ b/backend/plugin/advisor/tidb/advisor_stmt_no_select_all.go
@@ -7,6 +7,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -66,7 +67,7 @@ func (v *noSelectAllChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.StatementSelectAll.Int32(),
Title: v.title,
Content: fmt.Sprintf("\"%s\" uses SELECT all", v.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(v.line),
+ StartPosition: common.ConvertANTLRLineToPosition(v.line),
})
break
}
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.go
index 320a2e30bd..27f4982cc2 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
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -73,7 +74,7 @@ func (v *whereRequirementForSelectChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: code.Int32(),
Title: v.title,
Content: fmt.Sprintf("\"%s\" requires WHERE clause", v.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(v.line),
+ StartPosition: common.ConvertANTLRLineToPosition(v.line),
})
}
return in, false
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.go
index 0ccffbab67..bb2ec19f46 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
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -79,7 +80,7 @@ func (v *whereRequirementForUpdateDeleteChecker) Enter(in ast.Node) (ast.Node, b
Code: code.Int32(),
Title: v.title,
Content: fmt.Sprintf("\"%s\" requires WHERE clause", v.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(v.line),
+ StartPosition: common.ConvertANTLRLineToPosition(v.line),
})
}
return in, false
diff --git a/backend/plugin/advisor/tidb/advisor_table_comment_convention.go b/backend/plugin/advisor/tidb/advisor_table_comment_convention.go
index 140904ab13..9e02e797aa 100644
--- a/backend/plugin/advisor/tidb/advisor_table_comment_convention.go
+++ b/backend/plugin/advisor/tidb/advisor_table_comment_convention.go
@@ -78,7 +78,7 @@ func (checker *tableCommentConventionChecker) Enter(in ast.Node) (ast.Node, bool
Code: advisor.CommentEmpty.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table `%s` requires comments", node.Table.Name.O),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
if checker.payload.MaxLength >= 0 && len(comment) > checker.payload.MaxLength {
@@ -87,7 +87,7 @@ func (checker *tableCommentConventionChecker) Enter(in ast.Node) (ast.Node, bool
Code: advisor.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: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
if checker.payload.RequiredClassification {
@@ -97,7 +97,7 @@ func (checker *tableCommentConventionChecker) Enter(in ast.Node) (ast.Node, bool
Code: advisor.CommentMissingClassification.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table `%s` comment requires classification", node.Table.Name.O),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ 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.go
index aab56b38aa..815ca24c02 100644
--- a/backend/plugin/advisor/tidb/advisor_table_disallow_partition.go
+++ b/backend/plugin/advisor/tidb/advisor_table_disallow_partition.go
@@ -9,6 +9,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -82,7 +83,7 @@ func (checker *tableDisallowPartitionChecker) Enter(in ast.Node) (ast.Node, bool
Code: code.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Table partition is forbidden, but \"%s\" creates", checker.text),
- StartPosition: advisor.ConvertANTLRLineToPosition(checker.line),
+ StartPosition: common.ConvertANTLRLineToPosition(checker.line),
})
}
diff --git a/backend/plugin/advisor/tidb/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/tidb/advisor_table_drop_naming_convention.go
index f9f0a5929b..d3cfc20e5b 100644
--- a/backend/plugin/advisor/tidb/advisor_table_drop_naming_convention.go
+++ b/backend/plugin/advisor/tidb/advisor_table_drop_naming_convention.go
@@ -8,6 +8,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -70,7 +71,7 @@ func (v *namingDropTableConventionChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.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: advisor.ConvertANTLRLineToPosition(node.OriginTextPosition()),
+ 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.go
index d87bf71674..75fdcaed58 100644
--- a/backend/plugin/advisor/tidb/advisor_table_no_fk.go
+++ b/backend/plugin/advisor/tidb/advisor_table_no_fk.go
@@ -7,6 +7,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -63,7 +64,7 @@ func (checker *tableNoFKChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.TableHasFK.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Foreign key is not allowed in the table `%s`", node.Table.Name),
- StartPosition: advisor.ConvertANTLRLineToPosition(constraint.OriginTextPosition()),
+ StartPosition: common.ConvertANTLRLineToPosition(constraint.OriginTextPosition()),
})
}
}
@@ -75,7 +76,7 @@ func (checker *tableNoFKChecker) Enter(in ast.Node) (ast.Node, bool) {
Code: advisor.TableHasFK.Int32(),
Title: checker.title,
Content: fmt.Sprintf("Foreign key is not allowed in the table `%s`", node.Table.Name),
- StartPosition: advisor.ConvertANTLRLineToPosition(in.OriginTextPosition()),
+ 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.go
index ca6d8975d6..c45b86bfd1 100644
--- a/backend/plugin/advisor/tidb/advisor_table_require_pk.go
+++ b/backend/plugin/advisor/tidb/advisor_table_require_pk.go
@@ -8,6 +8,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -135,7 +136,7 @@ func (v *tableRequirePKChecker) generateAdviceList() []*storepb.Advice {
Code: advisor.TableNoPK.Int32(),
Title: v.title,
Content: fmt.Sprintf("Table `%s` requires PRIMARY KEY", tableName),
- StartPosition: advisor.ConvertANTLRLineToPosition(v.line[tableName]),
+ StartPosition: common.ConvertANTLRLineToPosition(v.line[tableName]),
})
}
}
diff --git a/backend/plugin/advisor/utils.go b/backend/plugin/advisor/utils.go
index 5d94096487..c526ce523e 100644
--- a/backend/plugin/advisor/utils.go
+++ b/backend/plugin/advisor/utils.go
@@ -13,12 +13,6 @@ import (
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
-var (
- DefaultPosition = &storepb.Position{
- Line: 0,
- }
-)
-
// NormalizeStatement limit the max length of the statements.
func NormalizeStatement(statement string) string {
maxLength := 1000
@@ -169,13 +163,3 @@ func DatabaseExists(ctx context.Context, checkCtx Context, database string) bool
return false
}
-
-func ConvertANTLRLineToPosition(line int) *storepb.Position {
- positionLine := line - 1
- if line == 0 {
- positionLine = 0
- }
- return &storepb.Position{
- Line: int32(positionLine),
- }
-}