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: fix on update for tidb (#11066)
Danny Xuaab1c0618cbb
diff --git a/backend/plugin/schema/tidb/get_design_schema_test.go b/backend/plugin/schema/tidb/get_design_schema_test.goindex 4c64288d8c..b22502725d 100644--- a/backend/plugin/schema/tidb/get_design_schema_test.go+++ b/backend/plugin/schema/tidb/get_design_schema_test.go@@ -55,3 +55,27 @@ func TestGetDesignSchema(t *testing.T) {a.NoError(err)}}++func TestNormalizeOnUpdate(t *testing.T) {+ tests := []struct {+ s string+ want string+ }{+ {+ s: "current_timestamp(6)",+ want: "CURRENT_TIMESTAMP(6)",+ },+ {+ s: "current_timestamp",+ want: "CURRENT_TIMESTAMP",+ },+ {+ s: "hello",+ want: "hello",+ },+ }+ for _, tc := range tests {+ got := normalizeOnUpdate(tc.s)+ require.Equal(t, tc.want, got, tc.s)+ }+}diff --git a/backend/plugin/schema/tidb/state.go b/backend/plugin/schema/tidb/state.goindex f33ff9b200..3d94c1f86a 100644--- a/backend/plugin/schema/tidb/state.go+++ b/backend/plugin/schema/tidb/state.go@@ -600,7 +600,7 @@ func normalizeOnUpdate(s string) string {re := regexp.MustCompile(`(current_timestamp|now|localtime|localtimestamp)(?:\((\d+)\))?`)match := re.FindStringSubmatch(lowerS)if len(match) > 0 {- if len(match) > 1 && match[1] != "" {+ if len(match) >= 3 && match[2] != "" {// has precisionreturn fmt.Sprintf("CURRENT_TIMESTAMP(%s)", match[2])}diff --git a/backend/plugin/schema/tidb/testdata/get_design_schema.yaml b/backend/plugin/schema/tidb/testdata/get_design_schema.yamlindex 6f77822331..8ff9380474 100644--- a/backend/plugin/schema/tidb/testdata/get_design_schema.yaml+++ b/backend/plugin/schema/tidb/testdata/get_design_schema.yaml@@ -73,7 +73,7 @@`a` int NOT NULL,`b` varchar(255) NOT NULL,`c` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),- `d` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(),+ `d` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,`e` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,KEY `idx_t_b` (`b`(20)) COMMENT 'this is comment with',KEY `idx_t_b2` (`b`(20))