Skip to content

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

chore: clean-up golangci-lint warning (#5415)

Danny Xufc8b62d0b9fe
diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml
index 0720ab7b71..bbe01622fc 100644
--- a/.github/workflows/backend-tests.yml
+++ b/.github/workflows/backend-tests.yml
@@ -37,7 +37,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
- version: v1.51.2
+ version: v1.52.2
args: --verbose --timeout 10m --max-same-issues=30
skip-cache: true
diff --git a/backend/bin/bb/cmd/migrate.go b/backend/bin/bb/cmd/migrate.go
index f4b2247fff..9b4967b719 100644
--- a/backend/bin/bb/cmd/migrate.go
+++ b/backend/bin/bb/cmd/migrate.go
@@ -52,7 +52,7 @@ func newMigrateCmd() *cobra.Command {
}
sqlReader := io.MultiReader(sqlReaders...)
- return migrateDatabase(context.Background(), u, description, issueID, false /*createDatabase*/, sqlReader)
+ return migrateDatabase(context.Background(), u, description, issueID, false /* createDatabase */, sqlReader)
}}
migrateCmd.Flags().StringVar(&dsn, "dsn", "", dsnUsage)
diff --git a/backend/plugin/advisor/mysql/advisor_syntax.go b/backend/plugin/advisor/mysql/advisor_syntax.go
index 223deec53a..0c32d5508e 100644
--- a/backend/plugin/advisor/mysql/advisor_syntax.go
+++ b/backend/plugin/advisor/mysql/advisor_syntax.go
@@ -27,7 +27,7 @@ func (*SyntaxAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Ad
// the TiDB unsupported statements, otherwise, the parser will panic or return the error.
_, supportStmt, err := parser.ExtractTiDBUnsupportStmts(statement)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []advisor.Advice{
{
Status: advisor.Error,
@@ -41,7 +41,7 @@ func (*SyntaxAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Ad
_, warns, err := p.Parse(supportStmt, ctx.Charset, ctx.Collation)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []advisor.Advice{
{
Status: advisor.Error,
@@ -55,7 +55,7 @@ func (*SyntaxAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Ad
if ctx.SyntaxMode == advisor.SyntaxModeSDL {
if line, err := transform.CheckFormat(parser.MySQL, statement); err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []advisor.Advice{
{
Status: advisor.Error,
@@ -116,7 +116,7 @@ func getWarnWithLine(statement string, charset string, collation string) []advis
func calculateErrorLine(statement string, charset string, collation string) int {
list, err := parser.SplitMultiSQL(parser.MySQL, statement)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return 1
}
diff --git a/backend/plugin/advisor/pg/parser.go b/backend/plugin/advisor/pg/parser.go
index 4ae8dfb607..8c55cf5340 100644
--- a/backend/plugin/advisor/pg/parser.go
+++ b/backend/plugin/advisor/pg/parser.go
@@ -42,7 +42,7 @@ func parseStatement(statement string) ([]ast.Node, []advisor.Advice) {
func calculateErrorLine(statement string) int {
statementList, err := parser.SplitMultiSQL(parser.Postgres, statement)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return 1
}
diff --git a/backend/plugin/db/mysql/dump.go b/backend/plugin/db/mysql/dump.go
index 4e29fd1d79..f1e0d41409 100644
--- a/backend/plugin/db/mysql/dump.go
+++ b/backend/plugin/db/mysql/dump.go
@@ -409,6 +409,9 @@ func GetBinlogInfo(ctx context.Context, db *sql.DB) (api.BinlogInfo, error) {
return api.BinlogInfo{}, errors.Wrapf(err, "cannot scan row from %q query", query)
}
}
+ if err := rows.Err(); err != nil {
+ return api.BinlogInfo{}, err
+ }
if !scanOneRow {
// SHOW MASTER STATUS returns empty row when binlog is off. We should not fail migration in this case for this expected case.
return api.BinlogInfo{}, nil
diff --git a/backend/plugin/db/mysql/restore.go b/backend/plugin/db/mysql/restore.go
index 6b7f5ba120..58f995c25c 100644
--- a/backend/plugin/db/mysql/restore.go
+++ b/backend/plugin/db/mysql/restore.go
@@ -839,7 +839,7 @@ func (driver *Driver) GetSortedBinlogFilesOnServer(ctx context.Context) ([]Binlo
var name string
var size int64
var unused any
- if err := rows.Scan(&name, &size, &unused /*Encrypted column*/); err != nil {
+ if err := rows.Scan(&name, &size, &unused /* encrypted column */); err != nil {
return nil, err
}
binlogFile, err := newBinlogFile(name, size)
diff --git a/backend/plugin/db/redshift/sync.go b/backend/plugin/db/redshift/sync.go
index b7f58f69c7..0ac3c9d51d 100644
--- a/backend/plugin/db/redshift/sync.go
+++ b/backend/plugin/db/redshift/sync.go
@@ -645,6 +645,9 @@ func (driver *Driver) getVersion(ctx context.Context) (string, error) {
return "", err
}
}
+ if err := rows.Err(); err != nil {
+ return "", err
+ }
// We try to parse the version string to get the PostgreSQL version and the Redshift version, but it's not a big deal if we fail.
// We will just return the version string as is.
pgVersion, redshiftVersion, err := getPgVersionAndRedshiftVersion(version)
diff --git a/backend/plugin/db/snowflake/sync.go b/backend/plugin/db/snowflake/sync.go
index 87f818136c..e6d9b330b4 100644
--- a/backend/plugin/db/snowflake/sync.go
+++ b/backend/plugin/db/snowflake/sync.go
@@ -148,6 +148,9 @@ func (driver *Driver) getSchemaList(ctx context.Context, database string) ([]str
}
result = append(result, schemaName)
}
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
return result, nil
}
diff --git a/backend/plugin/db/util/driverutil.go b/backend/plugin/db/util/driverutil.go
index c23934e91f..562ab1042f 100644
--- a/backend/plugin/db/util/driverutil.go
+++ b/backend/plugin/db/util/driverutil.go
@@ -163,7 +163,7 @@ func ExecuteMigration(ctx context.Context, executor MigrationExecutor, m *db.Mig
if !m.CreateDatabase && executor.GetType() != db.MongoDB {
// For baseline migration, we also record the live schema to detect the schema drift.
// See https://bytebase.com/blog/what-is-database-schema-drift
- if _, err := executor.Dump(ctx, m.Database, &prevSchemaBuf, true /*schemaOnly*/); err != nil {
+ if _, err := executor.Dump(ctx, m.Database, &prevSchemaBuf, true /* schemaOnly */); err != nil {
return "", "", FormatError(err)
}
}
@@ -181,7 +181,7 @@ func ExecuteMigration(ctx context.Context, executor MigrationExecutor, m *db.Mig
startedNs := time.Now().UnixNano()
defer func() {
- if err := EndMigration(ctx, executor, startedNs, insertedID, updatedSchema, databaseName, resErr == nil /*isDone*/); err != nil {
+ if err := EndMigration(ctx, executor, startedNs, insertedID, updatedSchema, databaseName, resErr == nil /* isDone */); err != nil {
log.Error("Failed to update migration history record",
zap.Error(err),
zap.String("migration_id", migrationHistoryID),
@@ -219,7 +219,7 @@ func ExecuteMigration(ctx context.Context, executor MigrationExecutor, m *db.Mig
}
// Phase 4 - Dump the schema after migration
var afterSchemaBuf bytes.Buffer
- if _, err := executor.Dump(ctx, m.Database, &afterSchemaBuf, true /*schemaOnly*/); err != nil {
+ if _, err := executor.Dump(ctx, m.Database, &afterSchemaBuf, true /* schemaOnly */); err != nil {
// We will ignore the dump error if the database is dropped.
if strings.Contains(err.Error(), "not found") {
return insertedID, "", nil
diff --git a/backend/plugin/vcs/internal/oauth/oauth.go b/backend/plugin/vcs/internal/oauth/oauth.go
index 79be1255a8..908d35e6b4 100644
--- a/backend/plugin/vcs/internal/oauth/oauth.go
+++ b/backend/plugin/vcs/internal/oauth/oauth.go
@@ -156,7 +156,7 @@ func getOAuthErrorDetails(code int, body []byte) error {
var oe oauthError
if err := json.Unmarshal(body, &oe); err != nil {
// If we failed to unmarshal body with oauth error, it's not oauthError and we should return nil.
- //nolint:nilerr
+ // nolint:nilerr
return nil
}
// https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/
diff --git a/backend/runner/anomaly/scanner.go b/backend/runner/anomaly/scanner.go
index 3c0aad6a35..f9a2f8a12d 100644
--- a/backend/runner/anomaly/scanner.go
+++ b/backend/runner/anomaly/scanner.go
@@ -242,7 +242,7 @@ func (s *Scanner) checkDatabaseAnomaly(ctx context.Context, instance *store.Inst
return
}
var schemaBuf bytes.Buffer
- if _, err := driver.Dump(ctx, database.DatabaseName, &schemaBuf, true /*schemaOnly*/); err != nil {
+ if _, err := driver.Dump(ctx, database.DatabaseName, &schemaBuf, true /* schemaOnly */); err != nil {
if common.ErrorCode(err) == common.NotFound {
log.Debug("Failed to check anomaly",
zap.String("instance", instance.ResourceID),
diff --git a/backend/runner/taskcheck/statement_affected_rows_report_executor.go b/backend/runner/taskcheck/statement_affected_rows_report_executor.go
index 5bffc742b8..19a33139ea 100644
--- a/backend/runner/taskcheck/statement_affected_rows_report_executor.go
+++ b/backend/runner/taskcheck/statement_affected_rows_report_executor.go
@@ -98,7 +98,7 @@ func (s *StatementAffectedRowsReportExecutor) Run(ctx context.Context, _ *store.
func reportStatementAffectedRowsForPostgres(ctx context.Context, sqlDB *sql.DB, statement string) ([]api.TaskCheckResult, error) {
stmts, err := parser.Parse(parser.Postgres, parser.ParseContext{}, statement)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
@@ -115,7 +115,7 @@ func reportStatementAffectedRowsForPostgres(ctx context.Context, sqlDB *sql.DB,
for _, stmt := range stmts {
rowCount, err := getAffectedRowsForPostgres(ctx, sqlDB, stmt)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
@@ -226,7 +226,7 @@ func getAffectedRowsCountForPostgres(res []any) (int64, error) {
func reportStatementAffectedRowsForMySQL(ctx context.Context, sqlDB *sql.DB, statement, charset, collation string) ([]api.TaskCheckResult, error) {
singleSQLs, err := parser.SplitMultiSQL(parser.MySQL, statement)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
@@ -259,7 +259,7 @@ func reportStatementAffectedRowsForMySQL(ctx context.Context, sqlDB *sql.DB, sta
}
root, _, err := p.Parse(stmt.Text, charset, collation)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
@@ -283,7 +283,7 @@ func reportStatementAffectedRowsForMySQL(ctx context.Context, sqlDB *sql.DB, sta
}
affectedRows, err := getAffectedRowsForMysql(ctx, sqlDB, root[0])
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
diff --git a/backend/runner/taskcheck/statement_type_executor.go b/backend/runner/taskcheck/statement_type_executor.go
index 041e37f708..f8c03910a0 100644
--- a/backend/runner/taskcheck/statement_type_executor.go
+++ b/backend/runner/taskcheck/statement_type_executor.go
@@ -229,7 +229,7 @@ func mysqlStatementTypeCheck(statement string, charset string, collation string,
// the TiDB unsupported statements, otherwise, the parser will panic or return the error.
unsupportStmt, supportStmt, err := parser.ExtractTiDBUnsupportStmts(statement)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
@@ -251,7 +251,7 @@ func mysqlStatementTypeCheck(statement string, charset string, collation string,
stmts, _, err := p.Parse(supportStmt, charset, collation)
if err != nil {
- //nolint: nilerr
+ // nolint: nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
@@ -264,7 +264,7 @@ func mysqlStatementTypeCheck(statement string, charset string, collation string,
}
if err != nil {
- //nolint: nilerr
+ // nolint: nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
@@ -344,7 +344,7 @@ func postgresqlCreateAndDropDatabaseCheck(nodeList []ast.Node) []api.TaskCheckRe
func postgresqlStatementTypeCheck(statement string, taskType api.TaskType) (result []api.TaskCheckResult, err error) {
stmts, err := parser.Parse(parser.Postgres, parser.ParseContext{}, statement)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
diff --git a/backend/runner/taskcheck/statement_type_report_executor.go b/backend/runner/taskcheck/statement_type_report_executor.go
index 78b6a46cfd..088b17156f 100644
--- a/backend/runner/taskcheck/statement_type_report_executor.go
+++ b/backend/runner/taskcheck/statement_type_report_executor.go
@@ -79,7 +79,7 @@ func (s *StatementTypeReportExecutor) Run(ctx context.Context, _ *store.TaskChec
func reportStatementTypeForMySQL(statement, charset, collation string) ([]api.TaskCheckResult, error) {
singleSQLs, err := parser.SplitMultiSQL(parser.MySQL, statement)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
@@ -112,7 +112,7 @@ func reportStatementTypeForMySQL(statement, charset, collation string) ([]api.Ta
}
root, _, err := p.Parse(stmt.Text, charset, collation)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
@@ -150,7 +150,7 @@ func reportStatementTypeForMySQL(statement, charset, collation string) ([]api.Ta
func reportStatementTypeForPostgres(statement string) ([]api.TaskCheckResult, error) {
stmts, err := parser.Parse(parser.Postgres, parser.ParseContext{}, statement)
if err != nil {
- //nolint:nilerr
+ // nolint:nilerr
return []api.TaskCheckResult{
{
Status: api.TaskCheckStatusError,
diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.go
index ad17e28dbf..1c7a766ef6 100644
--- a/backend/runner/taskrun/executor.go
+++ b/backend/runner/taskrun/executor.go
@@ -246,6 +246,9 @@ func getSetOracleTransactionIDFunc(ctx context.Context, task *store.TaskMessage,
return nil
}
}
+ if err := transactionID.Err(); err != nil {
+ return err
+ }
payload.TransactionID = txID
updatedPayload, err := json.Marshal(payload)
if err != nil {
diff --git a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
index d1c80d3a04..a74b04a577 100644
--- a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
+++ b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
@@ -150,7 +150,7 @@ func cutover(ctx context.Context, stores *store.Store, dbFactory *dbfactory.DBFa
startedNs := time.Now().UnixNano()
defer func() {
- if err := utils.EndMigration(ctx, stores, startedNs, insertedID, updatedSchema, db.BytebaseDatabase, resErr == nil /*isDone*/); err != nil {
+ if err := utils.EndMigration(ctx, stores, startedNs, insertedID, updatedSchema, db.BytebaseDatabase, resErr == nil /* isDone */); err != nil {
log.Error("failed to update migration history record",
zap.Error(err),
zap.String("migration_id", migrationHistoryID),
@@ -167,7 +167,7 @@ func cutover(ctx context.Context, stores *store.Store, dbFactory *dbfactory.DBFa
}
var afterSchemaBuf bytes.Buffer
- if _, err := executor.Dump(ctx, mi.Database, &afterSchemaBuf, true /*schemaOnly*/); err != nil {
+ if _, err := executor.Dump(ctx, mi.Database, &afterSchemaBuf, true /* schemaOnly */); err != nil {
return "", "", util.FormatError(err)
}
diff --git a/backend/server/webhook_test.go b/backend/server/webhook_test.go
index 25187d18c1..635c5b6cf9 100644
--- a/backend/server/webhook_test.go
+++ b/backend/server/webhook_test.go
@@ -14,7 +14,7 @@ import (
// TODO(d): fix the double underscore "__".
func TestValidateGitHubWebhookSignature256(t *testing.T) {
- //nolint:misspell
+ // nolint:misspell
const payload = `{"ref":"refs/heads/main","before":"07da1e122bdbb81da8499b6d82c6b6302581a5a7","after":"5a96148ac5ef11a53b838b8cc0d9c929420657f3","repository":{"id":470746482,"node_id":"R_kgDOHA8Fcg","name":"bytebase-test","full_name":"unknwon/bytebase-test","private":true,"owner":{"name":"unknwon","email":"[email protected]","login":"unknwon","id":2946214,"node_id":"MDQ6VXNlcjI5NDYyMTQ=","avatar_url":"https://avatars.githubusercontent.com/u/2946214?v=4","gravatar_id":"","url":"https://api.github.com/users/unknwon","html_url":"https://github.com/unknwon","followers_url":"https://api.github.com/users/unknwon/followers","following_url":"https://api.github.com/users/unknwon/following{/other_user}","gists_url":"https://api.github.com/users/unknwon/gists{/gist_id}","starred_url":"https://api.github.com/users/unknwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unknwon/subscriptions","organizations_url":"https://api.github.com/users/unknwon/orgs","repos_url":"https://api.github.com/users/unknwon/repos","events_url":"https://api.github.com/users/unknwon/events{/privacy}","received_events_url":"https://api.github.com/users/unknwon/received_events","type":"User","site_admin":false},"html_url":"https://github.com/unknwon/bytebase-test","description":null,"fork":false,"url":"https://github.com/unknwon/bytebase-test","forks_url":"https://api.github.com/repos/unknwon/bytebase-test/forks","keys_url":"https://api.github.com/repos/unknwon/bytebase-test/keys{/key_id}","collaborators_url":"https://api.github.com/repos/unknwon/bytebase-test/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/unknwon/bytebase-test/teams","hooks_url":"https://api.github.com/repos/unknwon/bytebase-test/hooks","issue_events_url":"https://api.github.com/repos/unknwon/bytebase-test/issues/events{/number}","events_url":"https://api.github.com/repos/unknwon/bytebase-test/events","assignees_url":"https://api.github.com/repos/unknwon/bytebase-test/assignees{/user}","branches_url":"https://api.github.com/repos/unknwon/bytebase-test/branches{/branch}","tags_url":"https://api.github.com/repos/unknwon/bytebase-test/tags","blobs_url":"https://api.github.com/repos/unknwon/bytebase-test/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/unknwon/bytebase-test/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/unknwon/bytebase-test/git/refs{/sha}","trees_url":"https://api.github.com/repos/unknwon/bytebase-test/git/trees{/sha}","statuses_url":"https://api.github.com/repos/unknwon/bytebase-test/statuses/{sha}","languages_url":"https://api.github.com/repos/unknwon/bytebase-test/languages","stargazers_url":"https://api.github.com/repos/unknwon/bytebase-test/stargazers","contributors_url":"https://api.github.com/repos/unknwon/bytebase-test/contributors","subscribers_url":"https://api.github.com/repos/unknwon/bytebase-test/subscribers","subscription_url":"https://api.github.com/repos/unknwon/bytebase-test/subscription","commits_url":"https://api.github.com/repos/unknwon/bytebase-test/commits{/sha}","git_commits_url":"https://api.github.com/repos/unknwon/bytebase-test/git/commits{/sha}","comments_url":"https://api.github.com/repos/unknwon/bytebase-test/comments{/number}","issue_comment_url":"https://api.github.com/repos/unknwon/bytebase-test/issues/comments{/number}","contents_url":"https://api.github.com/repos/unknwon/bytebase-test/contents/{+path}","compare_url":"https://api.github.com/repos/unknwon/bytebase-test/compare/{base}...{head}","merges_url":"https://api.github.com/repos/unknwon/bytebase-test/merges","archive_url":"https://api.github.com/repos/unknwon/bytebase-test/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/unknwon/bytebase-test/downloads","issues_url":"https://api.github.com/repos/unknwon/bytebase-test/issues{/number}","pulls_url":"https://api.github.com/repos/unknwon/bytebase-test/pulls{/number}","milestones_url":"https://api.github.com/repos/unknwon/bytebase-test/milestones{/number}","notifications_url":"https://api.github.com/repos/unknwon/bytebase-test/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/unknwon/bytebase-test/labels{/name}","releases_url":"https://api.github.com/repos/unknwon/bytebase-test/releases{/id}","deployments_url":"https://api.github.com/repos/unknwon/bytebase-test/deployments","created_at":1647463607,"updated_at":"2022-03-16T20:46:47Z","pushed_at":1658671596,"git_url":"git://github.com/unknwon/bytebase-test.git","ssh_url":"[email protected]:unknwon/bytebase-test.git","clone_url":"https://github.com/unknwon/bytebase-test.git","svn_url":"https://github.com/unknwon/bytebase-test","homepage":null,"size":20,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"allow_forking":true,"is_template":false,"web_commit_signoff_required":false,"topics":[],"visibility":"private","forks":0,"open_issues":0,"watchers":0,"default_branch":"main","stargazers":0,"master_branch":"main"},"pusher":{"name":"unknwon","email":"[email protected]"},"sender":{"login":"unknwon","id":2946214,"node_id":"MDQ6VXNlcjI5NDYyMTQ=","avatar_url":"https://avatars.githubusercontent.com/u/2946214?v=4","gravatar_id":"","url":"https://api.github.com/users/unknwon","html_url":"https://github.com/unknwon","followers_url":"https://api.github.com/users/unknwon/followers","following_url":"https://api.github.com/users/unknwon/following{/other_user}","gists_url":"https://api.github.com/users/unknwon/gists{/gist_id}","starred_url":"https://api.github.com/users/unknwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unknwon/subscriptions","organizations_url":"https://api.github.com/users/unknwon/orgs","repos_url":"https://api.github.com/users/unknwon/repos","events_url":"https://api.github.com/users/unknwon/events{/privacy}","received_events_url":"https://api.github.com/users/unknwon/received_events","type":"User","site_admin":false},"created":false,"deleted":false,"forced":false,"base_ref":null,"compare":"https://github.com/unknwon/bytebase-test/compare/07da1e122bdb...5a96148ac5ef","commits":[{"id":"5a96148ac5ef11a53b838b8cc0d9c929420657f3","tree_id":"8a842b23b62886d2ee12c152eda741cf39b1ceef","distinct":true,"message":"Create testdb_dev__202101131000__baseline__create_tablefoo_for_bar.sql","timestamp":"2022-07-24T22:06:36+08:00","url":"https://github.com/unknwon/bytebase-test/commit/5a96148ac5ef11a53b838b8cc0d9c929420657f3","author":{"name":"Joe Chen","email":"[email protected]","username":"unknwon"},"committer":{"name":"GitHub","email":"[email protected]","username":"web-flow"},"added":["Dev/testdb_dev__202101131000__baseline__create_tablefoo_for_bar.sql"],"removed":[],"modified":[]}],"head_commit":{"id":"5a96148ac5ef11a53b838b8cc0d9c929420657f3","tree_id":"8a842b23b62886d2ee12c152eda741cf39b1ceef","distinct":true,"message":"Create testdb_dev__202101131000__baseline__create_tablefoo_for_bar.sql","timestamp":"2022-07-24T22:06:36+08:00","url":"https://github.com/unknwon/bytebase-test/commit/5a96148ac5ef11a53b838b8cc0d9c929420657f3","author":{"name":"Joe Chen","email":"[email protected]","username":"unknwon"},"committer":{"name":"GitHub","email":"[email protected]","username":"web-flow"},"added":["Dev/testdb_dev__202101131000__baseline__create_tablefoo_for_bar.sql"],"removed":[],"modified":[]}}`
t.Run("wrong key", func(t *testing.T) {
diff --git a/backend/store/data_source.go b/backend/store/data_source.go
index d63a3975f3..0bf25cc841 100644
--- a/backend/store/data_source.go
+++ b/backend/store/data_source.go
@@ -116,6 +116,9 @@ func (*Store) listDataSourceV2(ctx context.Context, tx *Tx, instanceID string) (
dataSourceMessages = append(dataSourceMessages, &dataSourceMessage)
}
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
return dataSourceMessages, nil
}
diff --git a/backend/store/database.go b/backend/store/database.go
index 00f43792da..47d7aa1181 100644
--- a/backend/store/database.go
+++ b/backend/store/database.go
@@ -620,6 +620,9 @@ func (*Store) listDatabaseImplV2(ctx context.Context, tx *Tx, find *FindDatabase
databaseMessages = append(databaseMessages, &databaseMessage)
}
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
return databaseMessages, nil
}
diff --git a/backend/store/environment.go b/backend/store/environment.go
index 306c418a37..f15129a198 100644
--- a/backend/store/environment.go
+++ b/backend/store/environment.go
@@ -447,6 +447,10 @@ func listEnvironmentImplV2(ctx context.Context, tx *Tx, find *FindEnvironmentMes
environments = append(environments, &environment)
}
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+
return environments, nil
}
diff --git a/backend/store/idp.go b/backend/store/idp.go
index d0b86ead97..a5a38584b3 100644
--- a/backend/store/idp.go
+++ b/backend/store/idp.go
@@ -301,6 +301,9 @@ func (*Store) listIdentityProvidersImpl(ctx context.Context, tx *Tx, find *FindI
identityProviderMessage.Deleted = convertRowStatusToDeleted(rowStatus)
identityProviderMessages = append(identityProviderMessages, &identityProviderMessage)
}
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
return identityProviderMessages, nil
}
diff --git a/backend/store/instance.go b/backend/store/instance.go
index 0df14a359c..0a935e3467 100644
--- a/backend/store/instance.go
+++ b/backend/store/instance.go
@@ -450,6 +450,9 @@ func (s *Store) listInstanceImplV2(ctx context.Context, tx *Tx, find *FindInstan
instanceMessage.Deleted = convertRowStatusToDeleted(rowStatus)
instanceMessages = append(instanceMessages, &instanceMessage)
}
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
for _, instanceMessage := range instanceMessages {
dataSourceList, err := s.listDataSourceV2(ctx, tx, instanceMessage.ResourceID)
diff --git a/backend/store/issue.go b/backend/store/issue.go
index 9e6425cb7d..920f392995 100644
--- a/backend/store/issue.go
+++ b/backend/store/issue.go
@@ -897,6 +897,9 @@ func (s *Store) ListIssueV2(ctx context.Context, find *FindIssueMessage) ([]*Iss
}
issues = append(issues, &issue)
}
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
if err := tx.Commit(); err != nil {
return nil, FormatError(err)
diff --git a/backend/store/pg_engine_test.go b/backend/store/pg_engine_test.go
index 7ff94c92be..ac48ebb887 100644
--- a/backend/store/pg_engine_test.go
+++ b/backend/store/pg_engine_test.go
@@ -181,7 +181,7 @@ func TestMigrationCompatibility(t *testing.T) {
// Create a database with release latest schema.
databaseName := "hidb"
// Passing curVers = nil will create the database.
- err = migrate(ctx, d, nil, common.ReleaseModeProd, false /*strictDb*/, serverVersion, databaseName)
+ err = migrate(ctx, d, nil, common.ReleaseModeProd, false /* strictDb */, serverVersion, databaseName)
require.NoError(t, err)
// Check migration history.
histories, err := d.FindMigrationHistoryList(ctx, &dbdriver.MigrationHistoryFind{
@@ -192,7 +192,7 @@ func TestMigrationCompatibility(t *testing.T) {
require.Equal(t, histories[0].Version, releaseVersion.String())
// Check no migration after passing current version as the release cutoff version.
- err = migrate(ctx, d, &releaseVersion, common.ReleaseModeProd, false /*strictDb*/, serverVersion, databaseName)
+ err = migrate(ctx, d, &releaseVersion, common.ReleaseModeProd, false /* strictDb */, serverVersion, databaseName)
require.NoError(t, err)
// Check migration history.
histories, err = d.FindMigrationHistoryList(ctx, &dbdriver.MigrationHistoryFind{
@@ -202,7 +202,7 @@ func TestMigrationCompatibility(t *testing.T) {
require.Len(t, histories, 1)
// Apply migration to dev latest if there are patches.
- err = migrate(ctx, d, &releaseVersion, common.ReleaseModeDev, false /*strictDb*/, serverVersion, databaseName)
+ err = migrate(ctx, d, &releaseVersion, common.ReleaseModeDev, false /* strictDb */, serverVersion, databaseName)
require.NoError(t, err)
// Check migration history.
diff --git a/backend/store/principal.go b/backend/store/principal.go
index 27099de273..0f5dfe76bd 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -254,6 +254,9 @@ func (*Store) listUserImpl(ctx context.Context, tx *Tx, find *FindUserMessage) (
userMessage.MFAConfig = &mfaConfig
userMessages = append(userMessages, &userMessage)
}
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
return userMessages, nil
}
diff --git a/backend/store/project.go b/backend/store/project.go
index c08b090143..28dd6cd245 100644
--- a/backend/store/project.go
+++ b/backend/store/project.go
@@ -480,6 +480,9 @@ func (s *Store) listProjectImplV2(ctx context.Context, tx *Tx, find *FindProject
projectMessage.Deleted = convertRowStatusToDeleted(rowStatus)
projectMessages = append(projectMessages, &projectMessage)
}
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
for _, project := range projectMessages {
projectWebhooks, err := s.findProjectWebhookImplV2(ctx, tx, &FindProjectWebhookMessage{ProjectID: &project.UID})
diff --git a/backend/store/project_member.go b/backend/store/project_member.go
index 4a2ed3d953..81b7e1244f 100644
--- a/backend/store/project_member.go
+++ b/backend/store/project_member.go
@@ -227,6 +227,9 @@ func (s *Store) getProjectPolicyImpl(ctx context.Context, tx *Tx, find *GetProje
}
roleMap[role] = append(roleMap[role], member)
}
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
var roles []api.Role
for role := range roleMap {
diff --git a/backend/tests/rollback_test.go b/backend/tests/rollback_test.go
index 61e1e993f9..814bff9fe1 100644
--- a/backend/tests/rollback_test.go
+++ b/backend/tests/rollback_test.go
@@ -86,6 +86,7 @@ func TestRollback(t *testing.T) {
a.NoError(err)
records = append(records, r)
}
+ a.NoError(rows.Err())
want := []record{
{1, "alice\nalice", 90},
{2, "bob", 110},
@@ -210,6 +211,7 @@ func TestCreateRollbackIssueMySQL(t *testing.T) {
a.NoError(err)
records1 = append(records1, r)
}
+ a.NoError(rows1.Err())
want1 := []record{{2, "unknown\nunknown"}, {3, "unknown\nunknown"}}
a.Equal(want1, records1)
@@ -292,6 +294,7 @@ func TestCreateRollbackIssueMySQL(t *testing.T) {
a.NoError(err)
records2 = append(records2, r)
}
+ a.NoError(rows2.Err())
want2 := []record{{1, "1\n1"}, {2, "2\n2"}, {3, "3\n3"}}
a.Equal(want2, records2)
}
@@ -421,6 +424,7 @@ func TestCreateRollbackIssueMySQLByPatch(t *testing.T) {
a.NoError(err)
records1 = append(records1, r)
}
+ a.NoError(rows1.Err())
want1 := []record{{2, "unknown\nunknown"}, {3, "unknown\nunknown"}}
a.Equal(want1, records1)
@@ -503,6 +507,7 @@ func TestCreateRollbackIssueMySQLByPatch(t *testing.T) {
a.NoError(err)
records2 = append(records2, r)
}
+ a.NoError(rows2.Err())
want2 := []record{{1, "1\n1"}, {2, "2\n2"}, {3, "3\n3"}}
a.Equal(want2, records2)
}
@@ -632,6 +637,7 @@ func TestRollbackCanceled(t *testing.T) {
a.NoError(err)
records1 = append(records1, r)
}
+ a.NoError(rows1.Err())
want1 := []record{{2, "unknown\nunknown"}, {3, "unknown\nunknown"}}
a.Equal(want1, records1)
diff --git a/backend/utils/utils.go b/backend/utils/utils.go
index 205bb56075..d7e2b0d9c1 100644
--- a/backend/utils/utils.go
+++ b/backend/utils/utils.go
@@ -480,7 +480,7 @@ func ExecuteMigration(ctx context.Context, store *store.Store, driver db.Driver,
if !m.CreateDatabase {
// For baseline migration, we also record the live schema to detect the schema drift.
// See https://bytebase.com/blog/what-is-database-schema-drift
- if _, err := driver.Dump(ctx, m.Database, &prevSchemaBuf, true /*schemaOnly*/); err != nil {
+ if _, err := driver.Dump(ctx, m.Database, &prevSchemaBuf, true /* schemaOnly */); err != nil {
return "", "", err
}
}
@@ -496,7 +496,7 @@ func ExecuteMigration(ctx context.Context, store *store.Store, driver db.Driver,
startedNs := time.Now().UnixNano()
defer func() {
- if err := EndMigration(ctx, store, startedNs, insertedID, updatedSchema, db.BytebaseDatabase, resErr == nil /*isDone*/); err != nil {
+ if err := EndMigration(ctx, store, startedNs, insertedID, updatedSchema, db.BytebaseDatabase, resErr == nil /* isDone */); err != nil {
log.Error("Failed to update migration history record",
zap.Error(err),
zap.String("migration_id", migrationHistoryID),
@@ -533,7 +533,7 @@ func ExecuteMigration(ctx context.Context, store *store.Store, driver db.Driver,
// Phase 4 - Dump the schema after migration
var afterSchemaBuf bytes.Buffer
- if _, err := driver.Dump(ctx, m.Database, &afterSchemaBuf, true /*schemaOnly*/); err != nil {
+ if _, err := driver.Dump(ctx, m.Database, &afterSchemaBuf, true /* schemaOnly */); err != nil {
// We will ignore the dump error if the database is dropped.
if strings.Contains(err.Error(), "not found") {
return insertedID, "", nil