Skip to content

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

chore(structurer): nullable for text/blob/geometry/json (#10258)

h3n4l408a4a772a15
diff --git a/backend/plugin/schema/mysql/get_design_schema.go b/backend/plugin/schema/mysql/get_design_schema.go
index e6e0dbd364..15b9c9f796 100644
--- a/backend/plugin/schema/mysql/get_design_schema.go
+++ b/backend/plugin/schema/mysql/get_design_schema.go
@@ -2,6 +2,7 @@ package mysql
import (
"fmt"
+ "slices"
"sort"
"strings"
@@ -758,9 +759,13 @@ func (g *mysqlDesignSchemaGenerator) EnterColumnDefinition(ctx *mysql.ColumnDefi
return
}
if column.nullable {
- if _, err := g.columnDefine.WriteString(" NULL"); err != nil {
- g.err = err
- return
+ if !slices.ContainsFunc(expressionDefaultOnlyTypes, func(s string) bool {
+ return strings.EqualFold(s, column.tp)
+ }) {
+ if _, err := g.columnDefine.WriteString(" NULL"); err != nil {
+ g.err = err
+ return
+ }
}
} else {
if _, err := g.columnDefine.WriteString(" NOT NULL"); err != nil {
diff --git a/backend/plugin/schema/mysql/state.go b/backend/plugin/schema/mysql/state.go
index 27925c43bc..6a6163e080 100644
--- a/backend/plugin/schema/mysql/state.go
+++ b/backend/plugin/schema/mysql/state.go
@@ -492,8 +492,12 @@ func (c *columnState) toString(buf *strings.Builder) error {
return err
}
if c.nullable {
- if _, err := buf.WriteString(" NULL"); err != nil {
- return err
+ if !slices.ContainsFunc(expressionDefaultOnlyTypes, func(s string) bool {
+ return strings.EqualFold(s, c.tp)
+ }) {
+ if _, err := buf.WriteString(" NULL"); err != nil {
+ return err
+ }
}
} else {
if _, err := buf.WriteString(" NOT NULL"); err != nil {
diff --git a/backend/plugin/schema/mysql/testdata/get_design_schema.yaml b/backend/plugin/schema/mysql/testdata/get_design_schema.yaml
index cad0175b3a..1e88162f8e 100644
--- a/backend/plugin/schema/mysql/testdata/get_design_schema.yaml
+++ b/backend/plugin/schema/mysql/testdata/get_design_schema.yaml
@@ -33,6 +33,18 @@
"type": "text",
"nullable": true,
"defaultNull": true
+ },
+ {
+ "name": "c",
+ "type": "text",
+ "nullable": false,
+ "defaultExpression": "('aaa')"
+ },
+ {
+ "name": "d",
+ "type": "text",
+ "nullable": true,
+ "defaultExpression": "(NULL)"
}
],
"indexes": [
@@ -226,6 +238,8 @@
CREATE TABLE `t` (
`a` int NOT NULL,
`b` text,
+ `c` text NOT NULL DEFAULT ('aaa'),
+ `d` text DEFAULT (NULL),
UNIQUE KEY `t_a_uniq_idx` (`a`) COMMENT 'this is my comment ''!!'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `t4` (
@@ -247,7 +261,7 @@
`a` int NOT NULL COMMENT 'this is comment',
`b` VARCHAR(20) NOT NULL,
`c` int NOT NULL,
- `d` text NULL,
+ `d` text,
PRIMARY KEY (`a`),
UNIQUE KEY `t_c_uniq_idx` (`c`),
UNIQUE KEY `t_c_plus_5_uniq_idx` (((`c` + 5))),