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: handle tidb sequences (#6431)
Danny Xue3d59b0976e5
diff --git a/backend/plugin/db/mysql/dump.go b/backend/plugin/db/mysql/dump.goindex 118dfe5c9e..e7e5a856b6 100644--- a/backend/plugin/db/mysql/dump.go+++ b/backend/plugin/db/mysql/dump.go@@ -46,6 +46,11 @@ const ("-- View structure for `%s`\n" +"--\n" +"%s;\n"+ sequenceStmtFmt = "" ++ "--\n" ++ "-- Sequence structure for `%s`\n" ++ "--\n" ++ "%s;\n"tempViewStmtFmt = "" +"--\n" +"-- Temporary view structure for `%s`\n" +@@ -268,7 +273,7 @@ func dumpTxn(ctx context.Context, txn *sql.Tx, dbType db.Type, database string,}// Construct tables.for _, tbl := range tables {- if tbl.TableType != baseTableType {+ if tbl.TableType == viewTableType {continue}if schemaOnly {@@ -277,7 +282,7 @@ func dumpTxn(ctx context.Context, txn *sql.Tx, dbType db.Type, database string,if _, err := io.WriteString(out, fmt.Sprintf("%s\n", tbl.Statement)); err != nil {return err}- if !schemaOnly {+ if !schemaOnly && tbl.TableType == baseTableType {// Include db prefix if dumping multiple databases.includeDbPrefix := len(dumpableDbNames) > 1if err := exportTableData(txn, dbName, tbl.Name, includeDbPrefix, out); err != nil {@@ -534,6 +539,16 @@ func getTableStmt(txn *sql.Tx, dbName, tblName, tblType string) (string, error)return "", err}return fmt.Sprintf(viewStmtFmt, tblName, createStmt), nil+ case sequenceTableType:+ query := fmt.Sprintf("SHOW CREATE SEQUENCE `%s`.`%s`;", dbName, tblName)+ var stmt, unused string+ if err := txn.QueryRow(query).Scan(&unused, &stmt); err != nil {+ if err == sql.ErrNoRows {+ return "", common.FormatDBErrorEmptyRowWithQuery(query)+ }+ return "", err+ }+ return fmt.Sprintf(sequenceStmtFmt, tblName, stmt), nildefault:return "", errors.Errorf("unrecognized table type %q for database %q table %q", tblType, dbName, tblName)}diff --git a/backend/plugin/db/mysql/mysql.go b/backend/plugin/db/mysql/mysql.goindex df34683c09..2a36f89e72 100644--- a/backend/plugin/db/mysql/mysql.go+++ b/backend/plugin/db/mysql/mysql.go@@ -26,6 +26,8 @@ import (var (baseTableType = "BASE TABLE"viewTableType = "VIEW"+ // Sequence is available to TiDB only.+ sequenceTableType = "SEQUENCE"_ db.Driver = (*Driver)(nil))