fix(orm): consistent number-word boundary in toSnakeCase/toCamelCase - #6048
Open
g1mn wants to merge 1 commit into
Open
fix(orm): consistent number-word boundary in toSnakeCase/toCamelCase#6048g1mn wants to merge 1 commit into
g1mn wants to merge 1 commit into
Conversation
The abbreviation alternative in the shared tokenizer regex, `[A-Z]+(?![a-z])`, stopped matching before a trailing digit, splitting it into its own word (e.g. `userID2` -> `user_id_2`). The lowercase and mixed-case alternatives already absorbed trailing digits, so number attachment depended inconsistently on the casing of the preceding letter. Change the alternative to `[A-Z]+\d*(?![a-z])` so digits attach to an abbreviation the same way they do elsewhere, and extract the regex into a shared WORD_BOUNDARY constant used by both toSnakeCase and toCamelCase. Closes drizzle-team#6037
g1mn
force-pushed
the
fix/snakecase-number-word-boundary
branch
from
July 22, 2026 16:12
dc91062 to
8eb6216
Compare
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.
Summary
toSnakeCase/toCamelCaseshare a tokenizer regex whose abbreviation alternative,[A-Z]+(?![a-z]), stops matching before a trailing digit and leaves it as a separate word — unlike the other two alternatives, which already absorb trailing digits into the word. So whether a digit stays attached to the preceding word depended inconsistently on that word's casing.testStuffM3test_stuff_m_3test_stuff_m3totalUsageM3PerAtotal_usage_m_3_per_atotal_usage_m3_per_aparentEN1Proofparent_en_1_proofparent_en1_proofuserID2user_id_2user_id2foo2Barfoo2_barfoo2_bar(unchanged)parentEn1Proofparent_en1_proofparent_en1_proof(unchanged)drizzleORMdrizzle_ormdrizzle_orm(unchanged)drizzleORMAndKitdrizzle_orm_and_kitdrizzle_orm_and_kit(unchanged)Fix:
[A-Z]+(?![a-z])→[A-Z]+\d*(?![a-z]), and extracted the shared regex into a singleWORD_BOUNDARYconstant used by bothtoSnakeCaseandtoCamelCase(previously duplicated verbatim in each), so any future change stays in sync between the two.Closes #6037
Test plan
tests/casing/casing.test.tscovering every row in the table above plus symmetrictoCamelCaseround-trips.pnpm vitest run tests/casing— 92/92 passing (all dialect casing suites: mysql/pg/sqlite × snake/camel, plus casing.test.ts).drizzleORMAndKit— stays unaffected (no digit followsORM, so\d*matches zero digits).drizzle-kit's introspection code (also importstoCamelCase/toSnakeCase) for any snapshot/golden output depending on the old digit-splitting behavior — found none.