Skip to content

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

fix: support tidb binary column type (#8578)

zll600962edce1d985
diff --git a/backend/api/v1/schema_design_transformer_tidb.go b/backend/api/v1/schema_design_transformer_tidb.go
index 9a50581b12..50b5617a9b 100644
--- a/backend/api/v1/schema_design_transformer_tidb.go
+++ b/backend/api/v1/schema_design_transformer_tidb.go
@@ -159,7 +159,7 @@ func (t *tidbTransformer) Enter(in tidbast.Node) (tidbast.Node, bool) {
return in, false
}
-// getIntOrBigIntStr returns the type string of tp.
+// columnTypeStr returns the type string of tp.
func columnTypeStr(tp *tidbtypes.FieldType) string {
switch tp.GetType() {
// https://pkg.go.dev/github.com/pingcap/tidb/parser/mysql#TypeLong
@@ -171,6 +171,13 @@ func columnTypeStr(tp *tidbtypes.FieldType) string {
// tp.String() return bigint(20)
return "bigint"
default:
+ str := tp.String()
+ if strings.Contains(str, "binary") {
+ tp.SetFlag(tidbmysql.BinaryFlag)
+ tp.SetCharset("binary")
+ tp.SetCollate("binary")
+ return tp.CompactStr()
+ }
return tp.String()
}
}
@@ -225,6 +232,9 @@ func tidbRestoreNodeDefault(node tidbast.Node) (string, error) {
}
func tidbRestoreFieldType(fieldType *tidbtypes.FieldType) (string, error) {
+ if strings.Contains(fieldType.String(), "binary") {
+ return fieldType.CompactStr(), nil
+ }
var buffer strings.Builder
flag := tidbformat.RestoreKeyWordLowercase
ctx := tidbformat.NewRestoreCtx(flag, &buffer)
@@ -871,5 +881,10 @@ func tidbNewFieldType(tp string) *tidbtypes.FieldType {
if decimalInt > 0 {
ft.SetDecimal(decimalInt)
}
+ if strings.Contains(tpStr, "binary") {
+ ft.SetFlag(tidbmysql.BinaryFlag)
+ ft.SetCharset("binary")
+ ft.SetCollate("binary")
+ }
return ft
}
diff --git a/backend/api/v1/testdata/tidb/design.yaml b/backend/api/v1/testdata/tidb/design.yaml
index 78f45cadb7..1dcf77132e 100644
--- a/backend/api/v1/testdata/tidb/design.yaml
+++ b/backend/api/v1/testdata/tidb/design.yaml
@@ -37,6 +37,26 @@
comment: "ID"
classification: ""
usercomment: ""
+ - name: age
+ position: 0
+ default: null
+ nullable: true
+ type: varbinary(500)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: name
+ position: 0
+ default: null
+ nullable: true
+ type: binary
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
indexes:
- name: PRIMARY
expressions:
@@ -218,6 +238,8 @@
);
CREATE TABLE `users` (
`id` int(11) NOT NULL COMMENT 'ID',
+ `age` varbinary(500) NULL,
+ `name` binary NULL,
PRIMARY KEY(`id`) CLUSTERED
) ENGINE = InnoDB DEFAULT CHARACTER SET = UTF8MB4 DEFAULT COLLATE = UTF8MB4_BIN;
diff --git a/backend/api/v1/testdata/tidb/schema.yaml b/backend/api/v1/testdata/tidb/schema.yaml
index c1673f53fe..5027bd3a57 100644
--- a/backend/api/v1/testdata/tidb/schema.yaml
+++ b/backend/api/v1/testdata/tidb/schema.yaml
@@ -5,6 +5,7 @@
c int,
a int default 1 comment 'abcdefg',
b varchar(20) default 'NULL' comment '',
+ d varbinary(500),
primary key (a, b),
constraint fk1 foreign key (a) references t2 (b)
);
@@ -48,6 +49,16 @@
comment: ""
classification: ""
usercomment: ""
+ - name: d
+ position: 0
+ default: null
+ nullable: true
+ type: varbinary(500)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
indexes:
- name: PRIMARY
expressions: