Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughRenderer cast emission is now driven by an assembled CodecLookup supplied by adapter/stack wiring. At lower time the renderer consults each codec’s Postgres Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Stack as Execution Stack
participant Ext as Extension Pack(s)
participant Adapter as Postgres Adapter
participant Renderer as SQL Renderer
participant Lookup as CodecLookup
Stack->>Ext: collect extension descriptors & codecInstances
Stack->>Adapter: create adapter with assembled CodecLookup
Adapter->>Renderer: renderLoweredSql(ast, contract, codecLookup)
Renderer->>Lookup: lookup(codecId) for each ParamRef
alt codec found and nativeType not inferrable
Renderer->>Renderer: emit `$N::<nativeType>`
else codec found and nativeType inferrable or absent
Renderer->>Renderer: emit `$N`
else codec missing
Renderer->>Adapter: throw error (missing codecId)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/middleware-telemetry
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/3-targets/6-adapters/postgres/test/helpers/composed-adapter.ts (1)
59-59: Prefer descriptor factory over direct class construction for control helper parity.Using
postgresAdapterControlDescriptor.create(stack)keeps this test helper resilient if descriptor construction logic evolves.Suggested refactor
- return new PostgresControlAdapter(stack.codecLookup); + return postgresAdapterControlDescriptor.create(stack);As per coding guidelines, “Export interfaces and factory functions for public APIs; keep concrete classes as private implementation details.”
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/3-targets/6-adapters/postgres/test/helpers/composed-adapter.ts` at line 59, Replace the direct construction of PostgresControlAdapter with the descriptor factory to follow the public API pattern: instead of returning new PostgresControlAdapter(stack.codecLookup) use postgresAdapterControlDescriptor.create(stack) so the helper uses the descriptor factory; update references in this helper to rely on postgresAdapterControlDescriptor.create(stack) and remove direct usage of the PostgresControlAdapter constructor.packages/3-targets/6-adapters/postgres/test/sql-renderer.cast-policy.test.ts (1)
163-195: Consider reusing the composed-adapter test helper to reduce setup duplication.Both stack-derived tests inline near-identical runtime target/adapter composition. Reusing
test/helpers/composed-adapter.tswould keep wiring updates in one place.Also applies to: 211-227
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/3-targets/6-adapters/postgres/test/sql-renderer.cast-policy.test.ts` around lines 163 - 195, Replace the inline runtime/extension composition (the local target, geographyExtension, and the call to postgresRuntimeAdapterDescriptor.create({...}) that returns adapter) with the shared composed-adapter test helper: import and call the helper to produce the composed adapter (and any target/extension pack) instead of manually constructing target and geographyExtension; remove the duplicated definitions around the call sites (the block creating target, geographyExtension, and the call to postgresRuntimeAdapterDescriptor.create) and reuse the helper in both places referenced (lines near the current adapter creation and the other similar block around 211-227) so wiring is centralized via the composed-adapter helper API.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/architecture` docs/adrs/ADR 205 - SQL cast emission is adapter
policy.md:
- Around line 17-20: The fenced code block containing the error message "ERROR:
operator does not exist: vector <-> text" should include a language tag to
satisfy markdown lint (MD040); update the fence that surrounds that exact
error-output block to use ```text instead of just ``` so the block becomes a
labeled text code block. Ensure you modify the fenced block that contains the
string "ERROR: operator does not exist: vector <-> text" (the error-output
block) to include the language tag.
---
Nitpick comments:
In `@packages/3-targets/6-adapters/postgres/test/helpers/composed-adapter.ts`:
- Line 59: Replace the direct construction of PostgresControlAdapter with the
descriptor factory to follow the public API pattern: instead of returning new
PostgresControlAdapter(stack.codecLookup) use
postgresAdapterControlDescriptor.create(stack) so the helper uses the descriptor
factory; update references in this helper to rely on
postgresAdapterControlDescriptor.create(stack) and remove direct usage of the
PostgresControlAdapter constructor.
In
`@packages/3-targets/6-adapters/postgres/test/sql-renderer.cast-policy.test.ts`:
- Around line 163-195: Replace the inline runtime/extension composition (the
local target, geographyExtension, and the call to
postgresRuntimeAdapterDescriptor.create({...}) that returns adapter) with the
shared composed-adapter test helper: import and call the helper to produce the
composed adapter (and any target/extension pack) instead of manually
constructing target and geographyExtension; remove the duplicated definitions
around the call sites (the block creating target, geographyExtension, and the
call to postgresRuntimeAdapterDescriptor.create) and reuse the helper in both
places referenced (lines near the current adapter creation and the other similar
block around 211-227) so wiring is centralized via the composed-adapter helper
API.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 66d44003-569f-42df-8d66-39b8529eca38
📒 Files selected for processing (15)
docs/architecture docs/adrs/ADR 205 - SQL cast emission is adapter policy.mdpackages/3-extensions/pgvector/src/exports/runtime.tspackages/3-targets/6-adapters/postgres/src/core/adapter.tspackages/3-targets/6-adapters/postgres/src/core/codec-lookup.tspackages/3-targets/6-adapters/postgres/src/core/control-adapter.tspackages/3-targets/6-adapters/postgres/src/core/sql-renderer.tspackages/3-targets/6-adapters/postgres/src/core/types.tspackages/3-targets/6-adapters/postgres/src/exports/control.tspackages/3-targets/6-adapters/postgres/src/exports/runtime.tspackages/3-targets/6-adapters/postgres/test/control-adapter-lower-parity.test.tspackages/3-targets/6-adapters/postgres/test/descriptor-parity.test.tspackages/3-targets/6-adapters/postgres/test/helpers/composed-adapter.tspackages/3-targets/6-adapters/postgres/test/operation-lowering.test.tspackages/3-targets/6-adapters/postgres/test/rich-adapter.test.tspackages/3-targets/6-adapters/postgres/test/sql-renderer.cast-policy.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts`:
- Around line 77-79: The error path currently throws when adapter is missing but
leaves the created pg Pool open; before throwing in the branch that checks `if
(!adapter)` ensure the pool is cleanly closed (call and await `pool.end()` or
`pgPool.end()` as appropriate) and handle the case where `pool` may be
undefined; alternatively wrap the setup in try/finally and call `await
pool.end()` in the finally block so the `pool` created/pinged earlier is always
ended before the function (or the `if (!adapter)` branch) throws.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 52e5c77b-6a75-4738-a907-5772b58bb309
📒 Files selected for processing (1)
packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts
1c5d9c1 to
8035b0e
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts (1)
71-83:⚠️ Potential issue | 🟡 MinorClose the pool on setup failures.
At this point the
Poolhas already been created and pinged, so these new early throws can leak the connection if stack assembly is incomplete. Wrapping the whole post-new Pool(...)setup intry/catchandawait pool.end()before rethrowing would fix the adapter/driver branches and the rest of the init path in one place.Suggested fix
export async function createPgIntegrationRuntime( connectionString: string, ): Promise<PgIntegrationRuntime> { const pool = new Pool({ connectionString }); - await pool.query('select 1'); - - const contract = getTestContract(); - - const stack = createSqlExecutionStack({ - target: postgresTarget, - adapter: postgresAdapter, - driver: postgresDriver, - extensionPacks: [pgvectorRuntime], - }); - - const context = createExecutionContext<TestContract>({ contract, stack }); - const stackInstance = instantiateExecutionStack(stack); + try { + await pool.query('select 1'); + + const contract = getTestContract(); + + const stack = createSqlExecutionStack({ + target: postgresTarget, + adapter: postgresAdapter, + driver: postgresDriver, + extensionPacks: [pgvectorRuntime], + }); + + const context = createExecutionContext<TestContract>({ contract, stack }); + const stackInstance = instantiateExecutionStack(stack); // ... - return runtime; + return runtime; + } catch (error) { + await pool.end(); + throw error; + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts` around lines 71 - 83, The setup currently constructs a new Pool and then throws early if stackInstance.adapter or stackInstance.driver are missing, which can leak connections; wrap the code that runs after new Pool(...) (including accesses to stackInstance.adapter and stackInstance.driver and any subsequent init steps) in a try/catch, and in the catch call await pool.end() before rethrowing the original error so the pool is always closed on setup failure; reference the Pool construction, stackInstance.adapter and stackInstance.driver checks, and pool.end() when making this change.
🧹 Nitpick comments (1)
docs/architecture docs/adrs/ADR 205 - SQL cast emission is adapter policy.md (1)
62-110: Trim the implementation mechanics out of the ADR.The exact allow-list and pseudo-code are likely to drift faster than the architectural decision itself. I’d keep this document at the policy/constraint level and move the concrete mechanics to subsystem docs or inline code comments.
Based on learnings, "ADRs in prisma/prisma-next should document architectural design decisions and the key constraints/assumptions only. Do not include implementation algorithms, emitter derivation logic, or step-by-step derivation/migration rules."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/architecture` docs/adrs/ADR 205 - SQL cast emission is adapter policy.md around lines 62 - 110, The ADR includes detailed implementation mechanics (POSTGRES_INFERRABLE_NATIVE_TYPES set, renderTypedParam pseudo-code, and the pgVectorCodec example) that should be removed from the decision record; instead, trim the ADR to state the policy ("SQL cast emission is an adapter policy"), key constraints (which kinds of types are inferrable vs. must be cast, rationale about operator overloads like json/jsonb), and assumptions, and move the concrete allow-list, exact spellings, and the renderTypedParam algorithm into a subsystem implementation doc or inline code comments where POSTGRES_INFERRABLE_NATIVE_TYPES and renderTypedParam live; keep the pgVectorCodec example minimal or remove it from the ADR and place a fuller example in the implementation docs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/3-extensions/pgvector/src/exports/runtime.ts`:
- Around line 47-52: The comment describing why we mirror
pgvectorPackMeta.types.codecTypes.codecInstances is outdated: a missing runtime
lookup now causes renderTypedParam() to throw rather than silently drop
::vector. Update the comment to state that we mirror
pgvectorPackMeta.types.codecTypes.codecInstances so that extractCodecLookup
(which reads descriptor.types?.codecTypes?.codecInstances) exposes the
pg/vector@1 codec to runtime-plane assemblers and prevents renderTypedParam()
from throwing on a lookup miss, rather than saying the cast would “silently
disappear.”
---
Duplicate comments:
In `@packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts`:
- Around line 71-83: The setup currently constructs a new Pool and then throws
early if stackInstance.adapter or stackInstance.driver are missing, which can
leak connections; wrap the code that runs after new Pool(...) (including
accesses to stackInstance.adapter and stackInstance.driver and any subsequent
init steps) in a try/catch, and in the catch call await pool.end() before
rethrowing the original error so the pool is always closed on setup failure;
reference the Pool construction, stackInstance.adapter and stackInstance.driver
checks, and pool.end() when making this change.
---
Nitpick comments:
In `@docs/architecture` docs/adrs/ADR 205 - SQL cast emission is adapter
policy.md:
- Around line 62-110: The ADR includes detailed implementation mechanics
(POSTGRES_INFERRABLE_NATIVE_TYPES set, renderTypedParam pseudo-code, and the
pgVectorCodec example) that should be removed from the decision record; instead,
trim the ADR to state the policy ("SQL cast emission is an adapter policy"), key
constraints (which kinds of types are inferrable vs. must be cast, rationale
about operator overloads like json/jsonb), and assumptions, and move the
concrete allow-list, exact spellings, and the renderTypedParam algorithm into a
subsystem implementation doc or inline code comments where
POSTGRES_INFERRABLE_NATIVE_TYPES and renderTypedParam live; keep the
pgVectorCodec example minimal or remove it from the ADR and place a fuller
example in the implementation docs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 36bf3ea3-d95f-4284-9223-192216652d01
📒 Files selected for processing (16)
docs/architecture docs/adrs/ADR 205 - SQL cast emission is adapter policy.mdpackages/3-extensions/pgvector/src/exports/runtime.tspackages/3-extensions/sql-orm-client/test/integration/runtime-helpers.tspackages/3-targets/6-adapters/postgres/src/core/adapter.tspackages/3-targets/6-adapters/postgres/src/core/codec-lookup.tspackages/3-targets/6-adapters/postgres/src/core/control-adapter.tspackages/3-targets/6-adapters/postgres/src/core/sql-renderer.tspackages/3-targets/6-adapters/postgres/src/core/types.tspackages/3-targets/6-adapters/postgres/src/exports/control.tspackages/3-targets/6-adapters/postgres/src/exports/runtime.tspackages/3-targets/6-adapters/postgres/test/control-adapter-lower-parity.test.tspackages/3-targets/6-adapters/postgres/test/descriptor-parity.test.tspackages/3-targets/6-adapters/postgres/test/helpers/composed-adapter.tspackages/3-targets/6-adapters/postgres/test/operation-lowering.test.tspackages/3-targets/6-adapters/postgres/test/rich-adapter.test.tspackages/3-targets/6-adapters/postgres/test/sql-renderer.cast-policy.test.ts
🚧 Files skipped from review as they are similar to previous changes (8)
- packages/3-targets/6-adapters/postgres/src/core/types.ts
- packages/3-targets/6-adapters/postgres/src/core/codec-lookup.ts
- packages/3-targets/6-adapters/postgres/src/exports/runtime.ts
- packages/3-targets/6-adapters/postgres/test/operation-lowering.test.ts
- packages/3-targets/6-adapters/postgres/test/helpers/composed-adapter.ts
- packages/3-targets/6-adapters/postgres/test/rich-adapter.test.ts
- packages/3-targets/6-adapters/postgres/test/sql-renderer.cast-policy.test.ts
- packages/3-targets/6-adapters/postgres/src/core/adapter.ts
…hrows
Wrap stack/runtime construction in `createPgIntegrationRuntime` in a
try/catch that ends the pool on any error between pool creation and a
working runtime. Without this, an early throw (missing adapter/driver
descriptor, failed `pool.query("select 1")`, failed `driver.connect`,
etc.) leaves the pool open until the test process exits, leaking
connections to PG. CodeRabbit flagged this on PR #397.
Co-authored-by: Will Madden <[email protected]>
… in cast-policy tests Two CodeRabbit follow-ups on PR #397: - `test/helpers/composed-adapter.ts`: route the control-side composition through `postgresAdapterControlDescriptor.create(stack)` instead of `new PostgresControlAdapter(stack.codecLookup)`. Matches the codebase's "factories not classes" coding convention and uses the same factory `exports/control.ts` runs in production. Drops the now-unused import of `PostgresControlAdapter`. - `test/sql-renderer.cast-policy.test.ts`: factor the inline runtime stack composition in the geography-extension test and the pgvector smoke test through the existing `createComposedPostgresAdapter` helper. Drops the duplicated stub `RuntimeTargetDescriptor` declaration and the inline `postgresRuntimeAdapterDescriptor.create({...})` blocks. Drops the now-unused imports. Co-authored-by: Will Madden <[email protected]>
… moves to the adapter Spec, plan, and ADR 205 (draft) for replacing the hardcoded codec-ID switch in `sql-renderer.ts` with adapter-level cast policy driven by each codec's existing `nativeType` metadata. ADR 205 records the descriptive-vs-policy seam: codecs declare what they are, the adapter decides when to emit a `::T` cast via an inferrable-types vocabulary. Closes the layering inversion where the core adapter named the pgvector extension's codec ID.
… renderer (M1) No behaviour change: getCodecParamCast still drives cast emission. The renderer now receives a CodecLookup from each adapter so a follow-up can read codec metadata at lower-time without further plumbing. - PostgresAdapterOptions gains an optional readonly codecLookup; the impl defaults to a postgres-builtins-only lookup via createPostgresBuiltinCodecLookup. - PostgresControlAdapter takes an optional codecLookup ctor arg with the same default. - renderLoweredSql now requires a CodecLookup; threaded through the ParamIndexMap carrier so helper signatures stay stable. - Control descriptor passes stack.codecLookup; runtime descriptor derives an equivalent lookup via extractCodecLookup over stack components, since the runtime ExecutionStack does not (yet) carry codecLookup directly. M1 of TML-2310 / projects/sql-cast-policy. Co-authored-by: Will Madden <[email protected]>
…g fix Surfaced during M1 R1 review: pgvectorRuntimeDescriptor does not contribute types.codecTypes.codecInstances, so the runtime-plane lookup derived via extractCodecLookup is missing pg/vector@1. M1 stays behaviour-preserving (getCodecParamCast still drives emission), but M2 must address this before flipping the renderer to the lookup or vector casts will silently disappear at runtime. Also pin the inferrable-set spelling to actual on-disk meta.db.sql.postgres.nativeType values (format_type-style: integer, boolean, timestamp with time zone, etc.), not the ADRs udt_name shorthand. Co-authored-by: Will Madden <[email protected]>
…r types M2 pre-flip wiring fix for projects/sql-cast-policy. The Postgres adapter runtime-plane derives its codec lookup from `extractCodecLookup` over the target / adapter / extension descriptors, which inspects `types.codecTypes.codecInstances`. The pgvector control-side meta (`pgvectorPackMeta`) already exposes that list; the runtime descriptor was missing it, so the runtime lookup silently lacked `pg/vector@1`. Once M2 flips the renderer to lookup-driven cast policy, this would have caused `$N::vector` to disappear at runtime even though the test contracts still declare `nativeType: vector` on vector columns. Add the same field to the runtime descriptor so both planes see the same codec set. Co-authored-by: Will Madden <[email protected]>
…ata (M2) Replaces the hardcoded `getCodecParamCast` switch (`pg/vector@1` / `pg/json@1` / `pg/jsonb@1`) with a lookup-driven cast policy keyed off each codec's `meta.db.sql.postgres.nativeType`. The renderer now consults the assembled-stack `CodecLookup` first and emits `$N::<nativeType>` only for codecs whose `nativeType` is outside `POSTGRES_INFERRABLE_NATIVE_TYPES` (numeric / boolean / string / temporal / bit-string scalars). `json`, `jsonb`, `vector`, and any extension-supplied or unknown type fall outside the set and continue to emit a cast. When the codec lookup misses entirely (e.g. `createPostgresAdapter()` without an extension pack composing a stack), the renderer falls back to a `codecId → nativeType` map derived from the contract's `storage.tables[*].columns`. Contracts are themselves stack-derived artifacts emitted by the contract emitter, so this remains consistent with adapter-policy-driven-by-stack-metadata while keeping byte-identical SQL for legacy bare-factory call sites that exercise extension codecs through their contract column metadata (the existing test suites in `adapter.test.ts`, `operation-lowering.test.ts`, `rich-adapter.test.ts`, `control-adapter-lower-parity.test.ts` continue to assert `::jsonb` / `::json` / `::vector` byte-for-byte). Deletes `VECTOR_CODEC_ID`, `getCodecParamCast`, and the now-unused `PG_JSON_CODEC_ID` / `PG_JSONB_CODEC_ID` imports from the renderer. Adds `test/sql-renderer.cast-policy.test.ts` covering: codec with non- inferrable `nativeType` → cast; codec with inferrable `nativeType` → no cast; codec with no `meta` → no cast; codec lookup miss with contract fallback; param ref without `codecId` → no cast; extension codec contributed via `stack.extensionPacks` → cast (covers AC5); pgvector installed via `stack.extensionPacks` → `$1::vector` (probe for the M2 wiring fix in `pgvectorRuntimeDescriptor`). Closes M2 of TML-2310 / projects/sql-cast-policy. Co-authored-by: Will Madden <[email protected]>
…nderer (M2 R2) Removes the contract-storage fallback added in M2 R1. A `ParamRef` that carries a `codecId` not present in the assembled `codecLookup` is a stack-configuration failure (almost always a missing extension pack in the runtime stack), not a fallback opportunity. The renderer now throws a clear error at lower-time naming the offending codecId so callers fix the configuration rather than silently emitting an uncast `$N` or guessing native types from contract storage. The `codecId === undefined` and "lookup hit but no `meta`" branches are unchanged: they still emit plain `$N` (the LiteralExpr-shaped param ref and pg/enum@1-style codec cases respectively, per ADR 205). Drops `buildContractNativeTypeMap`, `contractNativeTypes` from the `ParamIndexMap` carrier, and the corresponding parameter from `renderTypedParam`. Updates the cast-policy tests: the two former "lookup miss → fallback" assertions are replaced with explicit throw assertions naming the codecId. Co-authored-by: Will Madden <[email protected]>
…k-composed adapter Three test files exercised `pg/vector@1` ParamRefs through bare `createPostgresAdapter()` / `new PostgresControlAdapter()`. Under M2's new lookup-miss-throws contract, these would now throw because bare factories cannot see extension codecs (ADR 205 § "Adapters built without a stack"). Migrate each to compose a stack with the pgvector runtime / control descriptor: - test/operation-lowering.test.ts - test/rich-adapter.test.ts - test/control-adapter-lower-parity.test.ts Existing assertions on the lowered SQL are unchanged — still byte- identical `$N::vector` etc. Adds `test/helpers/composed-adapter.ts` with two small factories (`createComposedPostgresAdapter` / `createComposedPostgresControlAdapter`) to keep the runtime / control stack composition local to the test suite without growing a generic harness. The control variant uses the real `sql` family / postgres target / postgres adapter control descriptors so the assembled `codecLookup` matches what `exports/control.ts` produces in production. Co-authored-by: Will Madden <[email protected]>
…iptor alias The control-side test helper imported `@prisma-next/target-postgres/control` under the name postgresControlAdapterDescriptor, but that descriptor is the postgres *target* control descriptor, not the postgres *adapter* control descriptor (which is the next import). Rename to postgresTargetControlDescriptor to match its actual role and avoid the two-line collision with postgresAdapterControlDescriptor. Co-authored-by: Will Madden <[email protected]>
…n docs/ TML-2310 done: spec / plan / ADR draft migrated to docs/architecture docs/adrs/ADR 205 - SQL cast emission is adapter policy.md. The transient projects/ folder is no longer needed. Co-authored-by: Will Madden <[email protected]>
…ntime helper The pg integration helper composed pgvectorRuntime into the execution stack but used a separate bare createPostgresAdapter() to lower plans for assertion-side SQL capture. With the renderer now throwing on codec-lookup miss (per ADR 205), any vector ParamRef going through the bare adapter fails immediately at lower-time — exactly what failed in CI on extension-operations and codec-async integration tests. Use the adapter from the assembled execution stack (which carries pg/vector@1 via the pgvector pack) for both lowering and execution. Removes the now-unused createPostgresAdapter import. Co-authored-by: Will Madden <[email protected]>
Co-authored-by: Will Madden <[email protected]>
…hrows
Wrap stack/runtime construction in `createPgIntegrationRuntime` in a
try/catch that ends the pool on any error between pool creation and a
working runtime. Without this, an early throw (missing adapter/driver
descriptor, failed `pool.query("select 1")`, failed `driver.connect`,
etc.) leaves the pool open until the test process exits, leaking
connections to PG. CodeRabbit flagged this on PR #397.
Co-authored-by: Will Madden <[email protected]>
… in cast-policy tests Two CodeRabbit follow-ups on PR #397: - `test/helpers/composed-adapter.ts`: route the control-side composition through `postgresAdapterControlDescriptor.create(stack)` instead of `new PostgresControlAdapter(stack.codecLookup)`. Matches the codebase's "factories not classes" coding convention and uses the same factory `exports/control.ts` runs in production. Drops the now-unused import of `PostgresControlAdapter`. - `test/sql-renderer.cast-policy.test.ts`: factor the inline runtime stack composition in the geography-extension test and the pgvector smoke test through the existing `createComposedPostgresAdapter` helper. Drops the duplicated stub `RuntimeTargetDescriptor` declaration and the inline `postgresRuntimeAdapterDescriptor.create({...})` blocks. Drops the now-unused imports. Co-authored-by: Will Madden <[email protected]>
…n type After replacing `new PostgresControlAdapter(stack.codecLookup)` with `postgresAdapterControlDescriptor.create(stack)` (CodeRabbit factory-not-class nit), the helpers return type narrowed to the framework-level `ControlAdapterInstance<"sql","postgres">`, which does not expose `.lower`. Annotate the helper as `SqlControlAdapter<"postgres">` (which does) so call sites like `control-adapter-lower-parity.test.ts` continue to type-check. Co-authored-by: Will Madden <[email protected]>
9de8894 to
c95038c
Compare
…hrows
Wrap stack/runtime construction in `createPgIntegrationRuntime` in a
try/catch that ends the pool on any error between pool creation and a
working runtime. Without this, an early throw (missing adapter/driver
descriptor, failed `pool.query("select 1")`, failed `driver.connect`,
etc.) leaves the pool open until the test process exits, leaking
connections to PG. CodeRabbit flagged this on PR #397.
Co-authored-by: Will Madden <[email protected]>
… in cast-policy tests Two CodeRabbit follow-ups on PR #397: - `test/helpers/composed-adapter.ts`: route the control-side composition through `postgresAdapterControlDescriptor.create(stack)` instead of `new PostgresControlAdapter(stack.codecLookup)`. Matches the codebase's "factories not classes" coding convention and uses the same factory `exports/control.ts` runs in production. Drops the now-unused import of `PostgresControlAdapter`. - `test/sql-renderer.cast-policy.test.ts`: factor the inline runtime stack composition in the geography-extension test and the pgvector smoke test through the existing `createComposedPostgresAdapter` helper. Drops the duplicated stub `RuntimeTargetDescriptor` declaration and the inline `postgresRuntimeAdapterDescriptor.create({...})` blocks. Drops the now-unused imports. Co-authored-by: Will Madden <[email protected]>
…hrows
Wrap stack/runtime construction in `createPgIntegrationRuntime` in a
try/catch that ends the pool on any error between pool creation and a
working runtime. Without this, an early throw (missing adapter/driver
descriptor, failed `pool.query("select 1")`, failed `driver.connect`,
etc.) leaves the pool open until the test process exits, leaking
connections to PG. CodeRabbit flagged this on PR #397.
Co-authored-by: Will Madden <[email protected]>
… in cast-policy tests Two CodeRabbit follow-ups on PR #397: - `test/helpers/composed-adapter.ts`: route the control-side composition through `postgresAdapterControlDescriptor.create(stack)` instead of `new PostgresControlAdapter(stack.codecLookup)`. Matches the codebase's "factories not classes" coding convention and uses the same factory `exports/control.ts` runs in production. Drops the now-unused import of `PostgresControlAdapter`. - `test/sql-renderer.cast-policy.test.ts`: factor the inline runtime stack composition in the geography-extension test and the pgvector smoke test through the existing `createComposedPostgresAdapter` helper. Drops the duplicated stub `RuntimeTargetDescriptor` declaration and the inline `postgresRuntimeAdapterDescriptor.create({...})` blocks. Drops the now-unused imports. Co-authored-by: Will Madden <[email protected]>
Summary
Replace the hardcoded codec-ID switch in the Postgres SQL renderer (
getCodecParamCast) with adapter-level cast policy driven by each codec's existingmeta.db.sql.postgres.nativeType. Architectural rationale lives indocs/architecture docs/adrs/ADR 205 - SQL cast emission is adapter policy.md.What changed
meta.db.sql.postgres.nativeTypefor DDL emission and introspection. The renderer now reads that field; no new codec field.POSTGRES_INFERRABLE_NATIVE_TYPESset (numeric, boolean, string, temporal, bit-string Postgres builtins). The renderer emits$Nif the codec'snativeTypeis in the set,$N::<nativeType>otherwise.json/jsonbare intentionally outside the set (operator-overload ambiguity);vectorand other extension types fall through automatically.SqlControlAdapterDescriptor.create(stack)andSqlRuntimeAdapterDescriptor.create(stack)thread the assembled codec lookup into the renderer. The barecreatePostgresAdapter()factory defaults to a postgres-builtins-only lookup (extensions only flow through stack composition, by design).ParamRefcarrying acodecIdwhose codec is absent from the assembled lookup throws at lower-time with a message naming the offendingcodecIdand pointing at extension-pack registration. Strengthens the ADR's invariant: extension-codec misconfiguration surfaces immediately rather than as an opaque Postgres parser error later.pgvectorRuntimeDescriptornow exposestypes.codecTypes.codecInstances(mirroringpgvectorPackMetaon the control side) so the runtime-plane lookup picks uppg/vector@1.operation-lowering.test.ts,rich-adapter.test.ts,control-adapter-lower-parity.test.ts) now compose stacks via a newtest/helpers/composed-adapter.ts. Lowered SQL assertions stay byte-identical.Layering
@prisma-next/adapter-postgresdoes not import any extension package by name. Vector/extension codec metadata reaches the renderer only throughstack.codecLookup.pnpm lint:depsclean; no new framework→target imports.Validation gates
pnpm --filter @prisma-next/adapter-postgres test— 644/644pnpm --filter @prisma-next/adapter-postgres typecheck— cleanpnpm --filter @prisma-next/adapter-postgres lint— cleanpnpm --filter @prisma-next/extension-pgvector test— 31/31pnpm --filter @prisma-next/extension-pgvector typecheck— cleanpnpm --filter @prisma-next/extension-pgvector lint— cleanpnpm test:integration— 524/524 (pgvector / JSON / JSONB e2e SQL byte-identity preserved)pnpm lint:deps— no dependency violationsrg "VECTOR_CODEC_ID|getCodecParamCast" packages/3-targets/6-adapters/postgres/src/— zero matchesCommit graph
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests