Skip to content

Give control drivers a per-family transport, off the generic interface (TML-2840)#738

Merged
wmadden merged 8 commits into
mainfrom
tml-2840-reshape-controldriverinstance-drop-the-sql-hardcoded
Jun 6, 2026
Merged

Give control drivers a per-family transport, off the generic interface (TML-2840)#738
wmadden merged 8 commits into
mainfrom
tml-2840-reshape-controldriverinstance-drop-the-sql-hardcoded

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

At a glance

The framework's target-agnostic control-driver interface used to hard-code SQL's transport. This PR takes it off:

// packages/1-framework/.../control/control-instances.ts
// before
interface ControlDriverInstance<TFamilyId, TTargetId> extends DriverInstance<TFamilyId, TTargetId> {
  query<Row>(sql: string, params?: readonly unknown[]): Promise<{ rows: Row[] }>;  // ← SQL-shaped
  close(): Promise<void>;
}
// after
interface ControlDriverInstance<TFamilyId, TTargetId> extends DriverInstance<TFamilyId, TTargetId> {
  close(): Promise<void>;   // transport now lives on each family's own driver interface
}

The decision

A control driver is an execution-plane driver plus a couple of control-plane tags, and its transport is family-specific. So the generic interface every family implements should carry no transport at all — just the tags and close(). Each family adds its own transport on its own interface.

Why the generic interface was wrong

query(sql, params) is SQL's control transport, and that part is fine. The problem is that it sat on the interface every family must implement. SQL was happy; Mongo was not. Mongo has no SQL to run, so its control driver implemented query() with a stub that just threw, and exposed a public .db handle as an escape hatch — so callers could reach Mongo's real transport, MongoDriver.execute(wireCommand), which lived on a separate interface the control driver didn't extend. The generic interface was forcing every non-SQL family to carry a method that makes no sense for it, and then leaking a side-channel to work around it.

What changes, family by family

GenericControlDriverInstance drops query; it's now tags + close(). The framework only threads the driver through (verify / sign / readMarker / readAllMarkers / readLedger / introspect) and never calls the transport, so nothing in the framework breaks.

SQLquery moves, verbatim, onto a new SqlControlDriverInstance<T extends string> extends ControlDriverInstance<'sql', T>, in @prisma-next/sql-contract/types so the SQL drivers, adapters, and family can all import it. PostgresControlDriver and SqliteControlDriver implement it; every .query call site narrows to it. No behaviour change.

Mongo — each plane gets one interface and one concretion, and the concretions live together in driver-mongo with the inheritance between them:

Execution plane Control plane
Interface (mongo-lowering) MongoDriver MongoControlDriverInstance extends ControlDriverInstance<'mongo','mongo'>, MongoDriver
Concretion (driver-mongo) MongoDriverImpl MongoControlDriver extends MongoDriverImpl

The production control driver — MongoControlDriver, the one the descriptor's create(url) builds — now subclasses MongoDriverImpl, so it inherits the real execute(wireCommand) and close() and just adds the control-plane tags + the db carve-out. No held driver instance, no constructing an execution driver from a raw Db. The throwing query() stub is gone. adapter-mongo defines no driver: its old in-package control-driver class is deleted, it depends only on the MongoControlDriverInstance interface, and its dependency on the concrete driver-mongo package is dropped entirely.

Casts → predicates — the two bare as casts that used to narrow the driver (extractDb, asMongoDriver) become type predicates (isMongoControlDriver in the adapter, isMongoTargetDriver in the family). Net production bare-cast count drops.

Scope: deliberately narrow

