fix(mysql): preserve buffers for binary and varbinary - #6174
Conversation
eeb5736 to
b786252
Compare
zubairz4far
left a comment
There was a problem hiding this comment.
The PR is ready for review. The upstream CodeQL and Release Router runs are currently gated as action_required with no jobs started, so a maintainer workflow approval is needed before those checks can execute. The regression/type coverage is included in the PR.
|
Added adapter-level regression coverage for the historical blocker: both mysql2 and the current |
Fixes #1188
/claim #1188
Summary
binaryandvarbinarycolumns asBufferinstead ofstring.Buffervalues returned by mysql2.Uint8Arrayvalues toBufferwithout changing bytes.Why
Bufferby default is viable nowThe original direct-
Bufferattempt in #425 was closed for one specific reason: mysql2 returnedBuffer, while the PlanetScale driver returned strings. That made one shared MySQL column type inconsistent across adapters at the time.Current
@planetscale/databaseno longer has that blocker:Uint8Arrayfor binary fields (charset === 63): https://github.com/planetscale/database-js/blob/main/src/cast.tsUint8Arraydirectly: https://github.com/planetscale/database-js/blob/main/src/sanitization.tsBufferis aUint8Array, so binary data can stay binary through both current mysql2 and PlanetScale paths. Drizzle normalizes a PlanetScaleUint8ArraytoBufferwithout a UTF-8 string round-trip.Historical review context
#425 was also explicitly asked to add runtime insert/select integration coverage for these columns. This PR now includes that exact evidence for both adapters, using non-UTF-8 bytes (
00 ff 80 31) so a lossy string conversion cannot pass unnoticed.The later direct-Buffer work in #1253 reached a maintainer comment that it “looks good to be merged” before stalling on signed commits and eventually being closed. The adapter behavior that made the older work difficult is what the current PlanetScale implementation has since changed.
Compatibility
Application/select/insert data is inferred as
Buffer, matching binary semantics. Existing schema code that uses string SQL defaults such asbinary(...).default('')remains accepted through a narrow builder override, so this fix does not require rewriting those default declarations.Verification
00 ff 80 31).Buffer, binary-adapterUint8Array, and legacy string values.binary/varbinaryselect and insert data infer asBufferwhile string defaults remain accepted.Upstream Actions are currently
action_requiredwith no jobs started, so the repository’s first-time-contributor workflow approval is still required before the integration/CI jobs can execute.