Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: tidb version (#15958)
Danny Xuf59e37f4d51b
diff --git a/backend/plugin/db/tidb/sync.go b/backend/plugin/db/tidb/sync.goindex d1a7a00a31..1dfe6d0207 100644--- a/backend/plugin/db/tidb/sync.go+++ b/backend/plugin/db/tidb/sync.go@@ -50,7 +50,7 @@ var (// SyncInstance syncs the instance.func (d *Driver) SyncInstance(ctx context.Context) (*db.InstanceMetadata, error) {- version, _, err := d.getVersion(ctx)+ version, err := d.getVersion(ctx)if err != nil {return nil, err}diff --git a/backend/plugin/db/tidb/tidb.go b/backend/plugin/db/tidb/tidb.goindex 17cf06890e..fbbb761c2a 100644--- a/backend/plugin/db/tidb/tidb.go+++ b/backend/plugin/db/tidb/tidb.go@@ -132,24 +132,25 @@ func (d *Driver) GetDB() *sql.DB {}// getVersion gets the version.-func (d *Driver) getVersion(ctx context.Context) (string, string, error) {+func (d *Driver) getVersion(ctx context.Context) (string, error) {query := "SELECT VERSION()"var version stringif err := d.db.QueryRowContext(ctx, query).Scan(&version); err != nil {if err == sql.ErrNoRows {- return "", "", common.FormatDBErrorEmptyRowWithQuery(query)+ return "", common.FormatDBErrorEmptyRowWithQuery(query)}- return "", "", util.FormatErrorWithQuery(err, query)+ return "", util.FormatErrorWithQuery(err, query)}return parseVersion(version)}-func parseVersion(version string) (string, string, error) {- if loc := regexp.MustCompile(`^\d+.\d+.\d+`).FindStringIndex(version); loc != nil {- return version[loc[0]:loc[1]], version[loc[1]:], nil+func parseVersion(version string) (string, error) {+ // Examples: 8.0.11-TiDB-v8.5.0, 8.0.11-TiDB-v7.5.2-serverless.+ if loc := regexp.MustCompile(`v\d+\.\d+\.\d+`).FindStringIndex(version); loc != nil {+ return version[loc[0]:loc[1]], nil}- return "", "", errors.Errorf("failed to parse version %q", version)+ return "", errors.Errorf("failed to parse version %q", version)}// Execute executes a SQL statement.diff --git a/backend/plugin/db/tidb/tidb_test.go b/backend/plugin/db/tidb/tidb_test.goindex 0ec755076c..36206ea507 100644--- a/backend/plugin/db/tidb/tidb_test.go+++ b/backend/plugin/db/tidb/tidb_test.go@@ -8,38 +8,24 @@ import (func TestParseVersion(t *testing.T) {tests := []struct {- version string- want string- wantRest string+ version string+ want string}{{- version: "8.0.27",- want: "8.0.27",- wantRest: "",+ version: "8.0.11-TiDB-v8.5.0",+ want: "v8.5.0",},{- version: "5.7.22-log",- want: "5.7.22",- wantRest: "-log",- },- {- version: "5.6.29_ddm_3.0.1.7",- want: "5.6.29",- wantRest: "_ddm_3.0.1.7",- },- {- version: "10.4.7-MariaDB",- want: "10.4.7",- wantRest: "-MariaDB",+ version: "8.0.11-TiDB-v7.5.2-serverless",+ want: "v7.5.2",},}a := require.New(t)for _, tc := range tests {- version, rest, err := parseVersion(tc.version)+ version, err := parseVersion(tc.version)a.NoError(err)a.Equal(tc.want, version)- a.Equal(tc.wantRest, rest)}}