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: ignore auto random base from table schema dump (#8216)
Danny Xudf3a02861f8c
diff --git a/backend/plugin/db/mysql/dump.go b/backend/plugin/db/mysql/dump.goindex fb521f99e4..284460adf7 100644--- a/backend/plugin/db/mysql/dump.go+++ b/backend/plugin/db/mysql/dump.go@@ -81,7 +81,8 @@ const ()var (- excludeAutoIncrement = regexp.MustCompile(` AUTO_INCREMENT=\d+`)+ excludeAutoIncrement = regexp.MustCompile(` AUTO_INCREMENT=\d+`)+ excludeAutoRandomBase = regexp.MustCompile(` AUTO_RANDOM_BASE=\d+`))// Dump dumps the database.@@ -228,7 +229,7 @@ func dumpTxn(txn *sql.Tx, dbType db.Type, database string, out io.Writer, schemacontinue}if schemaOnly {- tbl.Statement = excludeSchemaAutoIncrementValue(tbl.Statement)+ tbl.Statement = excludeSchemaAutoValues(tbl.Statement)}if _, err := io.WriteString(out, fmt.Sprintf("%s\n", tbl.Statement)); err != nil {return err@@ -307,9 +308,13 @@ func getTemporaryView(name string, columns []string) string {return fmt.Sprintf(tempViewStmtFmt, name, stmt)}-// excludeSchemaAutoIncrementValue excludes the starting value of AUTO_INCREMENT if it's a schema only dump.+// excludeSchemaAutoValues excludes+// 1) the starting value of AUTO_INCREMENT if it's a schema only dump.// https://github.com/bytebase/bytebase/issues/123-func excludeSchemaAutoIncrementValue(s string) string {+// 2) The auto random base in TiDB.+// /*T![auto_rand_base] AUTO_RANDOM_BASE=39456621 */.+func excludeSchemaAutoValues(s string) string {+ s = excludeAutoRandomBase.ReplaceAllString(s, ``)return excludeAutoIncrement.ReplaceAllString(s, ``)}diff --git a/backend/plugin/db/mysql/dump_test.go b/backend/plugin/db/mysql/dump_test.goindex 63ae6619a9..5f6a51d9d2 100644--- a/backend/plugin/db/mysql/dump_test.go+++ b/backend/plugin/db/mysql/dump_test.go@@ -13,7 +13,7 @@ func TestGetTemporaryView(t *testing.T) {a.Equal(want, got)}-func TestExcludeSchemaAutoIncrementValue(t *testing.T) {+func TestExcludeSchemaAutoValue(t *testing.T) {tests := []struct {stmt stringwant string@@ -28,6 +28,16 @@ func TestExcludeSchemaAutoIncrementValue(t *testing.T) {PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;`,},+ {+ `CREATE TABLE world (+ id int NOT NULL AUTO_INCREMENT,+ PRIMARY KEY (id)+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci /*T![auto_rand_base] AUTO_RANDOM_BASE=39456621 */;`,+ `CREATE TABLE world (+ id int NOT NULL AUTO_INCREMENT,+ PRIMARY KEY (id)+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci /*T![auto_rand_base] */;`,+ },{`CREATE TABLE world (id int NOT NULL AUTO_INCREMENT,@@ -41,7 +51,7 @@ func TestExcludeSchemaAutoIncrementValue(t *testing.T) {}for _, test := range tests {- got := excludeSchemaAutoIncrementValue(test.stmt)+ got := excludeSchemaAutoValues(test.stmt)require.Equal(t, test.want, got)}}