Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: cleanup driver dump function stub (#13750)
h3n4l62e8c1a81dd1
diff --git a/backend/plugin/advisor/utils_for_tests.go b/backend/plugin/advisor/utils_for_tests.goindex d36832a5c0..85bc547e80 100644--- a/backend/plugin/advisor/utils_for_tests.go+++ b/backend/plugin/advisor/utils_for_tests.go@@ -322,8 +322,8 @@ func (*MockDriver) SyncDBSchema(_ context.Context) (*storepb.DatabaseSchemaMetad}// Dump implements the Driver interface.-func (*MockDriver) Dump(_ context.Context, _ io.Writer) (string, error) {- return "", nil+func (*MockDriver) Dump(_ context.Context, _ io.Writer) error {+ return nil}// SyncSlowQuery implements the Driver interface.diff --git a/backend/plugin/db/bigquery/dump.go b/backend/plugin/db/bigquery/dump.goindex ef40b3c039..f1cf1cfd63 100644--- a/backend/plugin/db/bigquery/dump.go+++ b/backend/plugin/db/bigquery/dump.go@@ -6,6 +6,6 @@ import ()// Dump dumps the database.-func (*Driver) Dump(_ context.Context, _ io.Writer) (string, error) {- return "", nil+func (*Driver) Dump(_ context.Context, _ io.Writer) error {+ return nil}diff --git a/backend/plugin/db/clickhouse/dump.go b/backend/plugin/db/clickhouse/dump.goindex 66d4307b1d..60d0b500a3 100644--- a/backend/plugin/db/clickhouse/dump.go+++ b/backend/plugin/db/clickhouse/dump.go@@ -32,22 +32,18 @@ const ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {txn, err := driver.db.BeginTx(ctx, &sql.TxOptions{})if err != nil {- return "", err+ return err}defer txn.Rollback()if err := dumpTxn(ctx, txn, driver.databaseName, out); err != nil {- return "", err- }-- if err := txn.Commit(); err != nil {- return "", err+ return err}- return "", nil+ return txn.Commit()}// getDatabases gets all databases of an instance.diff --git a/backend/plugin/db/cockroachdb/dump.go b/backend/plugin/db/cockroachdb/dump.goindex fbd0ad4675..caded5d21b 100644--- a/backend/plugin/db/cockroachdb/dump.go+++ b/backend/plugin/db/cockroachdb/dump.go@@ -9,10 +9,10 @@ import ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, w io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, w io.Writer) error {conn, err := driver.db.Conn(ctx)if err != nil {- return "", err+ return err}defer conn.Close()@@ -35,12 +35,12 @@ func (driver *Driver) Dump(ctx context.Context, w io.Writer) (string, error) {err = rows.Err()return err}); err != nil {- return "", err+ return err}if _, err := w.Write([]byte(sb.String())); err != nil {- return "", err+ return err}- return sb.String(), nil+ return nil}diff --git a/backend/plugin/db/databricks/dump.go b/backend/plugin/db/databricks/dump.goindex f494628cba..9c3272731b 100644--- a/backend/plugin/db/databricks/dump.go+++ b/backend/plugin/db/databricks/dump.go@@ -27,10 +27,10 @@ var (dftSchema = "default")-func (d *Driver) Dump(ctx context.Context, writer io.Writer) (string, error) {+func (d *Driver) Dump(ctx context.Context, writer io.Writer) error {catalogMap, err := d.listCatologTables(ctx, "")if err != nil {- return "", err+ return err}for catalogName, schemaMap := range catalogMap {@@ -38,7 +38,7 @@ func (d *Driver) Dump(ctx context.Context, writer io.Writer) (string, error) {continue}if _, err := writer.Write([]byte(fmt.Sprintf("CREATE CATALOG %s\n", catalogName))); err != nil {- return "", err+ return err}for schemaName, tableList := range schemaMap {@@ -48,7 +48,7 @@ func (d *Driver) Dump(ctx context.Context, writer io.Writer) (string, error) {if schemaName != dftSchema {_, err := writer.Write([]byte(fmt.Sprintf("CREATE SCHEMA `%s`.`%s`\n", catalogName, schemaName)))if err != nil {- return "", err+ return err}}@@ -59,52 +59,52 @@ func (d *Driver) Dump(ctx context.Context, writer io.Writer) (string, error) {for _, tblUnion := range tableList {qualifiedName, err := getQualifiedTblName(catalogName, schemaName, tblUnion.name)if err != nil {- return "", err+ return err}switch tblUnion.typeName {case catalog.TableTypeView:ddl, err := d.showCreateTable(ctx, qualifiedName)if err != nil {- return "", err+ return err}formatDDL := fmt.Sprintf(schemaStmtFmt, "VIEW", qualifiedName, ddl)if _, err := viewDDL.WriteString(formatDDL); err != nil {- return "", err+ return err}case catalog.TableTypeMaterializedView:tblAddInfo, err := d.descTbl(ctx, qualifiedName)if err != nil {- return "", err+ return err}tblProperties, err := formatTblProperties(tblAddInfo)if err != nil {- return "", err+ return err}formatDDL, err := genMaterializedViewDDL(qualifiedName, tblUnion.materialView, tblProperties)if err != nil {- return "", err+ return err}if _, err := mtViewDDL.WriteString(formatDDL); err != nil {- return "", err+ return err}case catalog.TableTypeExternal:ddl, err := d.showCreateTable(ctx, qualifiedName)if err != nil {- return "", err+ return err}formatDDL := fmt.Sprintf(schemaStmtFmt, "EXTERNAL TABLE", qualifiedName, ddl)if _, err := extTblDDL.WriteString(formatDDL); err != nil {- return "", err+ return err}case catalog.TableTypeManaged:ddl, err := d.showCreateTable(ctx, qualifiedName)if err != nil {- return "", err+ return err}formatDDL := fmt.Sprintf(schemaStmtFmt, "MANAGED TABLE", qualifiedName, ddl)if _, err := mngTblDDL.WriteString(formatDDL); err != nil {- return "", err+ return err}default:// we do not sync streaming table.@@ -112,21 +112,21 @@ func (d *Driver) Dump(ctx context.Context, writer io.Writer) (string, error) {}}if _, err := writer.Write([]byte(mngTblDDL.String())); err != nil {- return "", err+ return err}if _, err := writer.Write([]byte(extTblDDL.String())); err != nil {- return "", err+ return err}if _, err := writer.Write([]byte(viewDDL.String())); err != nil {- return "", err+ return err}if _, err := writer.Write([]byte(mtViewDDL.String())); err != nil {- return "", err+ return err}}}- return "", nil+ return nil}func (d *Driver) showCreateTable(ctx context.Context, qualifiedTblName string) (string, error) {diff --git a/backend/plugin/db/dm/dump.go b/backend/plugin/db/dm/dump.goindex 56bfb16f7a..f3ed8feeed 100644--- a/backend/plugin/db/dm/dump.go+++ b/backend/plugin/db/dm/dump.go@@ -11,20 +11,20 @@ import ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {txn, err := driver.db.BeginTx(ctx, &sql.TxOptions{})if err != nil {- return "", err+ return err}defer txn.Rollback()schemas, err := getSchemas(txn)if err != nil {- return "", err+ return err}if len(schemas) == 0 {- return "", nil+ return err}var quotedSchemas []string@@ -32,13 +32,11 @@ func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {quotedSchemas = append(quotedSchemas, fmt.Sprintf("'%s'", schema))}if err := dumpTxn(ctx, txn, quotedSchemas, out); err != nil {- return "", err+ return err}- if err := txn.Commit(); err != nil {- return "", err- }- return "", nil+ err = txn.Commit()+ return err}func dumpTxn(ctx context.Context, txn *sql.Tx, schemas []string, out io.Writer) error {diff --git a/backend/plugin/db/driver.go b/backend/plugin/db/driver.goindex fdf98a27af..ae276da7ac 100644--- a/backend/plugin/db/driver.go+++ b/backend/plugin/db/driver.go@@ -305,7 +305,7 @@ type Driver interface {// CheckSlowQueryLogEnabled checks if the slow query log is enabled.CheckSlowQueryLogEnabled(ctx context.Context) error// Dump dumps the schema of database.- Dump(ctx context.Context, out io.Writer) (string, error)+ Dump(ctx context.Context, out io.Writer) error}// Register makes a database driver available by the provided type.diff --git a/backend/plugin/db/dynamodb/dump.go b/backend/plugin/db/dynamodb/dump.goindex 737589558a..54992816b0 100644--- a/backend/plugin/db/dynamodb/dump.go+++ b/backend/plugin/db/dynamodb/dump.go@@ -6,6 +6,6 @@ import ()// Dump dumps the database.-func (*Driver) Dump(_ context.Context, _ io.Writer) (string, error) {- return "", nil+func (*Driver) Dump(_ context.Context, _ io.Writer) error {+ return nil}diff --git a/backend/plugin/db/elasticsearch/dump.go b/backend/plugin/db/elasticsearch/dump.goindex a318831040..cf524c8de7 100644--- a/backend/plugin/db/elasticsearch/dump.go+++ b/backend/plugin/db/elasticsearch/dump.go@@ -6,6 +6,6 @@ import ()// Dump() is not applicable to Elasticsearch.-func (*Driver) Dump(_ context.Context, _ io.Writer) (string, error) {- return "", nil+func (*Driver) Dump(_ context.Context, _ io.Writer) error {+ return nil}diff --git a/backend/plugin/db/hive/dump.go b/backend/plugin/db/hive/dump.goindex f21acd16b2..4486978627 100644--- a/backend/plugin/db/hive/dump.go+++ b/backend/plugin/db/hive/dump.go@@ -53,29 +53,29 @@ type MaterializedViewDDLOptions struct {as string}-func (d *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (d *Driver) Dump(ctx context.Context, out io.Writer) error {var builder strings.BuilderdatabaseName := d.config.Databasedatabase, err := d.SyncDBSchema(ctx)if err != nil {- return "", err+ return err}if len(database.Schemas) == 0 {- return "", errors.New("database schemas is empty")+ return errors.New("database schemas is empty")}schema := database.Schemas[0]cursor := d.conn.Cursor()if err := executeCursor(ctx, cursor, fmt.Sprintf("use %s", databaseName)); err != nil {- return "", err+ return err}// dump managed tables.for _, table := range schema.GetTables() {tableDDL, err := showCreateDDL(ctx, d.conn, "TABLE", table.Name, d.config.MaximumSQLResultSize)if err != nil {- return "", errors.Wrapf(err, "failed to dump table %s", table.Name)+ return errors.Wrapf(err, "failed to dump table %s", table.Name)}// dump indexes.@@ -97,7 +97,7 @@ func (d *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {comment: index.Comment,})if err != nil {- return "", errors.Wrapf(err, "failed to generate DDL for index %s", index.Name)+ return errors.Wrapf(err, "failed to generate DDL for index %s", index.Name)}_, _ = builder.WriteString(fmt.Sprintf(schemaStmtFmt, "INDEX", fmt.Sprintf("`%s`", index.Name), indexDDL))@@ -109,7 +109,7 @@ func (d *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {for _, extTable := range schema.GetExternalTables() {tabDDL, err := showCreateDDL(ctx, d.conn, "TABLE", extTable.Name, d.config.MaximumSQLResultSize)if err != nil {- return "", errors.Wrapf(err, "failed to dump table %s", extTable.Name)+ return errors.Wrapf(err, "failed to dump table %s", extTable.Name)}_, _ = builder.WriteString(tabDDL)}@@ -118,7 +118,7 @@ func (d *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {for _, view := range schema.GetViews() {viewDDL, err := showCreateDDL(ctx, d.conn, "VIEW", view.Name, d.config.MaximumSQLResultSize)if err != nil {- return "", errors.Wrapf(err, "failed to dump view %s", view.Name)+ return errors.Wrapf(err, "failed to dump view %s", view.Name)}_, _ = builder.WriteString(viewDDL)}@@ -143,16 +143,16 @@ func (d *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {as: mtView.Definition,})if err != nil {- return "", errors.Wrapf(err, "failed to generate DDL for materialized view %s", mtView.Name)+ return errors.Wrapf(err, "failed to generate DDL for materialized view %s", mtView.Name)}_, _ = builder.WriteString(fmt.Sprintf(schemaStmtFmt, "MATERIALIZED VIEW", fmt.Sprintf("`%s`.`%s`", databaseName, mtView.Name), mtViewDDL))}if _, err = io.WriteString(out, builder.String()); err != nil {- return "", err+ return err}- return builder.String(), nil+ return nil}// This function shows DDLs for creating certain type of schema [VIEW, DATABASE, TABLE].diff --git a/backend/plugin/db/mongodb/mongodb.go b/backend/plugin/db/mongodb/mongodb.goindex 3a223aaad1..15b74d380f 100644--- a/backend/plugin/db/mongodb/mongodb.go+++ b/backend/plugin/db/mongodb/mongodb.go@@ -181,8 +181,8 @@ func (driver *Driver) Execute(ctx context.Context, statement string, _ db.Execut}// Dump dumps the database.-func (*Driver) Dump(_ context.Context, _ io.Writer) (string, error) {- return "", nil+func (*Driver) Dump(_ context.Context, _ io.Writer) error {+ return nil}// getBasicMongoDBConnectionURI returns the basic MongoDB connection URI, the following fields are excluded:diff --git a/backend/plugin/db/mssql/dump.go b/backend/plugin/db/mssql/dump.goindex 5b9f190e4d..3cafe8e6b9 100644--- a/backend/plugin/db/mssql/dump.go+++ b/backend/plugin/db/mssql/dump.go@@ -18,21 +18,18 @@ const ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {txn, err := driver.db.BeginTx(ctx, &sql.TxOptions{})if err != nil {- return "", err+ return err}defer txn.Rollback()if err := driver.dumpDatabaseTxn(ctx, txn, out); err != nil {- return "", errors.Wrapf(err, "failed to dump database %q", driver.databaseName)+ return errors.Wrapf(err, "failed to dump database %q", driver.databaseName)}- if err := txn.Commit(); err != nil {- return "", err- }- return "", nil+ return txn.Commit()}const (diff --git a/backend/plugin/db/mysql/dump.go b/backend/plugin/db/mysql/dump.goindex dfa9fc2e26..1a323ea2cc 100644--- a/backend/plugin/db/mysql/dump.go+++ b/backend/plugin/db/mysql/dump.go@@ -84,18 +84,16 @@ var ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {// mysqldump -u root --databases dbName --no-data --routines --events --triggers --compact// We must use the same MySQL connection to lock and unlock tables.conn, err := driver.db.Conn(ctx)if err != nil {- return "", err+ return err}defer conn.Close()- var payloadBytes []byte-readOnly := driver.getReadOnly()options := sql.TxOptions{ReadOnly: readOnly}@@ -104,20 +102,17 @@ func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {// ref: https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html, section "Interaction of Table Locking and Transactions".txn, err := conn.BeginTx(ctx, &options)if err != nil {- return "", err+ return err}defer txn.Rollback()slog.Debug("begin to dump database", slog.String("database", driver.databaseName))if err := dumpTxn(txn, driver.dbType, driver.databaseName, out); err != nil {- return "", err- }-- if err := txn.Commit(); err != nil {- return "", err+ return err}- return string(payloadBytes), nil+ err = txn.Commit()+ return err}func dumpTxn(txn *sql.Tx, dbType storepb.Engine, database string, out io.Writer) error {diff --git a/backend/plugin/db/obo/dump.go b/backend/plugin/db/obo/dump.goindex 96cdbe19a7..34a4643fa1 100644--- a/backend/plugin/db/obo/dump.go+++ b/backend/plugin/db/obo/dump.go@@ -14,21 +14,21 @@ import ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {txn, err := driver.db.BeginTx(ctx, &sql.TxOptions{})if err != nil {- return "", err+ return err}defer txn.Rollback()if err := driver.dumpTxn(ctx, txn, []string{driver.databaseName}, out); err != nil {- return "", err+ return err}if err := txn.Commit(); err != nil {- return "", err+ return err}- return "", nil+ return err}func (driver *Driver) dumpTxn(ctx context.Context, txn *sql.Tx, schemas []string, out io.Writer) error {diff --git a/backend/plugin/db/oracle/dump.go b/backend/plugin/db/oracle/dump.goindex 98cf63727e..f90053702a 100644--- a/backend/plugin/db/oracle/dump.go+++ b/backend/plugin/db/oracle/dump.go@@ -16,21 +16,18 @@ import ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {txn, err := driver.db.BeginTx(ctx, &sql.TxOptions{})if err != nil {- return "", err+ return err}defer txn.Rollback()if err := driver.dumpSchemaTxn(ctx, txn, driver.databaseName, out); err != nil {- return "", errors.Wrapf(err, "failed to dump database %q", driver.databaseName)+ return errors.Wrapf(err, "failed to dump database %q", driver.databaseName)}- if err := txn.Commit(); err != nil {- return "", err- }- return "", nil+ return txn.Commit()}func (driver *Driver) dumpSchemaTxn(ctx context.Context, txn *sql.Tx, schema string, out io.Writer) error {diff --git a/backend/plugin/db/pg/dump.go b/backend/plugin/db/pg/dump.goindex 169dc06eca..a9153645b9 100644--- a/backend/plugin/db/pg/dump.go+++ b/backend/plugin/db/pg/dump.go@@ -21,19 +21,19 @@ import ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {// We don't support pg_dump for CloudSQL, because pg_dump not support IAM & instance name for authentication.// To dump schema for CloudSQL, you need to run the cloud-sql-proxy with IAM to get the host and port.// Learn more: https://linear.app/bytebase/issue/BYT-5401/support-iam-authentication-for-gcp-and-awsif driver.config.AuthenticationType == storepb.DataSourceOptions_GOOGLE_CLOUD_SQL_IAM {- return "", nil+ return nil}// pg_dump -d dbName --schema-only+// Find all dumpable databasesdatabases, err := driver.getDatabases(ctx)if err != nil {- return "", errors.Wrap(err, "failed to get databases")+ return errors.Wrap(err, "failed to get databases")}var dumpableDbNames []string@@ -46,7 +46,7 @@ func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {}}if !exist {- return "", errors.Errorf("database %s not found", driver.databaseName)+ return errors.Errorf("database %s not found", driver.databaseName)}dumpableDbNames = []string{driver.databaseName}} else {@@ -60,11 +60,11 @@ func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {for _, dbName := range dumpableDbNames {if err := driver.dumpOneDatabaseWithPgDump(ctx, dbName, out); err != nil {- return "", err+ return err}}- return "", nil+ return nil}func (driver *Driver) dumpOneDatabaseWithPgDump(ctx context.Context, database string, out io.Writer) error {diff --git a/backend/plugin/db/redis/redis.go b/backend/plugin/db/redis/redis.goindex f5de73bd8c..9893b24635 100644--- a/backend/plugin/db/redis/redis.go+++ b/backend/plugin/db/redis/redis.go@@ -220,8 +220,8 @@ func (d *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteO// Dump and restore// Dump the database, if dbName is empty, then dump all databases.// Redis is schemaless, we don't support dump Redis data currently.-func (*Driver) Dump(_ context.Context, _ io.Writer) (string, error) {- return "", nil+func (*Driver) Dump(_ context.Context, _ io.Writer) error {+ return nil}// QueryConn queries a SQL statement in a given connection.diff --git a/backend/plugin/db/redshift/dump.go b/backend/plugin/db/redshift/dump.goindex 8b03e53a90..100ebdad9e 100644--- a/backend/plugin/db/redshift/dump.go+++ b/backend/plugin/db/redshift/dump.go@@ -7,6 +7,6 @@ import ()// Dump dumps the database to the writer. But not implemented yet.-func (*Driver) Dump(context.Context, io.Writer) (string, error) {- return "", nil+func (*Driver) Dump(context.Context, io.Writer) error {+ return nil}diff --git a/backend/plugin/db/risingwave/dump.go b/backend/plugin/db/risingwave/dump.goindex bf640c01ba..842ca8c805 100644--- a/backend/plugin/db/risingwave/dump.go+++ b/backend/plugin/db/risingwave/dump.go@@ -7,6 +7,6 @@ import (// Dump dumps the database.// TODO: RisingWave doesn't support pg_dump yet.-func (*Driver) Dump(_ context.Context, _ io.Writer) (string, error) {- return "", nil+func (*Driver) Dump(_ context.Context, _ io.Writer) error {+ return nil}diff --git a/backend/plugin/db/snowflake/dump.go b/backend/plugin/db/snowflake/dump.goindex 07492111ab..497fe1e0c5 100644--- a/backend/plugin/db/snowflake/dump.go+++ b/backend/plugin/db/snowflake/dump.go@@ -21,22 +21,19 @@ const ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {txn, err := driver.db.BeginTx(ctx, &sql.TxOptions{})if err != nil {- return "", err+ return err}defer txn.Rollback()if err := dumpTxn(ctx, txn, driver.databaseName, out); err != nil {- return "", err- }-- if err := txn.Commit(); err != nil {- return "", err+ return err}- return "", nil+ err = txn.Commit()+ return err}// dumpTxn will dump the input database. schemaOnly isn't supported yet and true by default.diff --git a/backend/plugin/db/spanner/dump.go b/backend/plugin/db/spanner/dump.goindex ff59737f0f..a78d0c5750 100644--- a/backend/plugin/db/spanner/dump.go+++ b/backend/plugin/db/spanner/dump.go@@ -10,10 +10,10 @@ import ()// Dump dumps the database.-func (d *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (d *Driver) Dump(ctx context.Context, out io.Writer) error {instance, err := d.SyncInstance(ctx)if err != nil {- return "", err+ return err}var dumpableDbNames []stringif d.databaseName != "" {@@ -25,7 +25,7 @@ func (d *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {}}if !exist {- return "", errors.Errorf("database %q not found", d.databaseName)+ return errors.Errorf("database %q not found", d.databaseName)}dumpableDbNames = []string{d.databaseName}} else {@@ -38,14 +38,14 @@ func (d *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {Database: getDSN(d.config.Host, db),})if err != nil {- return "", err+ return err}for _, stmt := range resp.Statements {if _, err := io.WriteString(out, fmt.Sprintf("%s;\n", stmt)); err != nil {- return "", err+ return err}}}- return "", nil+ return nil}diff --git a/backend/plugin/db/sqlite/dump.go b/backend/plugin/db/sqlite/dump.goindex c913081b72..63058a05a2 100644--- a/backend/plugin/db/sqlite/dump.go+++ b/backend/plugin/db/sqlite/dump.go@@ -12,15 +12,15 @@ import ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {if driver.databaseName == "" {- return "", errors.Errorf("SQLite can dump one database only at a time")+ return errors.Errorf("SQLite can dump one database only at a time")}// Find all dumpable databases and make sure the existence of the database to be dumped.databases, err := driver.getDatabases()if err != nil {- return "", errors.Wrap(err, "failed to get databases")+ return errors.Wrap(err, "failed to get databases")}exist := falsefor _, n := range databases {@@ -30,14 +30,10 @@ func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {}}if !exist {- return "", errors.Errorf("database %s not found", driver.databaseName)+ return errors.Errorf("database %s not found", driver.databaseName)}- if err := driver.dumpOneDatabase(ctx, out); err != nil {- return "", err- }-- return "", nil+ return driver.dumpOneDatabase(ctx, out)}type sqliteSchema struct {diff --git a/backend/plugin/db/starrocks/dump.go b/backend/plugin/db/starrocks/dump.goindex 45f4068ffb..8b885e114a 100644--- a/backend/plugin/db/starrocks/dump.go+++ b/backend/plugin/db/starrocks/dump.go@@ -69,13 +69,13 @@ const ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {// mysqldump -u root --databases dbName --no-data --routines --events --triggers --compact// We must use the same MySQL connection to lock and unlock tables.conn, err := driver.db.Conn(ctx)if err != nil {- return "", err+ return err}defer conn.Close()@@ -85,20 +85,16 @@ func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {// ref: https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html, section "Interaction of Table Locking and Transactions".txn, err := conn.BeginTx(ctx, &options)if err != nil {- return "", err+ return err}defer txn.Rollback()slog.Debug("begin to dump database", slog.String("database", driver.databaseName))if err := dumpTxn(txn, driver.databaseName, out); err != nil {- return "", err- }-- if err := txn.Commit(); err != nil {- return "", err+ return err}- return "", nil+ return txn.Commit()}func dumpTxn(txn *sql.Tx, database string, out io.Writer) error {diff --git a/backend/plugin/db/tidb/dump.go b/backend/plugin/db/tidb/dump.goindex d81f72df68..6022d0b376 100644--- a/backend/plugin/db/tidb/dump.go+++ b/backend/plugin/db/tidb/dump.go@@ -85,18 +85,16 @@ var ()// Dump dumps the database.-func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {+func (driver *Driver) Dump(ctx context.Context, out io.Writer) error {// mysqldump -u root --databases dbName --no-data --routines --events --triggers --compact// We must use the same MySQL connection to lock and unlock tables.conn, err := driver.db.Conn(ctx)if err != nil {- return "", err+ return err}defer conn.Close()- var payloadBytes []byte-options := sql.TxOptions{}// TiDB does not support readonly, so we only set for MySQL and OceanBase.if driver.dbType == storepb.Engine_MYSQL || driver.dbType == storepb.Engine_MARIADB || driver.dbType == storepb.Engine_OCEANBASE {@@ -105,20 +103,17 @@ func (driver *Driver) Dump(ctx context.Context, out io.Writer) (string, error) {txn, err := conn.BeginTx(ctx, &options)if err != nil {- return "", err+ return err}defer txn.Rollback()slog.Debug("begin to dump database", slog.String("database", driver.databaseName))if err := dumpTxn(txn, driver.dbType, driver.databaseName, out); err != nil {- return "", err- }-- if err := txn.Commit(); err != nil {- return "", err+ return err}- return string(payloadBytes), nil+ err = txn.Commit()+ return err}// FlushTablesWithReadLock runs FLUSH TABLES table1, table2, ... WITH READ LOCK for all the tables in the database.diff --git a/backend/runner/schemasync/syncer.go b/backend/runner/schemasync/syncer.goindex f7df851958..f98696d986 100644--- a/backend/runner/schemasync/syncer.go+++ b/backend/runner/schemasync/syncer.go@@ -412,7 +412,7 @@ func (s *Syncer) SyncDatabaseSchema(ctx context.Context, database *store.Databas// if oldDatabaseMetadata is nil and databaseMetadata is not, they are not equal resulting a sync.if force || !common.EqualDatabaseSchemaMetadataFast(oldDatabaseMetadata, databaseMetadata) {var schemaBuf bytes.Buffer- if _, err := driver.Dump(ctx, &schemaBuf); err != nil {+ if err := driver.Dump(ctx, &schemaBuf); err != nil {return errors.Wrapf(err, "failed to dump database schema for database %q", database.DatabaseName)}rawDump = schemaBuf.Bytes()diff --git a/backend/runner/taskrun/database_create_executor.go b/backend/runner/taskrun/database_create_executor.goindex b6559ee0ff..c1d1b513cc 100644--- a/backend/runner/taskrun/database_create_executor.go+++ b/backend/runner/taskrun/database_create_executor.go@@ -496,7 +496,7 @@ func (exec *DatabaseCreateExecutor) getSchemaFromPeerTenantDatabase(ctx context.}var schemaBuf bytes.Buffer- if _, err := driver.Dump(ctx, &schemaBuf); err != nil {+ if err := driver.Dump(ctx, &schemaBuf); err != nil {return nil, model.Version{}, "", err}return similarDB, schemaVersion, schemaBuf.String(), nildiff --git a/backend/runner/utils/sdl_utils.go b/backend/runner/utils/sdl_utils.goindex 3667a05e0a..ae9f0f1cd2 100644--- a/backend/runner/utils/sdl_utils.go+++ b/backend/runner/utils/sdl_utils.go@@ -29,7 +29,7 @@ func ComputeDatabaseSchemaDiff(ctx context.Context, instance *store.InstanceMess}()var schema bytes.Buffer- _, err = driver.Dump(ctx, &schema)+ err = driver.Dump(ctx, &schema)if err != nil {return "", errors.Wrap(err, "dump old schema")}diff --git a/backend/utils/utils.go b/backend/utils/utils.goindex 3c20c92956..aaad17ff4d 100644--- a/backend/utils/utils.go+++ b/backend/utils/utils.go@@ -252,7 +252,7 @@ func ExecuteMigrationWithFunc(ctx context.Context, driverCtx context.Context, s// Don't record schema if the database hasn't existed yet or is schemaless, e.g. 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 := driver.Dump(ctx, &prevSchemaBuf); err != nil {+ if err := driver.Dump(ctx, &prevSchemaBuf); err != nil {opts.LogSchemaDumpEnd(err.Error())return "", "", err}@@ -310,7 +310,7 @@ func ExecuteMigrationWithFunc(ctx context.Context, driverCtx context.Context, svar afterSchemaBuf bytes.Bufferif m.Type.NeedDump() {opts.LogSchemaDumpStart()- if _, err := driver.Dump(ctx, &afterSchemaBuf); err != nil {+ if err := driver.Dump(ctx, &afterSchemaBuf); err != nil {// We will ignore the dump error if the database is dropped.if strings.Contains(err.Error(), "not found") {return insertedID, "", nil