This PR only makes execute() available on the Mongo control driver. It does not rewrite the Mongo marker/ledger path to use it — those methods still go through extractDb(driver) + the existing Db-based helpers, and .db stays exposed (for marker/ledger + introspection). Routing marker/ledger through execute and removing the .db reach-around is TML-2825 (PR #719), which this PR unblocks.

One subtlety: why two predicates, not one

2-mongo-family (the mongo domain) may only import from the framework domain, so it cannot see MongoControlDriverInstance, which lives in the targets-domain adapter. The family seam therefore narrows only to ControlDriverInstance<'mongo','mongo'>; the transport-bearing predicate lives in the adapter, where execute() is actually called. pnpm lint:deps enforces this boundary — the split is the boundary, not an oversight.

Verification

  • pnpm build ✅ · pnpm typecheck ✅ (135/135) · pnpm lint:deps ✅ — framework-components gains no dependency on any lowering/exec-driver package (control-plane types don't leak into runtime bundles), and adapter-mongo no longer depends on the concrete driver-mongo package at all (it consumes only interfaces). The MongoControlDriverInstance interface lives in mongo-lowering with a type-only Db reference — mongodb is an optional peer there, not a runtime dependency.
  • Mongo path (the only real logic change) green via mongodb-memory-server: runner-integration 20/20, control-driver 5/5, runner-deps 2/2.
  • SQL control-adapter unit tests and the touched family.introspect integration test pass.
  • The Postgres-backed suites could not run in this worktree (the @prisma/dev server was unavailable — uniform connection errors across all Postgres tests, including ones this PR doesn't touch). This is a pure type-level transport re-home for SQL, so those failures are environmental, not behavioural — CI is the authoritative Postgres signal.

Alternatives considered

  • Leave query on the generic and just have Mongo additionally extend MongoDriver. Rejected — Mongo would still have to implement the throwing query() stub, so the wart survives.
  • Make the SQL control driver a full SqlQueryable (the rich runtime interface: execute / executePrepared / explain). Rejected — the control plane never needs prepared/explain/codec-lowered execute, and pulling SqlQueryable into control would drag runtime surface into control bundles and break tree-shaking. SQL's control transport stays a deliberately minimal query.
  • Collapse the control and runtime driver hierarchies into one. Rejected/deferred — it reaches into how drivers are constructed and injected across the CLI/migration flow, which is far larger; and tree-shaking wants the two interfaces separate anyway.

Refs: TML-2840. Related: TML-2825 (PR #719).

Summary by CodeRabbit

  • Refactor

    • Split control driver contracts into SQL-specific and Mongo-specific driver types for clearer, family-focused APIs.
    • Mongo driver internals refactored for improved inheritance and reuse; Mongo control driver no longer exposes a rejecting SQL-query method.
  • Style / Types

    • Replaced generic driver typings with family-specific types to improve type safety and clarity.
  • Tests

    • Updated tests and setups to use the new driver shapes and direct driver constructors.

@wmadden-electric wmadden-electric requested a review from a team as a code owner June 5, 2026 13:55
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 9297a506-0e60-4f61-b42e-706333758cbc

📥 Commits

Reviewing files that changed from the base of the PR and between 5b6b080 and 0b38cff.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (39)
  • packages/1-framework/1-core/framework-components/src/control/control-instances.ts
  • packages/2-mongo-family/6-transport/mongo-lowering/package.json
  • packages/2-mongo-family/6-transport/mongo-lowering/src/driver-types.ts
  • packages/2-mongo-family/6-transport/mongo-lowering/src/exports/index.ts
  • packages/2-mongo-family/9-family/src/core/control-instance.ts
  • packages/2-sql/1-core/contract/src/exports/types.ts
  • packages/2-sql/1-core/contract/src/types.ts
  • packages/2-sql/9-family/src/core/control-adapter.ts
  • packages/2-sql/9-family/src/core/control-instance.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner-integration.test.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner.polymorphism.integration.test.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner.schema-verify.integration.test.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner.validator-closed.integration.test.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner.validator-widen.integration.test.ts
  • packages/3-mongo-target/2-mongo-adapter/package.json
  • packages/3-mongo-target/2-mongo-adapter/src/core/mongo-control-driver.ts
  • packages/3-mongo-target/2-mongo-adapter/src/core/runner-deps.ts
  • packages/3-mongo-target/2-mongo-adapter/src/exports/control.ts
  • packages/3-mongo-target/2-mongo-adapter/test/runner-deps.test.ts
  • packages/3-mongo-target/3-mongo-driver/src/exports/control.ts
  • packages/3-mongo-target/3-mongo-driver/src/mongo-driver.ts
  • packages/3-mongo-target/3-mongo-driver/test/control-driver.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/postgres/src/core/enum-control-hooks.ts
  • packages/3-targets/6-adapters/postgres/src/core/marker-ledger.ts
  • packages/3-targets/6-adapters/postgres/test/control-adapter.defaults.test.ts
  • packages/3-targets/6-adapters/postgres/test/control-adapter.test.ts
  • packages/3-targets/6-adapters/postgres/test/enum-control-hooks.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/core/marker-ledger.ts
  • packages/3-targets/7-drivers/postgres/src/exports/control.ts
  • packages/3-targets/7-drivers/sqlite/src/core/control-driver.ts
  • test/integration/test/family.introspect.test.ts
  • test/integration/test/migration-ledger/ledger-operation-count-parity.test.ts
  • test/integration/test/mongo/aggregate-e2e.test.ts
  • test/integration/test/mongo/db-verify-sign.test.ts
💤 Files with no reviewable changes (3)
  • packages/1-framework/1-core/framework-components/src/control/control-instances.ts
  • packages/3-mongo-target/3-mongo-driver/test/control-driver.test.ts
  • packages/3-mongo-target/2-mongo-adapter/package.json
✅ Files skipped from review due to trivial changes (1)
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
🚧 Files skipped from review as they are similar to previous changes (30)
  • packages/2-mongo-family/6-transport/mongo-lowering/src/exports/index.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner.validator-widen.integration.test.ts
  • packages/3-targets/6-adapters/postgres/src/core/enum-control-hooks.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner.schema-verify.integration.test.ts
  • test/integration/test/mongo/db-verify-sign.test.ts
  • packages/2-sql/1-core/contract/src/exports/types.ts
  • packages/2-mongo-family/9-family/src/core/control-instance.ts
  • packages/3-targets/6-adapters/postgres/src/core/marker-ledger.ts
  • packages/3-mongo-target/2-mongo-adapter/test/runner-deps.test.ts
  • packages/3-mongo-target/3-mongo-driver/src/exports/control.ts
  • packages/2-mongo-family/6-transport/mongo-lowering/src/driver-types.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner-integration.test.ts
  • packages/2-sql/1-core/contract/src/types.ts
  • test/integration/test/family.introspect.test.ts
  • packages/3-targets/6-adapters/postgres/test/enum-control-hooks.basic.test.ts
  • test/integration/test/migration-ledger/ledger-operation-count-parity.test.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner.polymorphism.integration.test.ts
  • packages/3-targets/7-drivers/sqlite/src/core/control-driver.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner.validator-closed.integration.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • test/integration/test/mongo/aggregate-e2e.test.ts
  • packages/3-targets/7-drivers/postgres/src/exports/control.ts
  • packages/3-mongo-target/2-mongo-adapter/src/core/mongo-control-driver.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-mongo-target/3-mongo-driver/src/mongo-driver.ts
  • packages/3-mongo-target/2-mongo-adapter/src/exports/control.ts
  • packages/2-sql/9-family/src/core/control-adapter.ts
  • packages/2-sql/9-family/src/core/control-instance.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts

📝 Walkthrough

Walkthrough

Base control driver removes the SQL query method. A new SqlControlDriverInstance reintroduces typed SQL query capability and is adopted across SQL family adapters, migration runners, drivers, and tests. Mongo drivers and adapters drop query, add runtime narrowing (isMongoControlDriver), and tests/consumers are updated to construct the new driver shapes.

Changes

Driver Contract and Family-Specific Refactoring

Layer / File(s) Summary
Core driver contract refactoring
packages/1-framework/1-core/framework-components/src/control/control-instances.ts, packages/2-sql/1-core/contract/src/types.ts, packages/2-sql/1-core/contract/src/exports/types.ts
ControlDriverInstance removes the query method; new SqlControlDriverInstance<T> extends the base driver and re-introduces the typed query method for SQL family usage.
SQL family instance and adapter type updates
packages/2-sql/9-family/src/core/control-adapter.ts, packages/2-sql/9-family/src/core/control-instance.ts, packages/2-sql/9-family/src/core/migrations/types.ts
All SQL family verify, sign, marker, and ledger operations update their driver parameter types from generic ControlDriverInstance<'sql', TTarget> to the SQL-specific SqlControlDriverInstance<TTarget>.
Postgres adapter and test type updates
packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts, packages/3-targets/6-adapters/postgres/src/core/enum-control-hooks.ts, packages/3-targets/6-adapters/postgres/src/core/marker-ledger.ts, packages/3-targets/6-adapters/postgres/test/*
Postgres adapter methods, introspection helpers, marker/ledger types, and tests adopt SqlControlDriverInstance<'postgres'>.
SQLite adapter and type updates
packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts, packages/3-targets/6-adapters/sqlite/src/core/marker-ledger.ts, packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
SQLite adapters, marker-ledger alias, and migration runner execute signatures use SqlControlDriverInstance<'sqlite'>.
Mongo lowering and adapter alignment
packages/2-mongo-family/6-transport/mongo-lowering/src/driver-types.ts, packages/2-mongo-family/6-transport/mongo-lowering/src/exports/index.ts, packages/3-mongo-target/2-mongo-adapter/src/core/mongo-control-driver.ts, packages/3-mongo-target/2-mongo-adapter/src/exports/control.ts, packages/3-mongo-target/2-mongo-adapter/src/core/runner-deps.ts
Adds MongoControlDriverInstance to mongo-lowering exports; adapter exposes isMongoControlDriver guard; controlDriverFromDb no longer adds a query stub; extractDb uses the guard.
Mongo driver implementation refactor
packages/3-mongo-target/3-mongo-driver/src/mongo-driver.ts, packages/3-mongo-target/3-mongo-driver/src/exports/control.ts
MongoDriverImpl converts private # members to protected, exposes protected execute* methods, and MongoControlDriver now extends MongoDriverImpl and omits a query override.
Tests and integration updates
packages/3-mongo-target/*/test/*, test/integration/test/*
Integration and unit tests instantiate new MongoControlDriver(db, client) instead of factory, remove assertions about query() throwing, and update SQL-mock typings to SqlControlDriverInstance.
Package manifest update
packages/3-mongo-target/2-mongo-adapter/package.json, packages/2-mongo-family/6-transport/mongo-lowering/package.json
Reorder dependencies and add mongodb to mongo-lowering dev/peer deps (peer optional).

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • prisma/prisma-next#334: Both PRs modify the Mongo family control implementation and driver wiring in packages/2-mongo-family/9-family/src/core/control-instance.ts.
  • prisma/prisma-next#665: Changes the core ControlDriverInstance contract by removing query() and introducing SQL-specific driver typing, directly related to these edits.
  • prisma/prisma-next#712: Overlapping changes to SQL control adapter/family marker and ledger SPI and driver parameter types.

"🐰 I hopped through types and drivers bright,
Moved SQL's query to its own light,
Mongo now guards and keeps its db,
Tests rebuilt, constructors free,
A rabbit cheers—types tidy, code light!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly summarizes the main change: moving family-specific control driver transports (like SQL query) from the generic ControlDriverInstance interface to family-specific interfaces, which is the primary objective of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2840-reshape-controldriverinstance-drop-the-sql-hardcoded

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Jun 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@738

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@738

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@738

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@738

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@738

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@738

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@738

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@738

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@738

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@738

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@738

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@738

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@738

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@738

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@738

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@738

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@738

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@738

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@738

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@738

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@738

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@738

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@738

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@738

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@738

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@738

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@738

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@738

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@738

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@738

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@738

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@738

prisma-next

npm i https://pkg.pr.new/prisma-next@738

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@738

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@738

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@738

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@738

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@738

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@738

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@738

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@738

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@738

@prisma-next/mongo-orm

npm i https://pkg.pr.new/@prisma-next/mongo-orm@738

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@738

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@738

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@738

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@738

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@738

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@738

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@738

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@738

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@738

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@738

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@738

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@738

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@738

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@738

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@738

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@738

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@738

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@738

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@738

commit: 0b38cff

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 145.06 KB (0%)
postgres / emit 117.07 KB (0%)
mongo / no-emit 76.06 KB (+0.04% 🔺)
mongo / emit 70.93 KB (+0.06% 🔺)
cf-worker / no-emit 174.63 KB (0%)
cf-worker / emit 143.48 KB (0%)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/3-mongo-target/2-mongo-adapter/test/runner-deps.test.ts (1)

8-16: ⚡ Quick win

Add a regression case for mongo-typed drivers missing db.

This hunk improves the happy-path mock shape, but the failing-path coverage should also include { familyId: 'mongo', targetId: 'mongo' } without db so the runtime guard behavior is locked in.

Suggested test addition
   it("throws when the mongo control driver doesn't expose a db property", () => {
     const driver = {} as unknown as ControlDriverInstance<'mongo', 'mongo'>;
     expect(() => extractDb(driver)).toThrowError(
       /Mongo control driver does not expose a db property/,
     );
   });
+
+  it('throws when ids match mongo but db is missing', () => {
+    const driver = {
+      familyId: 'mongo',
+      targetId: 'mongo',
+      close: async () => {},
+    } as unknown as ControlDriverInstance<'mongo', 'mongo'>;
+    expect(() => extractDb(driver)).toThrowError(
+      /Mongo control driver does not expose a db property/,
+    );
+  });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/3-mongo-target/2-mongo-adapter/test/runner-deps.test.ts` around
lines 8 - 16, Add a regression test in runner-deps.test.ts that asserts the
runtime guard rejects a mongo-typed driver object that lacks the db property:
create a mock driver object with { familyId: 'mongo', targetId: 'mongo' } (no
db), cast to ControlDriverInstance<'mongo','mongo'> if needed, pass it into the
same validation/registration path used by the existing happy-path test (the same
variable names like driver or the function that consumes it), and assert the
expected failure/throw or error result to lock in the guard behavior for mongo
drivers missing db.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/3-mongo-target/2-mongo-adapter/src/core/mongo-control-driver.ts`:
- Around line 41-45: isMongoControlDriver currently only checks
familyId/targetId; strengthen it to also verify the Mongo-specific shape by
confirming the presence and types of required members (e.g., that the candidate
has a non-null "db" property and an "execute" method or other
MongoControlDriverInstance-specific functions). Update the predicate in
isMongoControlDriver to return true only when driver.familyId === 'mongo' &&
driver.targetId === 'mongo' && typeof (driver as any).execute === 'function' &&
(driver as any).db != null (or other required properties/methods from
MongoControlDriverInstance), so misclassified objects without DB or execute are
rejected.

---

Nitpick comments:
In `@packages/3-mongo-target/2-mongo-adapter/test/runner-deps.test.ts`:
- Around line 8-16: Add a regression test in runner-deps.test.ts that asserts
the runtime guard rejects a mongo-typed driver object that lacks the db
property: create a mock driver object with { familyId: 'mongo', targetId:
'mongo' } (no db), cast to ControlDriverInstance<'mongo','mongo'> if needed,
pass it into the same validation/registration path used by the existing
happy-path test (the same variable names like driver or the function that
consumes it), and assert the expected failure/throw or error result to lock in
the guard behavior for mongo drivers missing db.
🪄 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: 6300638f-d5e8-4b89-82c8-e8b5a34d3294

📥 Commits

Reviewing files that changed from the base of the PR and between ad553a8 and b7bce30.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (28)
  • packages/1-framework/1-core/framework-components/src/control/control-instances.ts
  • packages/2-mongo-family/9-family/src/core/control-instance.ts
  • packages/2-sql/1-core/contract/src/exports/types.ts
  • packages/2-sql/1-core/contract/src/types.ts
  • packages/2-sql/9-family/src/core/control-adapter.ts
  • packages/2-sql/9-family/src/core/control-instance.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner-integration.test.ts
  • packages/3-mongo-target/2-mongo-adapter/package.json
  • packages/3-mongo-target/2-mongo-adapter/src/core/mongo-control-driver.ts
  • packages/3-mongo-target/2-mongo-adapter/src/core/runner-deps.ts
  • packages/3-mongo-target/2-mongo-adapter/src/exports/control.ts
  • packages/3-mongo-target/2-mongo-adapter/test/runner-deps.test.ts
  • packages/3-mongo-target/3-mongo-driver/src/exports/control.ts
  • packages/3-mongo-target/3-mongo-driver/test/control-driver.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/postgres/src/core/enum-control-hooks.ts
  • packages/3-targets/6-adapters/postgres/src/core/marker-ledger.ts
  • packages/3-targets/6-adapters/postgres/test/control-adapter.defaults.test.ts
  • packages/3-targets/6-adapters/postgres/test/control-adapter.test.ts
  • packages/3-targets/6-adapters/postgres/test/enum-control-hooks.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/core/marker-ledger.ts
  • packages/3-targets/7-drivers/postgres/src/exports/control.ts
  • packages/3-targets/7-drivers/sqlite/src/core/control-driver.ts
  • test/integration/test/family.introspect.test.ts
💤 Files with no reviewable changes (4)
  • packages/3-mongo-target/3-mongo-driver/src/exports/control.ts
  • packages/1-framework/1-core/framework-components/src/control/control-instances.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner-integration.test.ts
  • packages/3-mongo-target/3-mongo-driver/test/control-driver.test.ts

@wmadden-electric wmadden-electric changed the title Reshape ControlDriverInstance: drop the SQL-hardcoded transport (TML-2840) Give control drivers a per-family transport, off the generic interface (TML-2840) Jun 5, 2026
constructor(db: Db, client: MongoClient) {
this.db = db;
this.#client = client;
this.#driver = MongoDriverImpl.fromDb(db);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is stupid. Why does the control driver instantiate an execution-plane driver and keep it hidden? This is shitty code sharing

@wmadden wmadden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-emptive approval. One comment worth addressing before merge

Comment on lines +20 to 25
if (!isMongoControlDriver(driver)) {
throw new Error(
'Mongo control driver does not expose a db property. ' +
'Use mongoControlDriver.create() from `@prisma-next/driver-mongo/control`.',
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message doesn't match the condition

@wmadden wmadden enabled auto-merge (rebase) June 6, 2026 17:09
wmadden and others added 8 commits June 6, 2026 19:10
Add SqlControlDriverInstance<T extends string> to @prisma-next/sql-contract/types.
It extends the generic ControlDriverInstance<'sql', T> and re-declares the query()
signature verbatim. PostgresControlDriver and SqliteControlDriver now declare
implements SqlControlDriverInstance<'postgres'/'sqlite'> respectively.

The generic ControlDriverInstance still carries query() at this point so all
existing SQL call sites continue to compile unchanged; the subsequent commit
retypes them to SqlControlDriverInstance.

Signed-off-by: Will Madden <madden@prisma.io>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Propagate SqlControlDriverInstance<T> to every location in the SQL family
and targets that declares driver parameters or local variables typed as
ControlDriverInstance<'sql', ...>:

- SqlControlFamilyInstance interface and implementation (control-instance.ts)
- SqlControlAdapter SPI (control-adapter.ts)
- CodecControlHooks.introspectTypes and SqlMigrationRunnerExecuteOptions
  (migrations/types.ts)
- PostgresControlAdapter / SqliteControlAdapter (both control-adapter.ts)
- PostgresMarkerWriteDriver / SqliteMarkerWriteDriver aliases (marker-ledger.ts)
- introspectPostgresEnumTypes (enum-control-hooks.ts)
- PostgresMigrationRunner.execute / SqliteMigrationRunner.execute (runner.ts)
- Mock drivers in postgres control-adapter tests and enum-control-hooks test

No SQL call site now depends on the generic ControlDriverInstance carrying query().

Signed-off-by: Will Madden <madden@prisma.io>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…re casts with predicates

Changes:
- MongoControlDriverInstance now extends both ControlDriverInstance<'mongo','mongo'>
  and MongoDriver, gaining execute() alongside the existing .db property.
- MongoControlDriverImpl delegates execute() to a held MongoDriverImpl.fromDb(db),
  so existing callers of createMongoControlDriver(db, client) are unchanged.
- Add isMongoControlDriver type predicate (exported from adapter-mongo/control);
  runner-deps.extractDb uses it in place of the previous bare cast.
- asMongoDriver in the Mongo family now uses a type predicate (isMongoTargetDriver)
  instead of a bare cast; the family layer cannot import MongoControlDriverInstance
  (targets domain), so the predicate narrowed to the framework interface only.
- Add @prisma-next/driver-mongo as a production dependency of adapter-mongo
  (the targets/adapters -> targets/drivers import is allowed; depcruiser only
  restricts the SQL driver direction).
- Update runner-deps.test.ts to supply the fields the isMongoControlDriver
  predicate checks (familyId, targetId) in the mock driver.
- query() stub is kept for now since ControlDriverInstance still declares it;
  it will be removed in the framework-cut commit.

Signed-off-by: Will Madden <madden@prisma.io>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…hrowing stub

Framework cut:
- ControlDriverInstance now carries only close() + inherited tags (no query).
- MongoControlDriverImpl.query() stub removed (no longer required by the interface).
- MongoControlDriver in @prisma-next/driver-mongo likewise drops its query() stub.
- controlDriverFromDb helper in adapter-mongo/control drops the query property.

Test cleanup:
- Remove the query()-throws tests from mongo-runner-integration.test.ts and
  control-driver.test.ts (the behaviour they validated no longer exists).
- Update family.introspect.test.ts in integration tests to type the mock driver
  as SqlControlDriverInstance<'postgres'> (ControlDriverInstance no longer
  carries query, so the mock needs the SQL-specific interface to satisfy
  familyInstance.introspect()).

Signed-off-by: Will Madden <madden@prisma.io>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…trolDriver extends MongoDriverImpl

- Add MongoControlDriverInstance interface to @prisma-next/mongo-lowering (with mongodb peer dep).
  It extends ControlDriverInstance<'mongo','mongo'>, MongoDriver, and adds `readonly db: Db`.
- Make MongoDriverImpl subclassable: protected constructor, protected readonly db/client fields,
  protected execute*Command helpers (renamed from hard-private #db/#client/#execute* methods).
- MongoControlDriver in driver-mongo now extends MongoDriverImpl and implements
  MongoControlDriverInstance, inheriting execute() and close() from the base class.
  It overrides db as public readonly to satisfy the interface's public carve-out.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Will Madden <madden@prisma.io>
…er-mongo dep

- Remove MongoControlDriverImpl and createMongoControlDriver from adapter-mongo.
  The adapter no longer constructs the control driver; it only uses the interface.
- MongoControlDriverInstance is now re-exported from @prisma-next/mongo-lowering
  in adapter-mongo's control exports (as a re-export from an exports/ file).
- isMongoControlDriver predicate stays in the adapter, typed against the interface.
- Remove @prisma-next/driver-mongo from adapter-mongo's dependencies; the adapter
  now depends only on the interface (via mongo-lowering) and never on the concretion.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Will Madden <madden@prisma.io>
…Driver constructor

All tests that previously called createMongoControlDriver(db, client) from
@prisma-next/adapter-mongo/control now construct new MongoControlDriver(db, client)
imported from @prisma-next/driver-mongo/control. Affected files span the target-mongo
integration tests and the shared integration test suite.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Will Madden <madden@prisma.io>
The guard is `!isMongoControlDriver(driver)` — a tag check — but the
old message said "does not expose a db property", describing the
property-presence check it replaced.  Updated the message and the
matching test assertion to reflect what the predicate actually checks.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Will Madden <madden@prisma.io>
@wmadden-electric wmadden-electric force-pushed the tml-2840-reshape-controldriverinstance-drop-the-sql-hardcoded branch from 5b6b080 to 0b38cff Compare June 6, 2026 17:10
@wmadden wmadden merged commit 1ac4aaa into main Jun 6, 2026
21 checks passed
@wmadden wmadden deleted the tml-2840-reshape-controldriverinstance-drop-the-sql-hardcoded branch June 6, 2026 17:21
wmadden-electric pushed a commit that referenced this pull request Jun 6, 2026
Now that TML-2840 (#738) gives MongoControlDriver a real
execute(wireCommand), MongoControlAdapterImpl narrows the driver via the
isMongoControlDriver predicate and dispatches through driver.execute
directly. Deletes the controlDriverDb helper, the throwaway
MongoDriverImpl.fromDb reach-around, and the source-level dependency on
@prisma-next/driver-mongo (forbidden migration->runtime plane edge).

The public @prisma-next/adapter-mongo/control free functions
(readMarker, readAllMarkers, initMarker, updateMarker, readLedger,
writeLedgerEntry) now take a MongoControlDriverInstance instead of a raw
Db: the fabricated db-only driver cannot carry the wire transport, and
the plane rule forbids adapter-mongo from constructing a real one. Tests
build new MongoControlDriver(db, client) and pass it; driver-mongo is
added as a devDependency where tests need it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Will Madden <madden@prisma.io>
wmadden-electric pushed a commit that referenced this pull request Jun 6, 2026
Now that TML-2840 (#738) gives MongoControlDriver a real
execute(wireCommand), MongoControlAdapterImpl narrows the driver via the
isMongoControlDriver predicate and dispatches through driver.execute
directly. Deletes the controlDriverDb helper, the throwaway
MongoDriverImpl.fromDb reach-around, and the source-level dependency on
@prisma-next/driver-mongo (a forbidden migration->runtime plane edge).

Removes the redundant readMarker / readAllMarkers / initMarker /
updateMarker / readLedger / writeLedgerEntry free functions from
@prisma-next/adapter-mongo/control: they were thin wrappers over a
private MongoControlAdapterImpl singleton and added nothing. Callers
(tests) now construct a MongoControlAdapterImpl plus a real
MongoControlDriver(db, client) and invoke the adapter methods directly.
driver-mongo is added as a devDependency where tests need it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Will Madden <madden@prisma.io>
wmadden added a commit that referenced this pull request Jun 6, 2026
Now that TML-2840 (#738) gives MongoControlDriver a real
execute(wireCommand), MongoControlAdapterImpl narrows the driver via the
isMongoControlDriver predicate and dispatches through driver.execute
directly. Deletes the controlDriverDb helper, the throwaway
MongoDriverImpl.fromDb reach-around, and the source-level dependency on
@prisma-next/driver-mongo (a forbidden migration->runtime plane edge).

Removes the redundant readMarker / readAllMarkers / initMarker /
updateMarker / readLedger / writeLedgerEntry free functions from
@prisma-next/adapter-mongo/control: they were thin wrappers over a
private MongoControlAdapterImpl singleton and added nothing. Callers
(tests) now construct a MongoControlAdapterImpl plus a real
MongoControlDriver(db, client) and invoke the adapter methods directly.
driver-mongo is added as a devDependency where tests need it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Will Madden <madden@prisma.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants