Skip to content

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

feat: write canonical data type in our standard format (#12529)

h3n4lefb53f0069d0
diff --git a/backend/plugin/schema/mysql/state.go b/backend/plugin/schema/mysql/state.go
index 8989245cf6..029b105ba9 100644
--- a/backend/plugin/schema/mysql/state.go
+++ b/backend/plugin/schema/mysql/state.go
@@ -16,6 +16,8 @@ import (
mysql "github.com/bytebase/mysql-parser"
+ mysqldb "github.com/bytebase/bytebase/backend/plugin/db/mysql"
+
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -204,6 +206,9 @@ func (t *tableState) toString(buf io.StringWriter) error {
if indexes[i].primary {
return true
}
+ if indexes[j].primary {
+ return false
+ }
return indexes[i].name < indexes[j].name
})
@@ -1314,7 +1319,8 @@ type columnState struct {
}
func (c *columnState) toString(buf io.StringWriter) error {
- if _, err := buf.WriteString(fmt.Sprintf("`%s` %s", c.name, c.tp)); err != nil {
+ columnCanonicalType := mysqldb.GetColumnTypeCanonicalSynonym(strings.ToLower(c.tp))
+ if _, err := buf.WriteString(fmt.Sprintf("`%s` %s", c.name, columnCanonicalType)); err != nil {
return err
}
if !c.nullable {
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml
index 3878809d0a..91b6254c1f 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml
@@ -549,7 +549,7 @@
--
CREATE TABLE `t5` (
`a` int NOT NULL COMMENT 'this is comment',
- `b` VARCHAR(20) NOT NULL,
+ `b` varchar(20) NOT NULL,
`c` int NOT NULL,
`d` text,
PRIMARY KEY (`a`),
@@ -618,6 +618,11 @@
"nullable": true,
"type": "int",
"defaultExpression": "AUTO_INCREMENT"
+ },
+ {
+ "name": "b",
+ "nullable": true,
+ "type": "int(11)"
}
]
},
@@ -660,7 +665,8 @@
}
result: |
CREATE TABLE `t1` (
- `a` int primary key AUTO_INCREMENT
+ `a` int primary key AUTO_INCREMENT,
+ `b` int
);
CREATE TABLE `t2` (
`a` int AUTO_INCREMENT primary key