Skip to content

fix(database): keep bigint ids exact inside relational json selections - #1792

Merged
realcodesiman merged 2 commits into
mainfrom
fix/bigint-as-string-json-precision
Nov 26, 2026
Merged

realcodesiman merged 2 commits into
mainfrom
fix/bigint-as-string-json-precision

Conversation

@realcodesiman

@realcodesiman realcodesiman commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Bigint id precision (flow draft save bug)

  • bigintAsString was a drizzle customType. Since drizzle-orm 1.0.0-rc.2 a custom column gets no JSON cast unless it declares a codec, so relational queries loaded nested with: relations through row_to_json and 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: bigintAsString is now the built-in bigint({ mode: "string" }), which drizzle casts to ::text / ::text[] inside JSON selections. No schema or migration change (same bigint column type).

  • Side effect — stricter generated zod schemas: drizzle's zod integration mapped the old custom column to z.any(); a bigint string column maps to an int64 digit-string schema. Every createSelectSchema/createInsertSchema field built from a bigintAsString column (and not already overridden with zodBigintAsString()) now rejects non-digit strings and numbers, and shows as string in 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 / listAll with includes=integration eager-loaded the raw integrationSmtp row (with auth, the SMTP/IMAP passwords). Through oRPC the output schema stripped auth but requires provider / inboundWebhookIssued, so any workspace with an SMTP inbox got a 500 (output validation); direct server callers (link builders, capabilities) received the raw row.
  • Rows now go through projectIntegrationSmtp (typed: the result's integrationSmtp is IntegrationSmtpResource). toResource and the projection live in integration-smtp/resource.ts, exported from the integration-smtp barrel, 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 SQL
  • packages/database/__tests__/integration/bigint-as-string-json.test.ts — round trip with production-size ids against a real DB (run with pnpm --filter @chatbotx.io/database test:db)
  • projectIntegrationSmtp unit tests (packages/business/__tests__/integration-smtp-service.test.ts)
  • full local pnpm test for builder, worker, business, database and the other workspaces
  • ultracite check on changed files
  • pre-commit turbo check-types --filter=...[HEAD] (26 workspaces, incl. builder)
  • Save a flow draft on staging and confirm the draft version updates
  • List inboxes with includes=integration for an SMTP inbox and confirm no auth in the response

🤖 Generated with Claude Code

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.
@github-actions github-actions Bot added the bug Something isn't working as expected label Nov 26, 2026
…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.
@realcodesiman
realcodesiman merged commit d3cc86a into main Nov 26, 2026
14 checks passed
@realcodesiman
realcodesiman deleted the fix/bigint-as-string-json-precision branch November 26, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant