Repository navigation
fix(database): keep bigint ids exact inside relational json selections - #1792
Merged
Merged
Conversation
bigintAsString was a customType; since drizzle-orm 1.0.0-rc.2 a custom column gets no JSON cast without a codec, so nested with: relations loaded snowflake ids through row_to_json as JS numbers and rounded them above 2^53. Writes back by such an id (e.g. saving a flow draft) silently missed their row. Use the built-in bigint({ mode: "string" }) column instead.
Also project integrationSmtp rows through toResource in inbox list/listAll responses so includes=integration no longer returns auth (SMTP/IMAP passwords); toResource moves to integration-smtp/resource.ts to avoid an import cycle.
…n-smtp resource Inbox listing swapped eager-loaded integrationSmtp rows for their public projection through a private, loosely typed helper. Move it next to toResource as a typed projectIntegrationSmtp, export the resource module from the barrel, and use digit-string ids in the broadcasts resend test now that bigint ids are validated as int64.
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
Bigint id precision (flow draft save bug)
bigintAsStringwas a drizzlecustomType. Since drizzle-orm1.0.0-rc.2a custom column gets no JSON cast unless it declares a codec, so relational queries loaded nestedwith:relations throughrow_to_jsonand parsed snowflake ids as JS numbers — rounding every id above 2^53 (e.g.…495→…496).Code that writes back by such a nested id (e.g. updating a flow's draft version via
POST /space/:workspaceId/flows/:flowId) silently updated no row.Fix:
bigintAsStringis now the built-inbigint({ mode: "string" }), which drizzle casts to::text/::text[]inside JSON selections. No schema or migration change (samebigintcolumn type).Side effect — stricter generated zod schemas: drizzle's zod integration mapped the old custom column to
z.any(); abigintstring column maps to an int64 digit-string schema. EverycreateSelectSchema/createInsertSchemafield built from abigintAsStringcolumn (and not already overridden withzodBigintAsString()) now rejects non-digit strings and numbers, and shows asstringin the OpenAPI spec (and so in the CLI/MCP). Real ids are digit strings, so only test fixtures with fake ids ("flow-1") needed changing.SMTP inbox integration in inbox list responses
inbox.list/listAllwithincludes=integrationeager-loaded the rawintegrationSmtprow (withauth, the SMTP/IMAP passwords). Through oRPC the output schema strippedauthbut requiresprovider/inboundWebhookIssued, so any workspace with an SMTP inbox got a 500 (output validation); direct server callers (link builders, capabilities) received the raw row.projectIntegrationSmtp(typed: the result'sintegrationSmtpisIntegrationSmtpResource).toResourceand the projection live inintegration-smtp/resource.ts, exported from theintegration-smtpbarrel, to avoid an import cycle between the inbox and SMTP services.Test plan
packages/database/__tests__/bigint-as-string-json.test.ts— nested bigint and bigint[] columns are cast to text in relational SQLpackages/database/__tests__/integration/bigint-as-string-json.test.ts— round trip with production-size ids against a real DB (run withpnpm --filter @chatbotx.io/database test:db)projectIntegrationSmtpunit tests (packages/business/__tests__/integration-smtp-service.test.ts)pnpm testfor builder, worker, business, database and the other workspacesultracite checkon changed filesturbo check-types --filter=...[HEAD](26 workspaces, incl. builder)includes=integrationfor an SMTP inbox and confirm noauthin the response🤖 Generated with Claude Code