Skip to content

fix(drizzle-kit): preserve MySQL enum values containing commas#5965

Open
sanjibani wants to merge 2 commits into
drizzle-team:mainfrom
sanjibani:fix/mysql-enum-comma-splitter
Open

fix(drizzle-kit): preserve MySQL enum values containing commas#5965
sanjibani wants to merge 2 commits into
drizzle-team:mainfrom
sanjibani:fix/mysql-enum-comma-splitter

Conversation

@sanjibani

Copy link
Copy Markdown

The MySQL serializer's handleEnumType helper reparses the generated enum('a,b','c') SQL string by splitting on raw commas. When an enum value contains a comma (e.g. mysqlEnum('e', ['a,b', 'c'])), the splitter collapses 'a,b' into two pieces 'a' and 'b', corrupting the snapshot type to enum('','','c').

The new matchAll pattern parses the value list as quoted SQL string literals. It tolerates escaped '' for embedded single quotes (consistent with the existing escapeSingleQuotes round-trip).

Regression test added in drizzle-kit/tests/mysql.test.ts: add table with enum value containing comma. The test asserts that mysqlEnum('enum', ['a,b', 'c']) generates type "enum('a,b','c')" in the snapshot. The test fails on the previous raw comma split (would produce enum('','','c')) and passes on the new quoted-string parsing.

Closes #5957.

…ulation race

The cache invalidation in PgPreparedQuery.queryWithCache was firing
concurrently with the DB write via Promise.all, contradicting the
in-code comment that said the DB write should resolve first.

When onMutate (a single Redis Lua script call) completed before the
DB write committed, a concurrent SELECT could read the pre-mutation
row and repopulate the cache via cache.put(), serving stale data
until TTL expiry. Repro: write-heavy workload with cache ex > DB RTT.

Change Promise.all([query(), onMutate]) to sequential await. The DB
write now commits before any cache keys are cleared, closing the race.
Same fix applied to mysql-core, sqlite-core, gel-core, singlestore-core
which shared the identical pattern.

Regression test added in pg-common-cache.ts that fails on the old
ordering (query:end > onMutate) and passes on the new (query:end < onMutate).

Closes drizzle-team#5828
The MySQL serializer's handleEnumType helper reparses the generated
enum('a,b','c') SQL string by splitting on raw commas. That collapses
'a,b' into two pieces 'a' and 'b', corrupting the snapshot type to
enum('','','c') when an enum value contains a comma.

Parse the value list as quoted SQL string literals instead. The new
matchAll pattern matches 'value' segments and tolerates escaped '' for
embedded single quotes (consistent with the existing
escapeSingleQuotes round-trip).

Closes drizzle-team#5957.
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