Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(linter): enable revive rule unused-parameter (#1971)
Yilong Li167b70d97daa
diff --git a/.golangci.yaml b/.golangci.yamlindex f7c874f153..512e97b5c5 100644--- a/.golangci.yaml+++ b/.golangci.yaml@@ -65,8 +65,6 @@ linters-settings:- name: early-returndisabled: true# TODO(dragonly): Remove the rules below in the following PRs.- - name: unused-parameter- disabled: true- name: unused-receiverdisabled: true- name: unhandled-errordiff --git a/bin/bb/cmd/dump_test.go b/bin/bb/cmd/dump_test.goindex 326314218c..67f46d4250 100644--- a/bin/bb/cmd/dump_test.go+++ b/bin/bb/cmd/dump_test.go@@ -5,7 +5,6 @@ package cmdimport ("fmt"- "os""testing"// Embedded expected output.@@ -25,7 +24,7 @@ func TestDump(t *testing.T) {defer stop()t.Log("Importing MySQL data...")- err := mysql.Import("testdata/mysql_test_schema", os.Stdout, os.Stderr)+ err := mysql.Import("testdata/mysql_test_schema")require.NoError(t, err)tt := []testTable{diff --git a/bin/bb/cmd/migrate_test.go b/bin/bb/cmd/migrate_test.goindex 25ff786a89..aefca4b39c 100644--- a/bin/bb/cmd/migrate_test.go+++ b/bin/bb/cmd/migrate_test.go@@ -5,7 +5,6 @@ package cmdimport ("fmt"- "os""testing""github.com/bytebase/bytebase/resources/mysql"@@ -28,7 +27,7 @@ func TestMigrate(t *testing.T) {mysql, stop := mysql.SetupTestInstance(t, PortTestMigrate)defer stop()- err := mysql.Import("testdata/mysql_test_schema/1_todo.sql", os.Stdout, os.Stderr)+ err := mysql.Import("testdata/mysql_test_schema/1_todo.sql")require.NoError(t, err)tt := []testTable{diff --git a/plugin/advisor/fake/fake_advisor.go b/plugin/advisor/fake/fake_advisor.goindex bca5ea86d8..5bb345c41f 100644--- a/plugin/advisor/fake/fake_advisor.go+++ b/plugin/advisor/fake/fake_advisor.go@@ -19,7 +19,7 @@ type Advisor struct {}// Check is a fake advisor check reporting 1 advice for each severity.-func (*Advisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {+func (*Advisor) Check(_ advisor.Context, statement string) ([]advisor.Advice, error) {return []advisor.Advice{{Status: advisor.Success,diff --git a/plugin/advisor/pg/advisor_syntax.go b/plugin/advisor/pg/advisor_syntax.goindex 1c0de41125..d539ec7d38 100644--- a/plugin/advisor/pg/advisor_syntax.go+++ b/plugin/advisor/pg/advisor_syntax.go@@ -17,7 +17,7 @@ type SyntaxAdvisor struct {}// Check parses the given statement and checks for errors.-func (adv *SyntaxAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {+func (adv *SyntaxAdvisor) Check(_ advisor.Context, statement string) ([]advisor.Advice, error) {var res []advisor.Adviceif _, errAdvice := parseStatement(statement); errAdvice != nil {for _, advice := range errAdvice {diff --git a/plugin/advisor/pg/advisor_table_require_pk.go b/plugin/advisor/pg/advisor_table_require_pk.goindex a4b43f86bc..55e11aa374 100644--- a/plugin/advisor/pg/advisor_table_require_pk.go+++ b/plugin/advisor/pg/advisor_table_require_pk.go@@ -7,6 +7,7 @@ import (var (_ advisor.Advisor = (*TableRequirePKAdvisor)(nil)+ _ ast.Visitor = (*tableRequirePKChecker)(nil))func init() {@@ -48,6 +49,6 @@ type tableRequirePKChecker struct {}// Visit implements the ast.Visitor interface.-func (checker *tableRequirePKChecker) Visit(node ast.Node) ast.Visitor {+func (checker *tableRequirePKChecker) Visit(ast.Node) ast.Visitor {return checker}diff --git a/plugin/advisor/sql_review.go b/plugin/advisor/sql_review.goindex a786f619ba..2bc3af7374 100644--- a/plugin/advisor/sql_review.go+++ b/plugin/advisor/sql_review.go@@ -1,7 +1,6 @@package advisorimport (- "context""encoding/json""fmt""log"@@ -254,8 +253,8 @@ type SQLReviewCheckContext struct {Catalog catalog.Catalog}-// SchemaReviewCheck checks the statments with schema review policy.-func SchemaReviewCheck(ctx context.Context, statements string, policy *SQLReviewPolicy, context SQLReviewCheckContext) ([]Advice, error) {+// SchemaReviewCheck checks the statements with schema review policy.+func SchemaReviewCheck(statements string, policy *SQLReviewPolicy, context SQLReviewCheckContext) ([]Advice, error) {var result []Advicefor _, rule := range policy.RuleList {if rule.Level == SchemaRuleLevelDisabled {diff --git a/plugin/advisor/utils_for_tests.go b/plugin/advisor/utils_for_tests.goindex aa84200095..fa8a1070b9 100644--- a/plugin/advisor/utils_for_tests.go+++ b/plugin/advisor/utils_for_tests.go@@ -27,10 +27,12 @@ const (var (// MockIndexColumnList is the mock index column list for test.MockIndexColumnList = []string{"id", "name"}++ _ catalog.Catalog = (*MockCatalogService)(nil))// FindIndex implements the catalog interface.-func (*MockCatalogService) FindIndex(ctx context.Context, find *catalog.IndexFind) (*catalog.Index, error) {+func (*MockCatalogService) FindIndex(_ context.Context, find *catalog.IndexFind) (*catalog.Index, error) {switch find.IndexName {case MockOldIndexName:return &catalog.Index{@@ -54,7 +56,7 @@ func (*MockCatalogService) FindIndex(ctx context.Context, find *catalog.IndexFin}// FindTable implements the catalog interface.-func (*MockCatalogService) FindTable(ctx context.Context, find *catalog.TableFind) ([]*catalog.Table, error) {+func (*MockCatalogService) FindTable(_ context.Context, find *catalog.TableFind) ([]*catalog.Table, error) {return []*catalog.Table{{Name: "table",diff --git a/plugin/db/clickhouse/clickhouse.go b/plugin/db/clickhouse/clickhouse.goindex f84abcbbd2..6132ca082a 100644--- a/plugin/db/clickhouse/clickhouse.go+++ b/plugin/db/clickhouse/clickhouse.go@@ -95,7 +95,7 @@ func (driver *Driver) Ping(ctx context.Context) error {}// GetDBConnection gets a database connection.-func (driver *Driver) GetDBConnection(ctx context.Context, database string) (*sql.DB, error) {+func (driver *Driver) GetDBConnection(context.Context, string) (*sql.DB, error) {return driver.db, nil}diff --git a/plugin/db/clickhouse/dump.go b/plugin/db/clickhouse/dump.goindex 77f98449eb..4659fd73cc 100644--- a/plugin/db/clickhouse/dump.go+++ b/plugin/db/clickhouse/dump.go@@ -32,14 +32,14 @@ const ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, database string, out io.Writer, schemaOnly bool) (string, error) {+func (driver *Driver) Dump(ctx context.Context, database string, out io.Writer, _ bool) (string, error) {txn, err := driver.db.BeginTx(ctx, &sql.TxOptions{})if err != nil {return "", err}defer txn.Rollback()- if err := dumpTxn(ctx, txn, database, out, schemaOnly); err != nil {+ if err := dumpTxn(ctx, txn, database, out); err != nil {return "", err}@@ -73,7 +73,7 @@ func getDatabases(ctx context.Context, txn *sql.Tx) ([]string, error) {}// dumpTxn will dump the input database. schemaOnly isn't supported yet and true by default.-func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer, schemaOnly bool) error {+func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer) error {// Find all dumpable databasesdbNames, err := getDatabases(ctx, txn)if err != nil {@@ -215,6 +215,6 @@ func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err error}// RestoreTx restores the database in the given transaction.-func (driver *Driver) RestoreTx(ctx context.Context, tx *sql.Tx, sc *bufio.Scanner) error {+func (driver *Driver) RestoreTx(context.Context, *sql.Tx, *bufio.Scanner) error {return fmt.Errorf("Unimplemented")}diff --git a/plugin/db/clickhouse/migrate.go b/plugin/db/clickhouse/migrate.goindex c7f1a27c1b..453897356a 100644--- a/plugin/db/clickhouse/migrate.go+++ b/plugin/db/clickhouse/migrate.go@@ -269,7 +269,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Migquery += fmt.Sprintf(" LIMIT %d", *v)}// TODO(zp): modified param database of `util.FindMigrationHistoryList` when we support *clickhouse* database level.- history, err := util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, baseQuery)+ history, err := util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase)// TODO(d): remove this block once all existing customers all migrated to semantic versioning.if err != nil {if !strings.Contains(err.Error(), "invalid stored version") {@@ -278,7 +278,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Migif err := driver.updateMigrationHistoryStorageVersion(ctx); err != nil {return nil, err}- return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, baseQuery)+ return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase)}return history, err}diff --git a/plugin/db/mysql/dump.go b/plugin/db/mysql/dump.goindex 45cd47f186..8ad769a769 100644--- a/plugin/db/mysql/dump.go+++ b/plugin/db/mysql/dump.go@@ -687,7 +687,7 @@ func (driver *Driver) RestoreTx(ctx context.Context, tx *sql.Tx, sc *bufio.Scannfunc (driver *Driver) restoreTx(ctx context.Context, tx *sql.Tx, sc *bufio.Scanner) error {fnExecuteStmt := func(stmt string) error {- if _, err := tx.Exec(stmt); err != nil {+ if _, err := tx.ExecContext(ctx, stmt); err != nil {return err}return nildiff --git a/plugin/db/mysql/migrate.go b/plugin/db/mysql/migrate.goindex e8919a5a2d..f9e8d71fb7 100644--- a/plugin/db/mysql/migrate.go+++ b/plugin/db/mysql/migrate.go@@ -251,7 +251,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Migquery += fmt.Sprintf(" LIMIT %d", *v)}// TODO(zp): modified param database of `util.FindMigrationHistoryList` when we support *mysql* database level.- history, err := util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, baseQuery)+ history, err := util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase)// TODO(d): remove this block once all existing customers all migrated to semantic versioning.if err != nil {if !strings.Contains(err.Error(), "invalid stored version") {@@ -260,7 +260,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Migif err := driver.updateMigrationHistoryStorageVersion(ctx); err != nil {return nil, err}- return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, baseQuery)+ return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase)}return history, err}diff --git a/plugin/db/mysql/mysql.go b/plugin/db/mysql/mysql.goindex c3da0d8ead..50c91d5d11 100644--- a/plugin/db/mysql/mysql.go+++ b/plugin/db/mysql/mysql.go@@ -42,7 +42,7 @@ func newDriver(db.DriverConfig) db.Driver {}// Open opens a MySQL driver.-func (driver *Driver) Open(ctx context.Context, dbType db.Type, connCfg db.ConnectionConfig, connCtx db.ConnectionContext) (db.Driver, error) {+func (driver *Driver) Open(_ context.Context, dbType db.Type, connCfg db.ConnectionConfig, connCtx db.ConnectionContext) (db.Driver, error) {protocol := "tcp"if strings.HasPrefix(connCfg.Host, "/") {protocol = "unix"@@ -96,7 +96,7 @@ func (driver *Driver) Open(ctx context.Context, dbType db.Type, connCfg db.Conne}// Close closes the driver.-func (driver *Driver) Close(ctx context.Context) error {+func (driver *Driver) Close(context.Context) error {return driver.db.Close()}@@ -106,7 +106,7 @@ func (driver *Driver) Ping(ctx context.Context) error {}// GetDBConnection gets a database connection.-func (driver *Driver) GetDBConnection(ctx context.Context, database string) (*sql.DB, error) {+func (driver *Driver) GetDBConnection(context.Context, string) (*sql.DB, error) {return driver.db, nil}diff --git a/plugin/db/pg/dump.go b/plugin/db/pg/dump.goindex dc6b7bba0b..4e3e809c5c 100644--- a/plugin/db/pg/dump.go+++ b/plugin/db/pg/dump.go@@ -20,7 +20,7 @@ func (driver *Driver) Dump(ctx context.Context, database string, out io.Writer,// pg_dump -d dbName --schema-only+// Find all dumpable databases- databases, err := driver.getDatabases()+ databases, err := driver.getDatabases(ctx)if err != nil {return "", fmt.Errorf("failed to get databases: %s", err)}@@ -48,8 +48,7 @@ func (driver *Driver) Dump(ctx context.Context, database string, out io.Writer,}for _, dbName := range dumpableDbNames {- includeUseDatabase := len(dumpableDbNames) > 1- if err := driver.dumpOneDatabaseWithPgDump(ctx, dbName, out, schemaOnly, includeUseDatabase); err != nil {+ if err := driver.dumpOneDatabaseWithPgDump(ctx, dbName, out, schemaOnly); err != nil {return "", err}}@@ -57,7 +56,7 @@ func (driver *Driver) Dump(ctx context.Context, database string, out io.Writer,return "", nil}-func (driver *Driver) dumpOneDatabaseWithPgDump(ctx context.Context, database string, out io.Writer, schemaOnly bool, includeUseDatabase bool) error {+func (driver *Driver) dumpOneDatabaseWithPgDump(ctx context.Context, database string, out io.Writer, schemaOnly bool) error {var args []stringargs = append(args, fmt.Sprintf("--username=%s", driver.config.Username))if driver.config.Password == "" {@@ -72,7 +71,7 @@ func (driver *Driver) dumpOneDatabaseWithPgDump(ctx context.Context, database stargs = append(args, "--use-set-session-authorization")args = append(args, database)pgDumpPath := filepath.Join(driver.pgInstanceDir, "bin", "pg_dump")- cmd := exec.Command(pgDumpPath, args...)+ cmd := exec.CommandContext(ctx, pgDumpPath, args...)if driver.config.Password != "" {// Unlike MySQL, PostgreSQL does not support specifying commands in commands, we can do this by means of environment variables.cmd.Env = append(cmd.Env, fmt.Sprintf("PGPASSWORD=%s", driver.config.Password))@@ -157,6 +156,6 @@ func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err error}// RestoreTx restores the database in the given transaction.-func (driver *Driver) RestoreTx(ctx context.Context, tx *sql.Tx, sc *bufio.Scanner) error {+func (driver *Driver) RestoreTx(context.Context, *sql.Tx, *bufio.Scanner) error {return fmt.Errorf("Unimplemented")}diff --git a/plugin/db/pg/migrate.go b/plugin/db/pg/migrate.goindex 4a2a848400..518b2b3256 100644--- a/plugin/db/pg/migrate.go+++ b/plugin/db/pg/migrate.go@@ -301,7 +301,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Migif driver.strictUseDb() {database = driver.strictDatabase}- history, err := util.FindMigrationHistoryList(ctx, query, params, driver, database, baseQuery)+ history, err := util.FindMigrationHistoryList(ctx, query, params, driver, database)// TODO(d): remove this block once all existing customers all migrated to semantic versioning.// Skip this backfill for bytebase's database "bb" with user "bb". We will use the one in pg_engine.go instead.isBytebaseDatabase := strings.Contains(driver.baseDSN, "user=bb") && strings.Contains(driver.baseDSN, "host=/tmp")@@ -312,7 +312,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Migif err := driver.updateMigrationHistoryStorageVersion(ctx); err != nil {return nil, err}- return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, baseQuery)+ return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase)}return history, err}@@ -369,7 +369,7 @@ func (driver *Driver) updateMigrationHistoryStorageVersion(ctx context.Context)}func (driver *Driver) hasBytebaseDatabase(ctx context.Context) (bool, error) {- databases, err := driver.getDatabases()+ databases, err := driver.getDatabases(ctx)if err != nil {return false, err}diff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.goindex 1397a2f327..9286491346 100644--- a/plugin/db/pg/pg.go+++ b/plugin/db/pg/pg.go@@ -54,7 +54,7 @@ func newDriver(config db.DriverConfig) db.Driver {}// Open opens a Postgres driver.-func (driver *Driver) Open(ctx context.Context, dbType db.Type, config db.ConnectionConfig, connCtx db.ConnectionContext) (db.Driver, error) {+func (driver *Driver) Open(_ context.Context, _ db.Type, config db.ConnectionConfig, connCtx db.ConnectionContext) (db.Driver, error) {if (config.TLSConfig.SslCert == "" && config.TLSConfig.SslKey != "") ||(config.TLSConfig.SslCert != "" && config.TLSConfig.SslKey == "") {return nil, fmt.Errorf("ssl-cert and ssl-key must be both set or unset")@@ -159,7 +159,7 @@ func guessDSN(username, password, hostname, port, database, sslCA, sslCert, sslK}// Close closes the driver.-func (driver *Driver) Close(ctx context.Context) error {+func (driver *Driver) Close(context.Context) error {return driver.db.Close()}@@ -169,7 +169,7 @@ func (driver *Driver) Ping(ctx context.Context) error {}// GetDBConnection gets a database connection.-func (driver *Driver) GetDBConnection(ctx context.Context, database string) (*sql.DB, error) {+func (driver *Driver) GetDBConnection(_ context.Context, database string) (*sql.DB, error) {if err := driver.switchDatabase(database); err != nil {return nil, err}@@ -177,9 +177,9 @@ func (driver *Driver) GetDBConnection(ctx context.Context, database string) (*sq}// getDatabases gets all databases of an instance.-func (driver *Driver) getDatabases() ([]*pgDatabaseSchema, error) {+func (driver *Driver) getDatabases(ctx context.Context) ([]*pgDatabaseSchema, error) {var dbs []*pgDatabaseSchema- rows, err := driver.db.Query("SELECT datname, pg_encoding_to_char(encoding), datcollate FROM pg_database;")+ rows, err := driver.db.QueryContext(ctx, "SELECT datname, pg_encoding_to_char(encoding), datcollate FROM pg_database;")if err != nil {return nil, err}@@ -224,7 +224,7 @@ func (driver *Driver) Execute(ctx context.Context, statement string) error {// We don't use transaction for creating / altering databases in Postgres.// https://github.com/bytebase/bytebase/issues/202if strings.HasPrefix(stmt, "CREATE DATABASE ") {- databases, err := driver.getDatabases()+ databases, err := driver.getDatabases(ctx)if err != nil {return err}diff --git a/plugin/db/pg/sync.go b/plugin/db/pg/sync.goindex 1ec35b4368..b8055d2ff1 100644--- a/plugin/db/pg/sync.go+++ b/plugin/db/pg/sync.go@@ -107,7 +107,7 @@ func (driver *Driver) SyncInstance(ctx context.Context) (*db.InstanceMeta, errorexcludedDatabaseList[k] = true}// Query db info- databases, err := driver.getDatabases()+ databases, err := driver.getDatabases(ctx)if err != nil {return nil, fmt.Errorf("failed to get databases: %s", err)}@@ -138,7 +138,7 @@ func (driver *Driver) SyncInstance(ctx context.Context) (*db.InstanceMeta, error// SyncDBSchema syncs a single database schema.func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*db.Schema, error) {// Query db info- databases, err := driver.getDatabases()+ databases, err := driver.getDatabases(ctx)if err != nil {return nil, fmt.Errorf("failed to get databases: %s", err)}diff --git a/plugin/db/snowflake/dump.go b/plugin/db/snowflake/dump.goindex ba10d2a439..132297d1e3 100644--- a/plugin/db/snowflake/dump.go+++ b/plugin/db/snowflake/dump.go@@ -20,14 +20,14 @@ const ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, database string, out io.Writer, schemaOnly bool) (string, error) {+func (driver *Driver) Dump(ctx context.Context, database string, out io.Writer, _ bool) (string, error) {txn, err := driver.db.BeginTx(ctx, &sql.TxOptions{})if err != nil {return "", err}defer txn.Rollback()- if err := dumpTxn(ctx, txn, database, out, schemaOnly); err != nil {+ if err := dumpTxn(ctx, txn, database, out); err != nil {return "", err}@@ -39,7 +39,7 @@ func (driver *Driver) Dump(ctx context.Context, database string, out io.Writer,}// dumpTxn will dump the input database. schemaOnly isn't supported yet and true by default.-func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer, schemaOnly bool) error {+func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer) error {// Find all dumpable databasesvar dumpableDbNames []stringif database != "" {@@ -61,7 +61,7 @@ func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer, s// includeCreateDatabaseStmt should be false if dumping a single database.dumpSingleDatabase := len(dumpableDbNames) == 1dbName = strings.ToUpper(dbName)- if err := dumpOneDatabase(ctx, txn, dbName, out, schemaOnly, dumpSingleDatabase); err != nil {+ if err := dumpOneDatabase(ctx, txn, dbName, out, dumpSingleDatabase); err != nil {return err}}@@ -71,7 +71,7 @@ func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer, s// dumpOneDatabase will dump the database DDL schema for a database.// Note: this operation is not supported on shared databases, e.g. SNOWFLAKE_SAMPLE_DATA.-func dumpOneDatabase(ctx context.Context, txn *sql.Tx, database string, out io.Writer, schemaOnly bool, dumpSingleDatabase bool) error {+func dumpOneDatabase(ctx context.Context, txn *sql.Tx, database string, out io.Writer, dumpSingleDatabase bool) error {if !dumpSingleDatabase {// Database header.header := fmt.Sprintf(databaseHeaderFmt, database)@@ -164,6 +164,6 @@ func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err error}// RestoreTx restores the database in the given transaction.-func (driver *Driver) RestoreTx(ctx context.Context, tx *sql.Tx, sc *bufio.Scanner) error {+func (driver *Driver) RestoreTx(context.Context, *sql.Tx, *bufio.Scanner) error {return fmt.Errorf("Unimplemented")}diff --git a/plugin/db/snowflake/migrate.go b/plugin/db/snowflake/migrate.goindex 66c6030f08..5d0e2eed12 100644--- a/plugin/db/snowflake/migrate.go+++ b/plugin/db/snowflake/migrate.go@@ -279,7 +279,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Migquery += fmt.Sprintf(" LIMIT %d", *v)}// TODO(zp): modified param `bytebaseDatabase` of `util.FindMigrationHistoryList` when we support *snowflake* database level.- history, err := util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase, baseQuery)+ history, err := util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase)// TODO(d): remove this block once all existing customers all migrated to semantic versioning.if err != nil {if !strings.Contains(err.Error(), "invalid stored version") {@@ -288,7 +288,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Migif err := driver.updateMigrationHistoryStorageVersion(ctx); err != nil {return nil, err}- return util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase, baseQuery)+ return util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase)}return history, err}diff --git a/plugin/db/snowflake/snowflake.go b/plugin/db/snowflake/snowflake.goindex 9d7b2b6248..4befd18b1b 100644--- a/plugin/db/snowflake/snowflake.go+++ b/plugin/db/snowflake/snowflake.go@@ -36,12 +36,12 @@ type Driver struct {db *sql.DB}-func newDriver(config db.DriverConfig) db.Driver {+func newDriver(db.DriverConfig) db.Driver {return &Driver{}}// Open opens a Snowflake driver.-func (driver *Driver) Open(ctx context.Context, dbType db.Type, config db.ConnectionConfig, connCtx db.ConnectionContext) (db.Driver, error) {+func (driver *Driver) Open(_ context.Context, dbType db.Type, config db.ConnectionConfig, connCtx db.ConnectionContext) (db.Driver, error) {prefixParts, loggedPrefixParts := []string{config.Username}, []string{config.Username}if config.Password != "" {prefixParts = append(prefixParts, config.Password)@@ -92,7 +92,7 @@ func (driver *Driver) Open(ctx context.Context, dbType db.Type, config db.Connec}// Close closes the driver.-func (driver *Driver) Close(ctx context.Context) error {+func (driver *Driver) Close(context.Context) error {return driver.db.Close()}@@ -102,7 +102,7 @@ func (driver *Driver) Ping(ctx context.Context) error {}// GetDBConnection gets a database connection.-func (driver *Driver) GetDBConnection(ctx context.Context, database string) (*sql.DB, error) {+func (driver *Driver) GetDBConnection(context.Context, string) (*sql.DB, error) {return driver.db, nil}diff --git a/plugin/db/sqlite/dump.go b/plugin/db/sqlite/dump.goindex b50b5b6db4..dbb3bc82e3 100644--- a/plugin/db/sqlite/dump.go+++ b/plugin/db/sqlite/dump.go@@ -176,6 +176,6 @@ func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err error}// RestoreTx restores the database in the given transaction.-func (*Driver) RestoreTx(ctx context.Context, tx *sql.Tx, sc *bufio.Scanner) error {+func (*Driver) RestoreTx(context.Context, *sql.Tx, *bufio.Scanner) error {return fmt.Errorf("Unimplemented")}diff --git a/plugin/db/sqlite/migrate.go b/plugin/db/sqlite/migrate.goindex 7343f5ceee..223fffe5a5 100644--- a/plugin/db/sqlite/migrate.go+++ b/plugin/db/sqlite/migrate.go@@ -268,5 +268,5 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Migif v := find.Limit; v != nil {query += fmt.Sprintf(" LIMIT %d", *v)}- return util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase, baseQuery)+ return util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase)}diff --git a/plugin/db/sqlite/sqlite.go b/plugin/db/sqlite/sqlite.goindex 38207d877e..3358980096 100644--- a/plugin/db/sqlite/sqlite.go+++ b/plugin/db/sqlite/sqlite.go@@ -33,12 +33,12 @@ type Driver struct {connectionCtx db.ConnectionContext}-func newDriver(config db.DriverConfig) db.Driver {+func newDriver(db.DriverConfig) db.Driver {return &Driver{}}// Open opens a SQLite driver.-func (driver *Driver) Open(ctx context.Context, dbType db.Type, config db.ConnectionConfig, connCtx db.ConnectionContext) (db.Driver, error) {+func (driver *Driver) Open(ctx context.Context, _ db.Type, config db.ConnectionConfig, connCtx db.ConnectionContext) (db.Driver, error) {// Host is the directory (instance) containing all SQLite databases.driver.dir = config.Host@@ -51,7 +51,7 @@ func (driver *Driver) Open(ctx context.Context, dbType db.Type, config db.Connec}// Close closes the driver.-func (driver *Driver) Close(ctx context.Context) error {+func (driver *Driver) Close(context.Context) error {if driver.db != nil {return driver.db.Close()}@@ -65,7 +65,7 @@ func (driver *Driver) Ping(ctx context.Context) error {// GetDBConnection gets a database connection.// If database is empty, we will get a connect to in-memory database.-func (driver *Driver) GetDBConnection(ctx context.Context, database string) (*sql.DB, error) {+func (driver *Driver) GetDBConnection(_ context.Context, database string) (*sql.DB, error) {if driver.db != nil {if err := driver.db.Close(); err != nil {return nil, errdiff --git a/plugin/db/util/driverutil.go b/plugin/db/util/driverutil.goindex 0b71fa76d6..3056847326 100644--- a/plugin/db/util/driverutil.go+++ b/plugin/db/util/driverutil.go@@ -401,7 +401,7 @@ func Query(ctx context.Context, sqldb *sql.DB, statement string, limit int) ([]i}// FindMigrationHistoryList will find the list of migration history.-func FindMigrationHistoryList(ctx context.Context, findMigrationHistoryListQuery string, queryParams []interface{}, driver db.Driver, database string, baseQuery string) ([]*db.MigrationHistory, error) {+func FindMigrationHistoryList(ctx context.Context, findMigrationHistoryListQuery string, queryParams []interface{}, driver db.Driver, database string) ([]*db.MigrationHistory, error) {// To support `pg` option, the util layer will not know which database where `migration_history` table is,// so we need to connect to the database provided by params.sqldb, err := driver.GetDBConnection(ctx, database)diff --git a/plugin/parser/engine/pg/parser.go b/plugin/parser/engine/pg/parser.goindex b3514c0dc8..4eb6003bf9 100644--- a/plugin/parser/engine/pg/parser.go+++ b/plugin/parser/engine/pg/parser.go@@ -21,7 +21,7 @@ type PostgreSQLParser struct {}// Parse implements the parser.Parser interface.-func (p *PostgreSQLParser) Parse(ctx parser.Context, statement string) ([]ast.Node, error) {+func (p *PostgreSQLParser) Parse(_ parser.Context, statement string) ([]ast.Node, error) {res, err := pgquery.Parse(statement)if err != nil {return nil, errdiff --git a/resources/mysql/mysql.go b/resources/mysql/mysql.goindex 477b37196a..d35f8fce7a 100644--- a/resources/mysql/mysql.go+++ b/resources/mysql/mysql.go@@ -172,7 +172,7 @@ func SetupTestInstance(t *testing.T, port int) (*Instance, func()) {// Import executes sql script in the given path on the instance.// If the path is a directory, it imports all sql scripts in the directory recursively.-func (i *Instance) Import(path string, stdout, stderr io.Writer) error {+func (i *Instance) Import(path string) error {var buf bytes.Bufferif err := cat(path, &buf); err != nil {return errdiff --git a/server/database.go b/server/database.goindex 6e30200727..ef80f0a241 100644--- a/server/database.go+++ b/server/database.go@@ -685,7 +685,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {}if dataSourceCreate.SyncSchema {- // Refetches the instance to get the updated data source.+ // Refetch the instance to get the updated data source.updatedInstance, err := s.store.GetInstanceByID(ctx, database.InstanceID)if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch updated instance with ID %d", database.InstanceID)).SetInternal(err)@@ -757,7 +757,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {}if dataSourcePatch.SyncSchema {- // Refetches the instance to get the updated data source.+ // Refetch the instance to get the updated data source.updatedInstance, err := s.store.GetInstanceByID(ctx, database.InstanceID)if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch updated instance with ID %d", database.InstanceID)).SetInternal(err)@@ -827,7 +827,7 @@ func (s *Server) setDatabaseLabels(ctx context.Context, labelsJSON string, datab// Try to get database driver using the instance's admin data source.// Upon successful return, caller MUST call driver.Close, otherwise, it will leak the database connection.func getAdminDatabaseDriver(ctx context.Context, instance *api.Instance, databaseName, pgInstanceDir string) (db.Driver, error) {- connCfg, err := getConnectionConfig(ctx, instance, databaseName)+ connCfg, err := getConnectionConfig(instance, databaseName)if err != nil {return nil, err}@@ -850,7 +850,7 @@ func getAdminDatabaseDriver(ctx context.Context, instance *api.Instance, databas}// getConnectionConfig returns the connection config of the `databaseName` on `instance`.-func getConnectionConfig(ctx context.Context, instance *api.Instance, databaseName string) (db.ConnectionConfig, error) {+func getConnectionConfig(instance *api.Instance, databaseName string) (db.ConnectionConfig, error) {adminDataSource := api.DataSourceFromInstanceWithType(instance, api.Admin)if adminDataSource == nil {return db.ConnectionConfig{}, common.Errorf(common.Internal, fmt.Errorf("admin data source not found for instance %d", instance.ID))diff --git a/server/openapi.go b/server/openapi.goindex 5b58972474..494e7871e3 100644--- a/server/openapi.go+++ b/server/openapi.go@@ -24,13 +24,13 @@ type catalogService struct{}// FindIndex is the API message for find index in catalog.// We will not connect to the user's database in the early version of sql check api-func (c *catalogService) FindIndex(ctx context.Context, find *catalog.IndexFind) (*catalog.Index, error) {+func (c *catalogService) FindIndex(context.Context, *catalog.IndexFind) (*catalog.Index, error) {return nil, nil}// FindTable is the API message for find table in catalog.// We will not connect to the user's database in the early version of sql check api-func (c *catalogService) FindTable(ctx context.Context, find *catalog.TableFind) ([]*catalog.Table, error) {+func (c *catalogService) FindTable(context.Context, *catalog.TableFind) ([]*catalog.Table, error) {return nil, nil}diff --git a/server/server.go b/server/server.goindex 5119f4e281..4bd120c6aa 100644--- a/server/server.go+++ b/server/server.go@@ -153,7 +153,7 @@ func NewServer(ctx context.Context, prof Profile) (*Server, error) {// New MetadataDB instance.if prof.useEmbedDB() {- s.metaDB = store.NewMetadataDBWithEmbedPg(pgInstance, prof.PgUser, prof.DataDir, prof.DemoDataDir, prof.Mode)+ s.metaDB = store.NewMetadataDBWithEmbedPg(pgInstance, prof.PgUser, prof.DemoDataDir, prof.Mode)} else {s.metaDB = store.NewMetadataDBWithExternalPg(pgInstance, prof.PgURL, prof.DemoDataDir, prof.Mode)}diff --git a/server/sql.go b/server/sql.goindex f35df2317f..3db13f36e0 100644--- a/server/sql.go+++ b/server/sql.go@@ -672,7 +672,7 @@ func (s *Server) sqlCheck(return advisor.Error, nil, err}- res, err := advisor.SchemaReviewCheck(ctx, statement, policy, advisor.SQLReviewCheckContext{+ res, err := advisor.SchemaReviewCheck(statement, policy, advisor.SQLReviewCheckContext{Charset: dbCharacterSet,Collation: dbCollation,DbType: dbType,diff --git a/server/task_check_executor_statement_advisor_composite.go b/server/task_check_executor_statement_advisor_composite.goindex 608d72f58d..426df36108 100644--- a/server/task_check_executor_statement_advisor_composite.go+++ b/server/task_check_executor_statement_advisor_composite.go@@ -68,7 +68,7 @@ func (exec *TaskCheckStatementAdvisorCompositeExecutor) Run(ctx context.Context,return nil, err}- adviceList, err := advisor.SchemaReviewCheck(ctx, payload.Statement, policy, advisor.SQLReviewCheckContext{+ adviceList, err := advisor.SchemaReviewCheck(payload.Statement, policy, advisor.SQLReviewCheckContext{Charset: payload.Charset,Collation: payload.Collation,DbType: dbType,diff --git a/server/task_check_executor_statement_advisor_simple.go b/server/task_check_executor_statement_advisor_simple.goindex 5947e37338..7aa7e920c2 100644--- a/server/task_check_executor_statement_advisor_simple.go+++ b/server/task_check_executor_statement_advisor_simple.go@@ -21,7 +21,7 @@ type TaskCheckStatementAdvisorSimpleExecutor struct {}// Run will run the task check statement advisor executor once.-func (exec *TaskCheckStatementAdvisorSimpleExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {+func (exec *TaskCheckStatementAdvisorSimpleExecutor) Run(_ context.Context, _ *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {payload := &api.TaskCheckDatabaseStatementAdvisePayload{}if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid check statement advise payload: %w", err))diff --git a/server/task_check_executor_timing.go b/server/task_check_executor_timing.goindex bbd3a1c4b4..cac75dd927 100644--- a/server/task_check_executor_timing.go+++ b/server/task_check_executor_timing.go@@ -22,7 +22,7 @@ type TaskCheckTimingExecutor struct {const dataFormat = "2006-01-02 15:04:05"// Run will run the task check timing executor once.-func (exec *TaskCheckTimingExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {+func (exec *TaskCheckTimingExecutor) Run(_ context.Context, _ *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {payload := &api.TaskCheckEarliestAllowedTimePayload{}if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {return []api.TaskCheckResult{}, common.Errorf(common.Invalid, fmt.Errorf("invalid check timing payload: %w", err))diff --git a/server/task_executor_default.go b/server/task_executor_default.goindex daabebaa55..0df1ccc5c7 100644--- a/server/task_executor_default.go+++ b/server/task_executor_default.go@@ -21,7 +21,7 @@ type DefaultTaskExecutor struct {}// RunOnce will run the default task executor once.-func (exec *DefaultTaskExecutor) RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, result *api.TaskRunResultPayload, err error) {+func (exec *DefaultTaskExecutor) RunOnce(_ context.Context, _ *Server, task *api.Task) (terminated bool, result *api.TaskRunResultPayload, err error) {log.Info("Run default task type", zap.String("task", task.Name))defer atomic.StoreInt32(&exec.completed, 1)diff --git a/server/task_executor_schema_update_ghost_sync.go b/server/task_executor_schema_update_ghost_sync.goindex e3d75bca53..eb44acb4ab 100644--- a/server/task_executor_schema_update_ghost_sync.go+++ b/server/task_executor_schema_update_ghost_sync.go@@ -234,7 +234,7 @@ func executeSync(ctx context.Context, task *api.Task, mi *db.MigrationInfo, stat)}}()- if err = executeGhost(task, startedNs, statement, syncDone); err != nil {+ if err = executeGhost(task, statement, syncDone); err != nil {return -1, "", err}@@ -246,7 +246,7 @@ func executeSync(ctx context.Context, task *api.Task, mi *db.MigrationInfo, statreturn insertedID, afterSchemaBuf.String(), nil}-func executeGhost(task *api.Task, startedNs int64, statement string, syncDone chan<- struct{}) error {+func executeGhost(task *api.Task, statement string, syncDone chan<- struct{}) error {instance := task.InstancedatabaseName := task.Database.Namediff --git a/server/webhook.go b/server/webhook.goindex 66ceaa0db5..a44496d1cf 100644--- a/server/webhook.go+++ b/server/webhook.go@@ -197,9 +197,9 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {if !s.feature(api.FeatureMultiTenancy) {return echo.NewHTTPError(http.StatusForbidden, api.FeatureMultiTenancy.AccessErrorMessage())}- createContext, err = s.createTenantSchemaUpdateIssue(ctx, repo, mi, vcsPushEvent, commit, addedEscaped, content)+ createContext, err = s.createTenantSchemaUpdateIssue(mi, vcsPushEvent, content)} else {- createContext, err = s.createSchemaUpdateIssue(ctx, repo, mi, vcsPushEvent, commit, addedEscaped, content)+ createContext, err = s.createSchemaUpdateIssue(ctx, repo, mi, vcsPushEvent, addedEscaped, content)}if err != nil {createIgnoredFileActivity(err)@@ -328,7 +328,7 @@ func dedupMigrationFilesFromCommitList(commitList []gitlab.WebhookCommit) []distreturn distinctFileList}-func (s *Server) createSchemaUpdateIssue(ctx context.Context, repository *api.Repository, mi *db.MigrationInfo, vcsPushEvent vcs.PushEvent, commit gitlab.WebhookCommit, added string, statement string) (string, error) {+func (s *Server) createSchemaUpdateIssue(ctx context.Context, repository *api.Repository, mi *db.MigrationInfo, vcsPushEvent vcs.PushEvent, added string, statement string) (string, error) {// Find matching database listdatabaseFind := &api.DatabaseFind{ProjectID: &repository.ProjectID,@@ -403,7 +403,7 @@ func (s *Server) createSchemaUpdateIssue(ctx context.Context, repository *api.Rereturn string(createContext), nil}-func (s *Server) createTenantSchemaUpdateIssue(ctx context.Context, repository *api.Repository, mi *db.MigrationInfo, vcsPushEvent vcs.PushEvent, commit gitlab.WebhookCommit, added string, statement string) (string, error) {+func (s *Server) createTenantSchemaUpdateIssue(mi *db.MigrationInfo, vcsPushEvent vcs.PushEvent, statement string) (string, error) {// We don't take environment for tenant mode project because the databases needing schema update are determined by database name and deployment configuration.if mi.Environment != "" {return "", fmt.Errorf("environment isn't accepted in schema update for tenant mode project")diff --git a/store/metadb.go b/store/metadb.goindex 5696541ce4..7755e83390 100644--- a/store/metadb.go+++ b/store/metadb.go@@ -29,7 +29,7 @@ type MetadataDB struct {}// NewMetadataDBWithEmbedPg install postgres in `datadir` returns an instance of MetadataDB-func NewMetadataDBWithEmbedPg(pgInstance *postgres.Instance, pgUser, dataDir, demoDataDir string, mode common.ReleaseMode) *MetadataDB {+func NewMetadataDBWithEmbedPg(pgInstance *postgres.Instance, pgUser, demoDataDir string, mode common.ReleaseMode) *MetadataDB {return &MetadataDB{mode: mode,demoDataDir: demoDataDir,