Skip to content

fix(drizzle-kit): preserve commas inside MySQL enum values in snapshots (#5957)#5961

Open
HarperZ9 wants to merge 1 commit into
drizzle-team:mainfrom
HarperZ9:fix/mysql-enum-comma-split
Open

fix(drizzle-kit): preserve commas inside MySQL enum values in snapshots (#5957)#5961
HarperZ9 wants to merge 1 commit into
drizzle-team:mainfrom
HarperZ9:fix/mysql-enum-comma-split

Conversation

@HarperZ9

Copy link
Copy Markdown

Fixes #5957.

Problem

handleEnumType in drizzle-kit/src/serializer/mysqlSerializer.ts splits the enum body on every comma:

const values = str.split(',').map((v) => `'${escapeSingleQuotes(v.substring(1, v.length - 1))}'`);

MySqlEnumColumn.getSQLType() emits enum values as raw, single-quoted strings joined by commas, so a value that itself contains a comma gets split apart. For mysqlEnum('col', ['a,b', 'c']) (type enum('a,b','c')) the generated snapshot column type comes out corrupted as enum('','','c').

Fix

Take the content between the first ( and last ), strip the outer quotes, and split on the ',' delimiter between values rather than on every comma. Plain enums round-trip unchanged.

Test

Added add table with enum values containing commas in drizzle-kit/tests/mysql.test.ts, modeled on the existing add table with ts enum test (no database required). It asserts that a plain enum still produces enum('a','b','c') and a comma-containing enum produces enum('a,b','c'). The test fails on the current code (enum('','','c')) and passes with the fix.

Notes

  • Scoped to the comma bug. Separately, getSQLType() emits values unescaped, so an enum value containing a literal ' produces malformed SQL; that looks like a pre-existing issue deserving its own PR and is not addressed here.
  • I could not run the full pnpm test end to end locally because the workspace drizzle-orm dist build fails on Windows (a tsc path-separator issue in the build tooling, unrelated to this change). The regression test was run against the real generateMySqlSnapshot code path via vitest; CI should run the standard harness cleanly.

handleEnumType split the enum body on every comma, which also split
inside quoted values. MySqlEnumColumn.getSQLType emits each raw value
wrapped in single quotes joined by ",", so a value like 'a,b' produced a
corrupted snapshot type (e.g. enum('','','c')).

Extract the body between the first '(' and last ')', strip the outer
quotes, and split on the "','" delimiter between values instead of on
every comma. Plain enums like enum('a','b','c') round-trip unchanged.

Adds a regression test in drizzle-kit/tests/mysql.test.ts asserting that
mysqlEnum values containing commas serialize to enum('a,b','c').

Fixes drizzle-team#5957.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@HarperZ9

HarperZ9 commented Jul 2, 2026

Copy link
Copy Markdown
Author

Current verification note from a fresh Windows checkout:

  • npx.cmd -y pnpm@10.6.3 --version -> 10.6.3
  • npx.cmd -y pnpm@10.6.3 install --frozen-lockfile --force stops before Vitest with:
ERR_PNPM_FETCH_404 GET https://registry.npmjs.org/drizzle-kit/-/drizzle-kit-0.25.0-b1faa33.tgz: Not Found - 404

So I do not have a fresh local rerun of the targeted regression test from this checkout. This is an install/registry blocker before the test runner starts, not a failure of the enum-comma test. The branch itself is unchanged and still scoped to the serializer split bug plus the regression test described above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MySQL enum values containing commas are corrupted by Drizzle Kit enum type splitting

1 participant