fix(drizzle-kit): preserve commas inside MySQL enum values in snapshots (#5957)#5961
Open
HarperZ9 wants to merge 1 commit into
Open
fix(drizzle-kit): preserve commas inside MySQL enum values in snapshots (#5957)#5961HarperZ9 wants to merge 1 commit into
HarperZ9 wants to merge 1 commit into
Conversation
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>
Author
|
Current verification note from a fresh Windows checkout:
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5957.
Problem
handleEnumTypeindrizzle-kit/src/serializer/mysqlSerializer.tssplits the enum body on every comma:MySqlEnumColumn.getSQLType()emits enum values as raw, single-quoted strings joined by commas, so a value that itself contains a comma gets split apart. FormysqlEnum('col', ['a,b', 'c'])(typeenum('a,b','c')) the generated snapshot column type comes out corrupted asenum('','','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 commasindrizzle-kit/tests/mysql.test.ts, modeled on the existingadd table with ts enumtest (no database required). It asserts that a plain enum still producesenum('a','b','c')and a comma-containing enum producesenum('a,b','c'). The test fails on the current code (enum('','','c')) and passes with the fix.Notes
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.pnpm testend to end locally because the workspacedrizzle-ormdist build fails on Windows (atscpath-separator issue in the build tooling, unrelated to this change). The regression test was run against the realgenerateMySqlSnapshotcode path via vitest; CI should run the standard harness cleanly.