Skip to content

fix(integrations): relation reads no longer round bigint and numeric array elements - #369

Merged
allisonmahmood merged 1 commit into
mainfrom
fix/340-array-elements
Sep 24, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
fix/340-array-elements

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Stacked on #368 (branch fix/341-bfcache).

Fixes #340. Postgres relation reads (list, get, getMany) rounded bigint[] and numeric[] elements, so two distinct external ids like 9007199254740992 and 9007199254740993 came back equal. query on the same columns already returned them exactly, as strings.

The relation mapping projected every array through to_jsonb, which turns elements into JSON numbers. Arrays whose element is int8 or numeric now go through text[] first, so elements arrive as strings, matching the scalar and query paths. Nulls and dimensions are kept, domain arrays and arrays of int8/numeric domains are covered, and older snapshots without element metadata fall back to the builtin array name. Other arrays (such as integer[]) still return numbers. The postgres skill and docs/product.md now say array elements of int8/numeric are strings.

Tests:

  • New parity case discovers a table with bigint[], numeric[] (with a null), an int8-domain array, a domain over bigint[], a 2-D bigint[] and an integer[] control, then checks list/get/getMany against query on both native Postgres and the PGlite dev fixture. It failed on the unmodified code with the ticket's exact rounding, on each surface separately.
  • Mapping unit test covers which arrays get the text projection, with and without element metadata.
  • pnpm typecheck and pnpm lint pass. The integrations suite passes. The full pnpm test had 4 timeouts under machine load (Operations, Runtime, PgliteCompanyDatabases); those files pass when run alone.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).

@github-actions github-actions Bot added area:server Touches the server area area:docs Touches the docs area area:integrations Company connections and integration implementations size:m 100-500 changed lines labels Sep 23, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed 18497dba75456caa7abe14e6fe73e1478627250f against origin/fix/341-bfcache at af60cd077031aa985dedf6c061aa040a3986843b, using issue #340 as the spec. One pass, no subagents, merge-blocking findings only.

Standards

No merge-blocking method or YAGNI findings. The fix stays in the existing shared projection mapping rather than adding another decoder. The test helpers extract setup now used by both parity cases. The fallback for absent element metadata matches the existing snapshot schema and native-type handling, rather than adding speculative compatibility.

Spec

No merge-blocking intent findings. The change preserves exact int8/numeric array elements across list, get and getMany, retains null elements and nested dimensions, handles supported domain arrays, and leaves unrelated arrays on their existing projection. Domain support is explicitly required by #340, not extra scope.

Checked the shared native/dev consumers, generated client typing, product documentation and distributed Postgres skill. Arrays remain unknown; no new routes, CLI commands, migrations or UI changes are introduced.

Verification

Ran pnpm exec vitest run packages/integrations/src/postgres/Mapping.test.ts packages/integrations/src/postgres/Parity.test.ts: 2 files passed, 9 tests passed. The parity regression exercises real Operations handlers against isolated native Postgres and PGlite, including all three relation reads and the query control. No live services were used. Full-suite, lint and typecheck runs were not repeated.

Summary: Standards 0 blockers, none to rank; Spec 0 blockers, none to rank.

…nts exact

Relation reads projected every array column through to_jsonb, so int8 and
numeric elements became JSON numbers and were rounded, merging distinct
bigint ids. The query path already returned them as exact strings.

int8/numeric arrays (including domain arrays and element domains) now
project through text[] before to_jsonb, keeping nulls and dimensions.
Other arrays are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 44fd62b into main Sep 24, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the fix/340-array-elements branch September 24, 2026 15:28
allisonmahmood added a commit that referenced this pull request Sep 24, 2026
…aracter and timestamp modifiers (#370)

Local Postgres fixtures dropped the source's type modifiers. A `numeric(8,2)` column became plain `numeric` under `.patchy/dev`, so inserting 9.995 read back as `"9.995"` locally but `"10.00"` from the source. `timestamp(0)` kept fractions, `character(4)` lost its padding, and `varchar(4)` accepted values the source refuses. Closes #336.

Stacked on #369 (branch fix/340-array-elements).

Discovery now reads each column's `atttypmod`, decodes it and stores the result as structured integers on the snapshot's column type. `numeric(8,2)` becomes `modifiers: [8, 2]`; for arrays the modifiers apply to the element. Fixture DDL and the fixture header render range-checked modifiers for numeric, varchar, bpchar, timestamp and timestamptz. For example, `"pg_catalog"."numeric"(8,2)` or `"pg_catalog"."timestamptz"(3)[]`. The source's formatted type string is still never executed. A modifier that fails validation excludes the column as `unsupported_type`. Domains still resolve to their base type without their own modifiers, and the schema-drift check still compares types without modifiers. Snapshots discovered before this change carry no modifiers until they are rediscovered.

The snapshot schema change is in `docs/API.md`. `docs/product.md` and the `patchy-postgres` project skill now describe the new fixture types.

Tests:
- New `Parity.test.ts` case runs the same reads natively and against the dev fixture over `numeric(8,2)`, `numeric(4)`, `timestamp(0)`, `timestamptz(3)`, `character(4)`, `varchar(4)` and `numeric(8,2)[]`. It failed on the base branch with the values the issue reports and passes now. It also checks that an over-length `varchar(4)` fixture row is refused locally with SQLSTATE 22001.
- New `Mapping.test.ts` case covers decoding (including a negative numeric scale), rendering, rejected modifiers and the unchanged drift check.
- `pnpm typecheck` and `pnpm lint` pass. On a loaded machine, `pnpm test` had 959 passed and 2 failed, both 5-second timeouts (`Operations.test.ts`, `Runtime.test.ts`). Re-run alone, both files pass.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Touches the docs area area:integrations Company connections and integration implementations area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

integrations: relation reads silently round bigint and numeric array elements

1 participant