Skip to content

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

chore: lint warning part 3 (#8999)

Danny Xu677c24a8d72f
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index 5296cd449e..ea8014c0c4 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -26,7 +26,7 @@ import (
"github.com/bytebase/bytebase/backend/component/state"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
api "github.com/bytebase/bytebase/backend/legacyapi"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/idp/ldap"
"github.com/bytebase/bytebase/backend/plugin/idp/oauth2"
"github.com/bytebase/bytebase/backend/plugin/idp/oidc"
@@ -207,7 +207,7 @@ func (s *AuthService) CreateUser(ctx context.Context, request *v1pb.CreateUserRe
isFirstUser := user.ID == api.PrincipalIDForFirstUser
s.metricReporter.Report(ctx, &metric.Metric{
- Name: metricAPI.PrincipalRegistrationMetricName,
+ Name: metricapi.PrincipalRegistrationMetricName,
Value: 1,
Labels: map[string]any{
"email": user.Email,
@@ -647,7 +647,7 @@ func (s *AuthService) Login(ctx context.Context, request *v1pb.LoginRequest) (*v
}
s.metricReporter.Report(ctx, &metric.Metric{
- Name: metricAPI.PrincipalLoginMetricName,
+ Name: metricapi.PrincipalLoginMetricName,
Value: 1,
Labels: map[string]any{
"email": loginUser.Email,
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index 4cbecd7d2b..25507718fa 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -19,7 +19,7 @@ import (
"github.com/bytebase/bytebase/backend/component/state"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
api "github.com/bytebase/bytebase/backend/legacyapi"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg"
"github.com/bytebase/bytebase/backend/runner/metricreport"
@@ -159,7 +159,7 @@ func (s *InstanceService) CreateInstance(ctx context.Context, request *v1pb.Crea
}
s.metricReporter.Report(ctx, &metric.Metric{
- Name: metricAPI.InstanceCreateMetricName,
+ Name: metricapi.InstanceCreateMetricName,
Value: 1,
Labels: map[string]any{
"engine": instance.Engine,
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 865b383554..667b3c9b6b 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -23,7 +23,7 @@ import (
"github.com/bytebase/bytebase/backend/component/state"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
api "github.com/bytebase/bytebase/backend/legacyapi"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
"github.com/bytebase/bytebase/backend/runner/metricreport"
"github.com/bytebase/bytebase/backend/runner/relay"
@@ -722,7 +722,7 @@ func (s *IssueService) createIssueGrantRequest(ctx context.Context, request *v1p
}
s.metricReporter.Report(ctx, &metric.Metric{
- Name: metricAPI.IssueCreateMetricName,
+ Name: metricapi.IssueCreateMetricName,
Value: 1,
Labels: map[string]any{
"type": issue.Type,
diff --git a/backend/api/v1/subscription_service.go b/backend/api/v1/subscription_service.go
index 7bc0bb86fe..e18fdcc972 100644
--- a/backend/api/v1/subscription_service.go
+++ b/backend/api/v1/subscription_service.go
@@ -14,7 +14,7 @@ import (
"github.com/bytebase/bytebase/backend/component/config"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
api "github.com/bytebase/bytebase/backend/legacyapi"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
"github.com/bytebase/bytebase/backend/runner/metricreport"
"github.com/bytebase/bytebase/backend/store"
@@ -164,7 +164,7 @@ func (s *SubscriptionService) TrialSubscription(ctx context.Context, request *v1
subscription = s.licenseService.LoadSubscription(ctx)
currentPlan := subscription.Plan
s.metricReporter.Report(ctx, &metric.Metric{
- Name: metricAPI.SubscriptionTrialMetricName,
+ Name: metricapi.SubscriptionTrialMetricName,
Value: 1,
Labels: map[string]any{
"trial_plan": currentPlan.String(),
diff --git a/backend/metric/collector/database_count.go b/backend/metric/collector/database_count.go
index a592c93c0d..237354566a 100644
--- a/backend/metric/collector/database_count.go
+++ b/backend/metric/collector/database_count.go
@@ -4,7 +4,7 @@ import (
"context"
"strconv"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
"github.com/bytebase/bytebase/backend/store"
)
@@ -44,7 +44,7 @@ func (c *databaseCountCollector) Collect(ctx context.Context) ([]*metric.Metric,
labels["backup_enabled"] = strconv.FormatBool(*v)
}
res = append(res, &metric.Metric{
- Name: metricAPI.DatabaseCountMetricName,
+ Name: metricapi.DatabaseCountMetricName,
Value: databaseCountMetric.Count,
Labels: labels,
})
diff --git a/backend/metric/collector/instance_count.go b/backend/metric/collector/instance_count.go
index 515b6ec651..c0a12e6208 100644
--- a/backend/metric/collector/instance_count.go
+++ b/backend/metric/collector/instance_count.go
@@ -4,7 +4,7 @@ import (
"context"
"log/slog"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
"github.com/bytebase/bytebase/backend/store"
)
@@ -42,7 +42,7 @@ func (c *instanceCountCollector) Collect(ctx context.Context) ([]*metric.Metric,
}
res = append(res, &metric.Metric{
- Name: metricAPI.InstanceCountMetricName,
+ Name: metricapi.InstanceCountMetricName,
Value: instanceCountMetric.Count,
Labels: map[string]any{
"engine": instanceCountMetric.Engine.String(),
diff --git a/backend/metric/collector/issue_count.go b/backend/metric/collector/issue_count.go
index bf1add6e5f..dd71177ff2 100644
--- a/backend/metric/collector/issue_count.go
+++ b/backend/metric/collector/issue_count.go
@@ -3,7 +3,7 @@ package collector
import (
"context"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
"github.com/bytebase/bytebase/backend/store"
)
@@ -33,7 +33,7 @@ func (c *issueCountCollector) Collect(ctx context.Context) ([]*metric.Metric, er
for _, issueCountMetric := range issueCountMetricList {
res = append(res, &metric.Metric{
- Name: metricAPI.IssueCountMetricName,
+ Name: metricapi.IssueCountMetricName,
Value: issueCountMetric.Count,
Labels: map[string]any{
"type": string(issueCountMetric.Type),
diff --git a/backend/metric/collector/member_count.go b/backend/metric/collector/member_count.go
index e293a7293e..f286cc4503 100644
--- a/backend/metric/collector/member_count.go
+++ b/backend/metric/collector/member_count.go
@@ -3,7 +3,7 @@ package collector
import (
"context"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
"github.com/bytebase/bytebase/backend/store"
)
@@ -33,7 +33,7 @@ func (c *memberCountCollector) Collect(ctx context.Context) ([]*metric.Metric, e
for _, memberCountMetric := range memberCountMetricList {
res = append(res, &metric.Metric{
- Name: metricAPI.MemberCountMetricName,
+ Name: metricapi.MemberCountMetricName,
Value: memberCountMetric.Count,
Labels: map[string]any{
"role": string(memberCountMetric.Role),
diff --git a/backend/metric/collector/policy_count.go b/backend/metric/collector/policy_count.go
index 27134325bf..93373f9787 100644
--- a/backend/metric/collector/policy_count.go
+++ b/backend/metric/collector/policy_count.go
@@ -5,7 +5,7 @@ import (
"fmt"
api "github.com/bytebase/bytebase/backend/legacyapi"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
"github.com/bytebase/bytebase/backend/store"
)
@@ -33,7 +33,7 @@ func (c *policyCountCollector) Collect(ctx context.Context) ([]*metric.Metric, e
return nil, err
}
- policyCountMap := make(map[string]*metricAPI.PolicyCountMetric)
+ policyCountMap := make(map[string]*metricapi.PolicyCountMetric)
for _, policy := range policies {
var key string
@@ -80,7 +80,7 @@ func (c *policyCountCollector) Collect(ctx context.Context) ([]*metric.Metric, e
}
if _, ok := policyCountMap[key]; !ok {
- policyCountMap[key] = &metricAPI.PolicyCountMetric{
+ policyCountMap[key] = &metricapi.PolicyCountMetric{
Type: policy.Type,
Value: value,
EnvironmentName: environment.Title,
@@ -93,7 +93,7 @@ func (c *policyCountCollector) Collect(ctx context.Context) ([]*metric.Metric, e
for _, policyCountMetric := range policyCountMap {
res = append(res, &metric.Metric{
- Name: metricAPI.PolicyCountMetricName,
+ Name: metricapi.PolicyCountMetricName,
Value: policyCountMetric.Count,
Labels: map[string]any{
"type": string(policyCountMetric.Type),
diff --git a/backend/metric/collector/project_count.go b/backend/metric/collector/project_count.go
index 3cd8562fd4..161f599d89 100644
--- a/backend/metric/collector/project_count.go
+++ b/backend/metric/collector/project_count.go
@@ -3,7 +3,7 @@ package collector
import (
"context"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
"github.com/bytebase/bytebase/backend/store"
)
@@ -33,7 +33,7 @@ func (c *projectCountCollector) Collect(ctx context.Context) ([]*metric.Metric,
for _, projectCountMetric := range projectCountMetricList {
res = append(res, &metric.Metric{
- Name: metricAPI.ProjectCountMetricName,
+ Name: metricapi.ProjectCountMetricName,
Value: projectCountMetric.Count,
Labels: map[string]any{
"tenant_mode": string(projectCountMetric.TenantMode),
diff --git a/backend/metric/collector/sheet_count.go b/backend/metric/collector/sheet_count.go
index b1c197a722..0c24242f5e 100644
--- a/backend/metric/collector/sheet_count.go
+++ b/backend/metric/collector/sheet_count.go
@@ -3,7 +3,7 @@ package collector
import (
"context"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
"github.com/bytebase/bytebase/backend/store"
)
@@ -33,7 +33,7 @@ func (c *sheetCountCollector) Collect(ctx context.Context) ([]*metric.Metric, er
for _, sheetCountMetric := range sheetCountMetricList {
res = append(res, &metric.Metric{
- Name: metricAPI.SheetCountMetricName,
+ Name: metricapi.SheetCountMetricName,
Value: sheetCountMetric.Count,
Labels: map[string]any{
"row_status": string(sheetCountMetric.RowStatus),
diff --git a/backend/metric/collector/task_count.go b/backend/metric/collector/task_count.go
index f1b163bb14..e3490b3e1f 100644
--- a/backend/metric/collector/task_count.go
+++ b/backend/metric/collector/task_count.go
@@ -3,7 +3,7 @@ package collector
import (
"context"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
"github.com/bytebase/bytebase/backend/store"
)
@@ -33,7 +33,7 @@ func (c *taskCountCollector) Collect(ctx context.Context) ([]*metric.Metric, err
for _, taskCountMetric := range taskCountMetricList {
res = append(res, &metric.Metric{
- Name: metricAPI.TaskCountMetricName,
+ Name: metricapi.TaskCountMetricName,
Value: taskCountMetric.Count,
Labels: map[string]any{
"type": string(taskCountMetric.Type),
diff --git a/backend/plugin/db/mongodb/sync.go b/backend/plugin/db/mongodb/sync.go
index 751652e413..db163263f4 100644
--- a/backend/plugin/db/mongodb/sync.go
+++ b/backend/plugin/db/mongodb/sync.go
@@ -182,7 +182,10 @@ func getIndexes(ctx context.Context, collection *mongo.Collection) ([]*storepb.I
if !ok {
return nil, errors.New("cannot get index name from index info")
}
- indexName := name.(string)
+ indexName, ok := name.(string)
+ if !ok {
+ return nil, errors.New("cannot cinvert index name to string")
+ }
key, ok := indexInfo["key"]
if !ok {
return nil, errors.New("cannot get index key from index info")
@@ -193,7 +196,10 @@ func getIndexes(ctx context.Context, collection *mongo.Collection) ([]*storepb.I
}
unique := false
if u, ok := indexInfo["unique"]; ok {
- unique = u.(bool)
+ unique, ok = u.(bool)
+ if !ok {
+ return nil, errors.New("cannot convert unique to bool")
+ }
}
if _, ok := indexMap[indexName]; !ok {
@@ -229,7 +235,11 @@ func (driver *Driver) getVersion(ctx context.Context) (string, error) {
if !ok {
return "", errors.New("cannot get version from buildInfo command result")
}
- return version.(string), nil
+ v, ok := version.(string)
+ if !ok {
+ return "", errors.New("cannot convert version to string")
+ }
+ return v, nil
}
// isDatabaseExist returns true if the database exists.
diff --git a/backend/plugin/db/mysql/binlog_stream_parser.go b/backend/plugin/db/mysql/binlog_stream_parser.go
index 76656627b6..e8a46f22ff 100644
--- a/backend/plugin/db/mysql/binlog_stream_parser.go
+++ b/backend/plugin/db/mysql/binlog_stream_parser.go
@@ -187,8 +187,7 @@ func getEventType(header string) BinlogEventType {
return UpdateRowsEventType
} else if strings.Contains(header, "Delete_rows") {
return DeleteRowsEventType
- } else {
- // Ignore other events.
- return UnknownEventType
}
+ // Ignore other events.
+ return UnknownEventType
}
diff --git a/backend/plugin/db/oracle/oracle.go b/backend/plugin/db/oracle/oracle.go
index ebd65b1361..9e16489d0c 100644
--- a/backend/plugin/db/oracle/oracle.go
+++ b/backend/plugin/db/oracle/oracle.go
@@ -13,7 +13,7 @@ import (
// Import go-ora Oracle driver.
"github.com/pkg/errors"
- go_ora "github.com/sijms/go-ora/v2"
+ goora "github.com/sijms/go-ora/v2"
"google.golang.org/protobuf/types/known/durationpb"
"github.com/bytebase/bytebase/backend/common/log"
@@ -57,7 +57,7 @@ func (driver *Driver) Open(ctx context.Context, _ storepb.Engine, config db.Conn
if config.SID != "" {
options["SID"] = config.SID
}
- dsn := go_ora.BuildUrl(config.Host, port, config.ServiceName, config.Username, config.Password, options)
+ dsn := goora.BuildUrl(config.Host, port, config.ServiceName, config.Username, config.Password, options)
db, err := sql.Open("oracle", dsn)
if err != nil {
return nil, err
diff --git a/backend/plugin/db/spanner/spanner.go b/backend/plugin/db/spanner/spanner.go
index fdacbe7f1d..f4b9695a4a 100644
--- a/backend/plugin/db/spanner/spanner.go
+++ b/backend/plugin/db/spanner/spanner.go
@@ -9,7 +9,7 @@ import (
"strings"
"time"
- spanner "cloud.google.com/go/spanner"
+ "cloud.google.com/go/spanner"
spannerdb "cloud.google.com/go/spanner/admin/database/apiv1"
"cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
diff --git a/backend/plugin/parser/mybatis/mapper/parser.go b/backend/plugin/parser/mybatis/mapper/parser.go
index 894a65e46b..157c61943f 100644
--- a/backend/plugin/parser/mybatis/mapper/parser.go
+++ b/backend/plugin/parser/mybatis/mapper/parser.go
@@ -67,7 +67,11 @@ func (p *Parser) Parse() (*ast.RootNode, error) {
case xml.StartElement:
newNode := p.newNodeByStartElement(&ele)
if ele.Name.Local == "sql" {
- p.sqlMap[newNode.(*ast.SQLNode).ID] = newNode.(*ast.SQLNode)
+ node, ok := newNode.(*ast.SQLNode)
+ if !ok {
+ return nil, errors.Errorf("failed convert to SQL node")
+ }
+ p.sqlMap[newNode.(*ast.SQLNode).ID] = node
}
startElementStack = append(startElementStack, &ele)
nodeStack = append(nodeStack, newNode)
diff --git a/backend/plugin/parser/mybatis/mapper/parser_test.go b/backend/plugin/parser/mybatis/mapper/parser_test.go
index 4c5cabe564..a42d49f164 100644
--- a/backend/plugin/parser/mybatis/mapper/parser_test.go
+++ b/backend/plugin/parser/mybatis/mapper/parser_test.go
@@ -7,7 +7,7 @@ import (
"strings"
"testing"
- pg_query "github.com/pganalyze/pg_query_go/v4"
+ pgquery "github.com/pganalyze/pg_query_go/v4"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
@@ -53,7 +53,7 @@ func runTest(t *testing.T, filepath string, record bool) {
}
// The result should be parsed correctly by PostgreSQL parser.
- _, err = pg_query.Parse(testCases[i].PostgreSQL)
+ _, err = pgquery.Parse(testCases[i].PostgreSQL)
require.NoError(t, err, "failed to parse restored sql with PostgreSQL parser: %s", testCases[i].PostgreSQL)
stringsBuilder.Reset()
diff --git a/backend/plugin/parser/pg/pg_test.go b/backend/plugin/parser/pg/pg_test.go
index e2862ad2ed..421a99b68a 100644
--- a/backend/plugin/parser/pg/pg_test.go
+++ b/backend/plugin/parser/pg/pg_test.go
@@ -27,7 +27,8 @@ func TestPostgreSQLParser(t *testing.T) {
for _, test := range tests {
res, err := ParsePostgreSQL(test.statement)
if res != nil {
- _, _ = res.Tree.(*parser.RootContext)
+ _, ok := res.Tree.(*parser.RootContext)
+ require.True(t, ok)
}
if test.errorMessage == "" {
require.NoError(t, err)
diff --git a/backend/plugin/parser/pg/query.go b/backend/plugin/parser/pg/query.go
index 8334026c4e..d7022a2962 100644
--- a/backend/plugin/parser/pg/query.go
+++ b/backend/plugin/parser/pg/query.go
@@ -9,6 +9,7 @@ import (
pgquery "github.com/pganalyze/pg_query_go/v4"
pgparser "github.com/pganalyze/pg_query_go/v4/parser"
+ "github.com/pkg/errors"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/plugin/parser/base"
@@ -123,7 +124,10 @@ func ExtractResourceList(currentDatabase string, currentSchema string, sql strin
}
resourceMap := make(map[string]base.SchemaResource)
- list := extractRangeVarFromJSON(currentDatabase, currentSchema, jsonData)
+ list, err := extractRangeVarFromJSON(currentDatabase, currentSchema, jsonData)
+ if err != nil {
+ return nil, err
+ }
for _, resource := range list {
resourceMap[resource.String()] = resource
}
@@ -137,19 +141,30 @@ func ExtractResourceList(currentDatabase string, currentSchema string, sql strin
return list, nil
}
-func extractRangeVarFromJSON(currentDatabase string, currentSchema string, jsonData map[string]any) []base.SchemaResource {
+func extractRangeVarFromJSON(currentDatabase string, currentSchema string, jsonData map[string]any) ([]base.SchemaResource, error) {
var result []base.SchemaResource
if jsonData["RangeVar"] != nil {
resource := base.SchemaResource{
Database: currentDatabase,
Schema: currentSchema,
}
- rangeVar := jsonData["RangeVar"].(map[string]any)
+ rangeVar, ok := jsonData["RangeVar"].(map[string]any)
+ if !ok {
+ return nil, errors.Errorf("failed to convert range var")
+ }
if rangeVar["schemaname"] != nil {
- resource.Schema = rangeVar["schemaname"].(string)
+ schema, ok := rangeVar["schemaname"].(string)
+ if !ok {
+ return nil, errors.Errorf("failed to convert schemaname")
+ }
+ resource.Schema = schema
}
if rangeVar["relname"] != nil {
- resource.Table = rangeVar["relname"].(string)
+ table, ok := rangeVar["relname"].(string)
+ if !ok {
+ return nil, errors.Errorf("failed to convert relname")
+ }
+ resource.Table = table
}
result = append(result, resource)
}
@@ -157,17 +172,25 @@ func extractRangeVarFromJSON(currentDatabase string, currentSchema string, jsonD
for _, value := range jsonData {
switch v := value.(type) {
case map[string]any:
- result = append(result, extractRangeVarFromJSON(currentDatabase, currentSchema, v)...)
+ resources, err := extractRangeVarFromJSON(currentDatabase, currentSchema, v)
+ if err != nil {
+ return nil, err
+ }
+ result = append(result, resources...)
case []any:
for _, item := range v {
if m, ok := item.(map[string]any); ok {
- result = append(result, extractRangeVarFromJSON(currentDatabase, currentSchema, m)...)
+ resources, err := extractRangeVarFromJSON(currentDatabase, currentSchema, m)
+ if err != nil {
+ return nil, err
+ }
+ result = append(result, resources...)
}
}
}
}
- return result
+ return result, nil
}
func convertToSyntaxError(statement string, err error) *base.SyntaxError {
diff --git a/backend/plugin/parser/plsql/plsql_test.go b/backend/plugin/parser/plsql/plsql_test.go
index cdd7cb1ae8..987b0f7c72 100644
--- a/backend/plugin/parser/plsql/plsql_test.go
+++ b/backend/plugin/parser/plsql/plsql_test.go
@@ -32,8 +32,9 @@ func TestPLSQLParser(t *testing.T) {
for _, test := range tests {
tree, _, err := ParsePLSQL(test.statement)
- _, _ = tree.(*parser.Sql_scriptContext)
+ _, ok := tree.(*parser.Sql_scriptContext)
if test.errorMessage == "" {
+ require.True(t, ok)
require.NoError(t, err)
} else {
require.EqualError(t, err, test.errorMessage)
diff --git a/backend/plugin/parser/tidb/masking.go b/backend/plugin/parser/tidb/masking.go
index 28cd9bd18e..454059419f 100644
--- a/backend/plugin/parser/tidb/masking.go
+++ b/backend/plugin/parser/tidb/masking.go
@@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
- parser "github.com/pingcap/tidb/parser"
+ "github.com/pingcap/tidb/parser"
tidbast "github.com/pingcap/tidb/parser/ast"
"github.com/bytebase/bytebase/backend/plugin/parser/base"
diff --git a/backend/plugin/schema-engine/pg/structurer.go b/backend/plugin/schema-engine/pg/structurer.go
index 90a9c820fa..bf0e113240 100644
--- a/backend/plugin/schema-engine/pg/structurer.go
+++ b/backend/plugin/schema-engine/pg/structurer.go
@@ -12,7 +12,7 @@ import (
pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg"
- ast "github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
+ "github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
pgrawparser "github.com/bytebase/bytebase/backend/plugin/parser/sql/engine/pg"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.go
index 0684700762..e49b4d356d 100644
--- a/backend/runner/approval/runner.go
+++ b/backend/runner/approval/runner.go
@@ -19,7 +19,7 @@ import (
"go.uber.org/multierr"
"google.golang.org/protobuf/encoding/protojson"
- v1 "github.com/bytebase/bytebase/backend/api/v1"
+ apiv1 "github.com/bytebase/bytebase/backend/api/v1"
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/component/activity"
@@ -100,7 +100,10 @@ func (r *Runner) runOnce(ctx context.Context) {
var errs error
r.stateCfg.ApprovalFinding.Range(func(key, value any) bool {
- issue := value.(*store.IssueMessage)
+ issue, ok := value.(*store.IssueMessage)
+ if !ok {
+ return true
+ }
done, err := r.findApprovalTemplateForIssue(ctx, issue, risks, approvalSetting)
if err != nil {
errs = multierr.Append(errs, errors.Wrapf(err, "failed to find approval template for issue %v", issue.UID))
@@ -375,7 +378,7 @@ func getDatabaseGeneralIssueRisk(ctx context.Context, s *store.Store, licenseSer
}
}
- pipelineCreate, err := v1.GetPipelineCreate(ctx, s, licenseService, dbFactory, plan.Config.Steps, issue.Project)
+ pipelineCreate, err := apiv1.GetPipelineCreate(ctx, s, licenseService, dbFactory, plan.Config.Steps, issue.Project)
if err != nil {
return 0, store.RiskSourceUnknown, false, errors.Wrap(err, "failed to get pipeline create")
}
diff --git a/backend/runner/plancheck/statement_report_executor.go b/backend/runner/plancheck/statement_report_executor.go
index 25f39e5002..90f97928e3 100644
--- a/backend/runner/plancheck/statement_report_executor.go
+++ b/backend/runner/plancheck/statement_report_executor.go
@@ -21,7 +21,7 @@ import (
"github.com/bytebase/bytebase/backend/plugin/parser/base"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
pgrawparser "github.com/bytebase/bytebase/backend/plugin/parser/sql/engine/pg"
- tidb "github.com/bytebase/bytebase/backend/plugin/parser/tidb"
+ "github.com/bytebase/bytebase/backend/plugin/parser/tidb"
"github.com/bytebase/bytebase/backend/store"
"github.com/bytebase/bytebase/backend/utils"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
diff --git a/backend/runner/rollbackrun/runner.go b/backend/runner/rollbackrun/runner.go
index 2cdcb7fa54..01fdd772d3 100644
--- a/backend/runner/rollbackrun/runner.go
+++ b/backend/runner/rollbackrun/runner.go
@@ -52,7 +52,10 @@ func (r *Runner) Run(ctx context.Context, wg *sync.WaitGroup) {
select {
case <-ticker.C:
r.stateCfg.RollbackGenerate.Range(func(key, value any) bool {
- task := value.(*store.TaskMessage)
+ task, ok := value.(*store.TaskMessage)
+ if !ok {
+ return true
+ }
slog.Debug(fmt.Sprintf("Generating rollback SQL for task %d", task.ID))
ctx, cancel := context.WithCancel(ctx)
r.stateCfg.RollbackCancel.Store(task.ID, cancel)
diff --git a/backend/runner/taskrun/database_config_merge.go b/backend/runner/taskrun/database_config_merge.go
index 217f8c66a8..c47ab4b25b 100644
--- a/backend/runner/taskrun/database_config_merge.go
+++ b/backend/runner/taskrun/database_config_merge.go
@@ -4,8 +4,6 @@ import (
"reflect"
"sort"
- "google.golang.org/protobuf/proto"
-
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -142,7 +140,6 @@ func mergeColumnConfig(target, baseline, current *storepb.ColumnConfig) *storepb
// Current is never nil.
// If baseline = A, target = B, current = C, we should set merged value to B.
// If baseline = A, target = A, current = B, we should set merged value to B since there is no change intentially.
- current = proto.Clone(current).(*storepb.ColumnConfig)
if target.SemanticTypeId != baseline.SemanticTypeId {
current.SemanticTypeId = target.SemanticTypeId
}
diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.go
index 7855110e31..f0501f446a 100644
--- a/backend/runner/taskrun/executor.go
+++ b/backend/runner/taskrun/executor.go
@@ -24,7 +24,7 @@ import (
"github.com/bytebase/bytebase/backend/plugin/db"
"github.com/bytebase/bytebase/backend/plugin/db/mysql"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/transform"
- vcsPlugin "github.com/bytebase/bytebase/backend/plugin/vcs"
+ vcsplugin "github.com/bytebase/bytebase/backend/plugin/vcs"
"github.com/bytebase/bytebase/backend/store"
"github.com/bytebase/bytebase/backend/store/model"
"github.com/bytebase/bytebase/backend/utils"
@@ -653,11 +653,11 @@ func writeBackLatestSchema(
storage *store.Store,
repository *store.RepositoryMessage,
vcs *store.ExternalVersionControlMessage,
- pushEvent *vcsPlugin.PushEvent,
+ pushEvent *vcsplugin.PushEvent,
mi *db.MigrationInfo,
writebackBranch, latestSchemaFile string, schema string, bytebaseURL string,
) (string, error) {
- schemaFileMeta, err := vcsPlugin.Get(vcs.Type, vcsPlugin.ProviderConfig{}).ReadFileMeta(
+ schemaFileMeta, err := vcsplugin.Get(vcs.Type, vcsplugin.ProviderConfig{}).ReadFileMeta(
ctx,
common.OauthContext{
ClientID: vcs.ApplicationID,
@@ -669,8 +669,8 @@ func writeBackLatestSchema(
vcs.InstanceURL,
repository.ExternalID,
latestSchemaFile,
- vcsPlugin.RefInfo{
- RefType: vcsPlugin.RefTypeBranch,
+ vcsplugin.RefInfo{
+ RefType: vcsplugin.RefTypeBranch,
RefName: writebackBranch,
},
)
@@ -722,19 +722,19 @@ func writeBackLatestSchema(
return "", err
}
- schemaFileCommit := vcsPlugin.FileCommitCreate{
+ schemaFileCommit := vcsplugin.FileCommitCreate{
Branch: writebackBranch,
CommitMessage: commitMessage,
Content: schema,
- AuthorName: vcsPlugin.BytebaseAuthorName,
- AuthorEmail: vcsPlugin.BytebaseAuthorEmail,
+ AuthorName: vcsplugin.BytebaseAuthorName,
+ AuthorEmail: vcsplugin.BytebaseAuthorEmail,
}
if createSchemaFile {
slog.Debug("Create latest schema file",
slog.String("schema_file", latestSchemaFile),
)
- err := vcsPlugin.Get(vcs2.Type, vcsPlugin.ProviderConfig{}).CreateFile(
+ err := vcsplugin.Get(vcs2.Type, vcsplugin.ProviderConfig{}).CreateFile(
ctx,
common.OauthContext{
ClientID: vcs2.ApplicationID,
@@ -758,7 +758,7 @@ func writeBackLatestSchema(
schemaFileCommit.LastCommitID = schemaFileMeta.LastCommitID
schemaFileCommit.SHA = schemaFileMeta.SHA
- err := vcsPlugin.Get(vcs2.Type, vcsPlugin.ProviderConfig{}).OverwriteFile(
+ err := vcsplugin.Get(vcs2.Type, vcsplugin.ProviderConfig{}).OverwriteFile(
ctx,
common.OauthContext{
ClientID: vcs2.ApplicationID,
@@ -786,7 +786,7 @@ func writeBackLatestSchema(
}
// VCS such as GitLab API doesn't return the commit on write, so we have to call ReadFileMeta again
- schemaFileMeta, err = vcsPlugin.Get(vcs2.Type, vcsPlugin.ProviderConfig{}).ReadFileMeta(
+ schemaFileMeta, err = vcsplugin.Get(vcs2.Type, vcsplugin.ProviderConfig{}).ReadFileMeta(
ctx,
common.OauthContext{
ClientID: vcs2.ApplicationID,
@@ -798,8 +798,8 @@ func writeBackLatestSchema(
vcs2.InstanceURL,
repo2.ExternalID,
latestSchemaFile,
- vcsPlugin.RefInfo{
- RefType: vcsPlugin.RefTypeBranch,
+ vcsplugin.RefInfo{
+ RefType: vcsplugin.RefTypeBranch,
RefName: writebackBranch,
},
)
diff --git a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
index 7c8b17927c..69024a5e40 100644
--- a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
+++ b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
@@ -103,7 +103,10 @@ func (e *SchemaUpdateGhostCutoverExecutor) RunOnce(ctx context.Context, _ contex
if !ok {
return true, nil, errors.Errorf("failed to get gh-ost state from sync task")
}
- sharedGhost := value.(sharedGhostState)
+ sharedGhost, ok := value.(sharedGhostState)
+ if !ok {
+ return true, nil, errors.Errorf("failed to convert shared gh-ost state")
+ }
// not using the rendered statement here because we want to avoid leaking the rendered statement
version := model.Version{Version: payload.SchemaVersion}
diff --git a/backend/sql-server/advise.go b/backend/sql-server/advise.go
index 1bac2513df..6c51a0d48e 100644
--- a/backend/sql-server/advise.go
+++ b/backend/sql-server/advise.go
@@ -7,7 +7,7 @@ import (
"io"
"net/http"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/labstack/echo/v4"
"gopkg.in/yaml.v3"
@@ -117,7 +117,7 @@ func (s *Server) sqlCheckController(c echo.Context) error {
}
s.metricReporter.Report(&metric.Metric{
- Name: metricAPI.SQLAdviseAPIMetricName,
+ Name: metricapi.SQLAdviseAPIMetricName,
Value: 1,
Labels: map[string]any{
"database_type": engineType.String(),
diff --git a/backend/sql-server/metric.go b/backend/sql-server/metric.go
index 41764b5b5e..d532ea8d13 100644
--- a/backend/sql-server/metric.go
+++ b/backend/sql-server/metric.go
@@ -8,7 +8,7 @@ import (
"github.com/labstack/echo/v4"
"github.com/bytebase/bytebase/backend/common/log"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
+ metricapi "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
)
@@ -25,7 +25,7 @@ func (m *metricReporter) Report(metric *metric.Metric) {
if err := m.reporter.Report(m.workspaceID, metric); err != nil {
slog.Error(
"Failed to report metric",
- slog.String("metric", string(metricAPI.OpenAPIMetricName)),
+ slog.String("metric", string(metricapi.OpenAPIMetricName)),
log.BBError(err),
)
}
@@ -42,7 +42,7 @@ func metricMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
responseCode := c.Response().Status
s.metricReporter.Report(&metric.Metric{
- Name: metricAPI.OpenAPIMetricName,
+ Name: metricapi.OpenAPIMetricName,
Value: 1,
Labels: map[string]any{
"latency_ns": strconv.FormatInt(duration.Nanoseconds(), 10),