drizzle-team / drizzle-team/drizzle-orm
MySQL enum values containing commas are corrupted by Drizzle Kit enum type splitting
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
## Summary
`mysqlEnum('e', ['a,b', 'c'])` can be serialized incorrectly during MySQL snapshot generation. The enum builder emits `enum('a,b','c')`, but Drizzle Kit's MySQL serializer splits the enum body on every comma, including commas inside quoted enum values.
## Steps to reproduce
1. Define a MySQL enum column with a comma inside one enum value:
```ts
mysqlEnum('e', ['a,b', 'c'])
```
2. Let the MySQL snapshot serializer normalize the generated SQL type:
```ts
enum('a,b','c')
```
3. Observe how the enum body is split.
## Expected behavior
The enum should remain two values:
```sql
enum('a,b','c')
```
The comma inside `'a,b'` should be preserved as part of the first enum value.
## Actual behavior
The serializer splits on every comma:
```ts
["'a", "b'", "'c'"]
```
In a source-level reproduction of the current serializer logic, this becomes:
```sql
enum('','','c')
```
So the original `a,b` value is not preserved.
## Evidence
- `drizzle-orm/src/mysql-core/columns/enum.ts` accepts string enum arrays through `mysqlEnum(...)`.
- The MySQL enum builder emits enum SQL by joining quoted values with commas.
- `drizzle-kit/src/serializer/mysqlSerializer.ts` reparses the enum SQL type using raw comma splitting.
- The serializer applies that parser to enum column SQL types during snapshot generation.
A minimal checked result for `['a,b', 'c']`:
- builder SQL type: `enum('a,b','c')`
- split tokens: `["'a", "b'", "'c'"]`
- serialized output: `enum('','','c')`
## Suggested fix
Parse the `enum(...)` value list as quoted SQL string literals instead of splitting on raw commas. Another option would be to avoid reparsing the SQL type string when reliable `enumValues` are already available from the column object.
A focused regression test could add a MySQL enum case with:
```ts
mysqlEnum('e', ['a,b', 'c'])
```
and assert that the generated snapshot / SQL type preserves:
```sql
enum('a,b','c')
```
## Additional context / Related coverage
A current GitHub search did not identify exact coverage for commas inside MySQL enum values. Existing nearby coverage exercises single-quote escaping for MySQL enum values. Adjacent PR `#2959` covers enum single-quote escaping, but this comma-preservation case appears separate.
---
Submitted with Codex.
Contributor guide
Research direction
Start in drizzle-kit/src/serializer/mysqlSerializer.ts and trace how MySQL enum column SQL types are parsed during snapshot generation. Review drizzle-orm/src/mysql-core/columns/enum.ts and nearby coverage for single-quote escaping, then add a regression case for mysqlEnum('e', ['a,b', 'c']). Done means the generated snapshot or SQL type preserves enum('a,b','c') with two values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100