[Mysql-kit] Fix introspection dropping a zero default on numeric columns#5997
Open
Otto-Deviant1904 wants to merge 1 commit into
Open
[Mysql-kit] Fix introspection dropping a zero default on numeric columns#5997Otto-Deviant1904 wants to merge 1 commit into
Otto-Deviant1904 wants to merge 1 commit into
Conversation
introspect-mysql.ts appends .default(...) based on a truthy check of the parsed default value. int and tinyint already guard this correctly with typeof defaultValue !== 'undefined', but smallint, mediumint, bigint, boolean, double, float, and real still used the truthy check, so a legitimate default of 0 (or false) was silently dropped during introspection. Applied the same typeof check already used by int and tinyint to the remaining affected types. Fixes drizzle-team#5911
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 #5911.
introspect-mysql.ts'scolumn()function decides whether to append.default(...)to a generated column definition using a plain truthy check on the parsed default value:defaultValue ? '.default(...)' : ''.That breaks for a legitimate default of
0(numeric types) orfalse(boolean), since both are falsy in JS.intandtinyintalready guard against this correctly withtypeof defaultValue !== 'undefined', butsmallint,mediumint,bigint,boolean,double,float, andrealstill used the truthy check, so aNOT NULL DEFAULT 0column on any of those types silently loses its.default()during introspection — matching the report exactly (a MySQLFLOAT NOT NULL DEFAULT 1.5column round-trips fine, but the same column withDEFAULT 0doesn't).Fixed by applying the same
typeof defaultValue !== 'undefined'checkint/tinyintalready use, to the remaining affected types.Verified against a real
mysql:8.0container:float().notNull().default(0)introspects asfloat().notNull()— default silently dropped.float().default(0).notNull().Added two regression tests to
tests/introspect/mysql.test.ts: one matching the reported float case, one covering the other affected types (smallint,mediumint,bigint,double,real) with a zero default. Ran the fullintrospect/mysql.test.tssuite — all 12 pass.Left
booleanout of the regression test even though I fixed that code path too — MySQL reportsBOOLEANcolumns astinyint(1)ininformation_schema, notboolean, so that branch turned out to be unreachable via real introspection and hits an unrelated, pre-existing bug in the generated file's import list when exercised directly. Didn't want to fix an unrelated issue in this PR, but happy to file it separately if useful.