Skip to content

Commit b79a9e5

Browse files
committed
Support MariaDB UUID column type
The TiDB parser used by the MySQL engine does not recognize MariaDB's UUID column type, so schemas like `id uuid NOT NULL DEFAULT (uuid())` fail with a syntax error (#3401). Upgrade the parser to the latest upstream revision and add a dolphin preprocessor that rewrites `uuid` column types to `binary(16)` (matching MariaDB's internal 16-byte storage) before parsing, then restores the `uuid` type name in the AST. Map `uuid` to `string` in the MySQL Go codegen so callers receive the canonical 36-character representation. https://claude.ai/code/session_01NX1Ept2eQUWQ26qi4HGpKi
1 parent 64d18fc commit b79a9e5

File tree

12 files changed

+415
-8
lines changed

12 files changed

+415
-8
lines changed

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/lib/pq v1.12.3
1818
github.com/ncruces/go-sqlite3 v0.33.3
1919
github.com/pganalyze/pg_query_go/v6 v6.2.2
20-
github.com/pingcap/tidb/pkg/parser v0.0.0-20250324122243-d51e00e5bbf0
20+
github.com/pingcap/tidb/pkg/parser v0.0.0-20260418072757-ce92298d1124
2121
github.com/riza-io/grpc-go v0.2.0
2222
github.com/spf13/cobra v1.10.2
2323
github.com/spf13/pflag v1.0.10
@@ -34,13 +34,14 @@ require (
3434
require (
3535
cel.dev/expr v0.25.1 // indirect
3636
filippo.io/edwards25519 v1.1.1 // indirect
37+
github.com/coreos/go-semver v0.3.1 // indirect
3738
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3839
github.com/jackc/pgpassfile v1.0.0 // indirect
3940
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
4041
github.com/jackc/puddle/v2 v2.2.2 // indirect
4142
github.com/ncruces/go-sqlite3-wasm v1.1.1-0.20260409221933-87e4b35a38d0 // indirect
4243
github.com/ncruces/julianday v1.0.0 // indirect
43-
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb // indirect
44+
github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee // indirect
4445
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
4546
github.com/pingcap/log v1.1.0 // indirect
4647
github.com/rogpeppe/go-internal v1.10.0 // indirect

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmO
88
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
99
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
1010
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
11+
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
12+
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
1113
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
1214
github.com/cubicdaiya/gonp v1.0.4 h1:ky2uIAJh81WiLcGKBVD5R7KsM/36W6IqqTy6Bo6rGws=
1315
github.com/cubicdaiya/gonp v1.0.4/go.mod h1:iWGuP/7+JVTn02OWhRemVbMmG1DOUnmrGTYYACpOI0I=
@@ -58,14 +60,14 @@ github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvz
5860
github.com/pganalyze/pg_query_go/v6 v6.2.2 h1:O0L6zMC226R82RF3X5n0Ki6HjytDsoAzuzp4ATVAHNo=
5961
github.com/pganalyze/pg_query_go/v6 v6.2.2/go.mod h1:Cn6+j4870kJz3iYNsb0VsNG04vpSWgEvBwc590J4qD0=
6062
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
61-
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb h1:3pSi4EDG6hg0orE1ndHkXvX6Qdq2cZn8gAPir8ymKZk=
62-
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
63+
github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee h1:/IDPbpzkzA97t1/Z1+C3KlxbevjMeaI6BQYxvivu4u8=
64+
github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
6365
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
6466
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
6567
github.com/pingcap/log v1.1.0 h1:ELiPxACz7vdo1qAvvaWJg1NrYFoY6gqAh/+Uo6aXdD8=
6668
github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
67-
github.com/pingcap/tidb/pkg/parser v0.0.0-20250324122243-d51e00e5bbf0 h1:W3rpAI3bubR6VWOcwxDIG0Gz9G5rl5b3SL116T0vBt0=
68-
github.com/pingcap/tidb/pkg/parser v0.0.0-20250324122243-d51e00e5bbf0/go.mod h1:+8feuexTKcXHZF/dkDfvCwEyBAmgb4paFc3/WeYV2eE=
69+
github.com/pingcap/tidb/pkg/parser v0.0.0-20260418072757-ce92298d1124 h1:zYmP5fBH+i2yhhU6f5uOol6zxHtR2/sD47BsJLfy0oU=
70+
github.com/pingcap/tidb/pkg/parser v0.0.0-20260418072757-ce92298d1124/go.mod h1:zDLDsfNBU5+L6T4J9/OgWAHc/WZvMUjbpgHqQ/t3yKo=
6971
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
7072
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7173
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

internal/codegen/golang/mysql_type.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.C
114114
case "json":
115115
return "json.RawMessage"
116116

117+
case "uuid":
118+
// MariaDB UUID type. The go-sql-driver returns UUID values as the
119+
// canonical 36-character string representation.
120+
if notNull {
121+
return "string"
122+
}
123+
return "sql.NullString"
124+
117125
case "any":
118126
return "interface{}"
119127

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"contexts": ["base"],
3+
"meta": {
4+
"invalid_schema": true
5+
}
6+
}

internal/endtoend/testdata/mysql_mariadb_uuid/mysql/go/db.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/mysql_mariadb_uuid/mysql/go/models.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/mysql_mariadb_uuid/mysql/go/query.sql.go

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- name: GetDocument :one
2+
SELECT * FROM documents WHERE id = ?;
3+
4+
-- name: ListDocuments :many
5+
SELECT * FROM documents;
6+
7+
-- name: CreateDocument :exec
8+
INSERT INTO documents (owner) VALUES (?);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE TABLE `organisations` (
2+
`id` int NOT NULL AUTO_INCREMENT,
3+
`name` varchar(64) NOT NULL,
4+
`description` varchar(255) NOT NULL,
5+
PRIMARY KEY (`id`)
6+
);
7+
8+
CREATE TABLE `documents` (
9+
`id` uuid NOT NULL DEFAULT (uuid()),
10+
`uploaded` datetime NOT NULL DEFAULT (current_timestamp()),
11+
`owner` int NOT NULL,
12+
PRIMARY KEY (`id`),
13+
INDEX `owner` (`owner`),
14+
CONSTRAINT `owner` FOREIGN KEY (`owner`) REFERENCES `organisations` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
15+
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"sql_package": "database/sql",
7+
"sql_driver": "github.com/go-sql-driver/mysql",
8+
"engine": "mysql",
9+
"name": "querytest",
10+
"schema": "schema.sql",
11+
"queries": "query.sql"
12+
}
13+
]
14+
}

0 commit comments

Comments
 (0)