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(mysql): resolve conflict between default value and auto_increment (#9204)
zll60098e456670e5f
diff --git a/backend/api/v1/schema_design_transformer.go b/backend/api/v1/schema_design_transformer.goindex a231559d88..1bb4d439db 100644--- a/backend/api/v1/schema_design_transformer.go+++ b/backend/api/v1/schema_design_transformer.go@@ -1408,6 +1408,18 @@ func (g *mysqlDesignSchemaGenerator) EnterColumnDefinition(ctx *mysql.ColumnDefi}startPos := typeCtx.GetStop().GetTokenIndex() + 1+ // Column attributes.+ // TODO(zp): refactor column auto_increment.+ skipSchemaAutoIncrement := false+ for _, attr := range ctx.FieldDefinition().AllColumnAttribute() {+ if attr.AUTO_INCREMENT_SYMBOL() != nil || attr.DEFAULT_SYMBOL() != nil {+ // if schema string has default value or auto_increment.+ // and metdata has default value.+ // we skip the schema auto_increment and only compare default value.+ skipSchemaAutoIncrement = column.hasDefault+ break+ }+ }newAttr := extractNewAttrs(column, ctx.FieldDefinition().AllColumnAttribute())for _, attribute := range ctx.FieldDefinition().AllColumnAttribute() {@@ -1527,6 +1539,9 @@ func (g *mysqlDesignSchemaGenerator) EnterColumnDefinition(ctx *mysql.ColumnDefireturn}}++ case attribute.AUTO_INCREMENT_SYMBOL() != nil && skipSchemaAutoIncrement:+ // just skip this condition.default:if _, err := g.columnDefine.WriteString(ctx.GetParser().GetTokenStream().GetTextFromInterval(antlr.Interval{Start: startPos,diff --git a/backend/api/v1/testdata/design.yaml b/backend/api/v1/testdata/design.yamlindex b847a85ca1..c85bde6948 100644--- a/backend/api/v1/testdata/design.yaml+++ b/backend/api/v1/testdata/design.yaml@@ -172,3 +172,87 @@CREATE TABLE `t` (`a` int NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT 'this is comment';+- engine: 2+ baseline: |-+ CREATE TABLE `t1` (+ `a` int primary key+ );+ CREATE TABLE `t2` (+ `a` int AUTO_INCREMENT primary key+ );+ CREATE TABLE `t3` (+ `a` int default 1 primary key+ );+ CREATE TABLE `t4` (+ `a` int AUTO_INCREMENT primary key+ );+ target: |-+ {+ "schemas": [+ {+ "tables": [+ {+ "name": "t1",+ "columns": [+ {+ "name": "a",+ "nullable": true,+ "type": "int",+ "hasDefault": true,+ "defaultExpression": "auto_increment"+ }+ ]+ },+ {+ "name": "t2",+ "columns": [+ {+ "name": "a",+ "nullable": true,+ "type": "int",+ "hasDefault": true,+ "defaultExpression": "auto_increment"+ }+ ]+ },+ {+ "name": "t3",+ "columns": [+ {+ "name": "a",+ "nullable": true,+ "type": "int",+ "hasDefault": true,+ "defaultExpression": "auto_increment"+ }+ ]+ },+ {+ "name": "t4",+ "columns": [+ {+ "name": "a",+ "nullable": true,+ "type": "int",+ "hasDefault": true,+ "defaultExpression": "1"+ }+ ]+ }+ ]+ }+ ]+ }+ result: |+ CREATE TABLE `t1` (+ `a` int primary key auto_increment+ );+ CREATE TABLE `t2` (+ `a` int auto_increment primary key+ );+ CREATE TABLE `t3` (+ `a` int auto_increment primary key+ );+ CREATE TABLE `t4` (+ `a` int DEFAULT 1 primary key+ );