Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: trim parens of current_timestamp if do not contain precision for TiDB (#10848)

h3n4l14f2ebd59205
diff --git a/backend/plugin/schema/tidb/parse_to_metadata.go b/backend/plugin/schema/tidb/parse_to_metadata.go
index 892703f1e0..458b013fae 100644
--- a/backend/plugin/schema/tidb/parse_to_metadata.go
+++ b/backend/plugin/schema/tidb/parse_to_metadata.go
@@ -286,6 +286,9 @@ func restoreExpr(expr tidbast.ExprNode) (*string, error) {
if err != nil {
return nil, err
}
+ if result == "CURRENT_TIMESTAMP()" {
+ result = "CURRENT_TIMESTAMP"
+ }
return &result, nil
}
diff --git a/backend/plugin/schema/tidb/testdata/parse_to_metadata.yaml b/backend/plugin/schema/tidb/testdata/parse_to_metadata.yaml
index d0adf8e6fc..c1941afd14 100644
--- a/backend/plugin/schema/tidb/testdata/parse_to_metadata.yaml
+++ b/backend/plugin/schema/tidb/testdata/parse_to_metadata.yaml
@@ -4,6 +4,8 @@
`a` int NOT NULL COMMENT 'this is comment',
`b` VARCHAR(20) NOT NULL,
`c` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
+ `d` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `e` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(),
KEY `idx` (((`a` + 20))),
UNIQUE KEY `idx2` (`a`),
KEY `idx_length` (`b`(10)),
@@ -34,6 +36,20 @@
"defaultExpression": "CURRENT_TIMESTAMP(3)",
"onUpdate": "CURRENT_TIMESTAMP(3)",
"type": "timestamp(3)"
+ },
+ {
+ "name": "d",
+ "position": 4,
+ "defaultExpression": "CURRENT_TIMESTAMP",
+ "onUpdate": "CURRENT_TIMESTAMP",
+ "type": "datetime"
+ },
+ {
+ "name": "e",
+ "position": 5,
+ "defaultExpression": "CURRENT_TIMESTAMP",
+ "onUpdate": "CURRENT_TIMESTAMP",
+ "type": "datetime"
}
],
"indexes": [