Keep generatedAlwaysAsIdentity columns in select schema types (typebox/valibot/arktype)#5888
Open
MahinAnowar wants to merge 1 commit into
Open
Conversation
createSelectSchema in drizzle-typebox, drizzle-valibot and drizzle-arktype dropped columns defined with generatedAlwaysAsIdentity() from the generated type, even though the runtime select schema keeps them — the type/runtime mismatch reported in drizzle-team#4724. BuildSchema's key remapping excluded generated-always columns for every schema type. drizzle-zod already guards this with `TType extends 'select'`; apply the same guard to typebox, valibot and arktype so generated columns are kept for select and still omitted for insert/update. Extend each package's "table - select" type test with a generatedAlwaysAsIdentity() column, mirroring the existing drizzle-zod test.
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.
Closes #4724.
createSelectSchemain drizzle-typebox, drizzle-valibot and drizzle-arktype drops columns defined withgeneratedAlwaysAsIdentity()(and anygenerated: 'always'column) from the generated type, even though the runtime select schema keeps them. So selecting from a table with an identity primary key gives a schema whose runtime shape and static type disagree.Cause
The runtime is correct —
createSelectSchemausesselectConditionswherenever: () => false, so generated-always columns are kept on select (only insert/update omit them):But the type-level
BuildSchemaexcludes them for every schema type:So the column exists at runtime but is missing from the type — the mismatch reported in the issue.
Fix
drizzle-zodalready handles this correctly by guarding the exclusion withTType extends 'select':This applies that exact guard to the typebox, valibot and arktype packages (the issue notes all three share the defect, and they're kept in lockstep with zod). Generated-always columns are now kept for
selectand still omitted forinsert/update, matching the runtime in every package.Tests
Extends each package's existing
table - selecttype test with agenerated: integer().generatedAlwaysAsIdentity()column and asserts it appears in the resulting schema — mirroring thetable - selecttest that already exists indrizzle-zod. Verified each test fails on the current code (Property 'generated' is missing/Type 'false' does not satisfy the constraint 'true'from theExpect<Equal<…>>assertion) and passes with this change. The full runtime suites (vitest run, 62 tests per package) stay green anddprintformatting is clean.