Skip to content

Upgrade to Prisma 7 (blocked on libnest, esbuild-plugin-prisma and MongoDB support) #1625

Open

Description

@joshunrau

The dependency update on the deps branch holds prisma and @prisma/client at 6.19.3, the last 6.x release, in apps/api and apps/gateway, and prisma-json-types-generator at 3.6.2. The newest releases eligible under the repo's 7-day minimumReleaseAge on 2026-10-04 were 7.10.0 and 5.1.1.

Why it was not upgraded

  • libnest: @douglasneuroinformatics/libnest@9.0.0 peers @prisma/client ^6.9.0 and depends on @prisma/engines ^6.19.2.
  • esbuild-plugin-prisma: @douglasneuroinformatics/esbuild-plugin-prisma@1.0.1 peers prisma, @prisma/client and @prisma/engines at 5.x || 6.x. The gateway build uses it (apps/gateway/scripts/build.ts:5,32).
  • prisma-json-types-generator: 4.x peers Prisma ^7, and 5.x peers ^7.8. 3.6.2 is the last release for Prisma 6.
  • MongoDB support: Prisma's v7 upgrade guide said v7 does not yet support MongoDB, and apps/api/prisma/schema.prisma:12 uses provider = "mongodb". Check whether that still holds for the current 7.x.
  • Generator migration: v7 replaces the prisma-client-js generator, which both schemas use, with prisma-client. The new generator needs an explicit output, driver adapters and a prisma.config.ts.

What is required

  1. Confirm that Prisma 7 supports MongoDB.
  2. Release Prisma 7 support in libnest and in esbuild-plugin-prisma. The plugin may become unnecessary with the new generator and driver adapters.
  3. Migrate this repo:
    • Move both schemas to the prisma-client generator and add prisma.config.ts.
    • Adopt a driver adapter for the gateway's SQLite database.
    • Update every import of the generated clients.
    • Bump prisma-json-types-generator to 5.x.
  4. Run pnpm lint, pnpm test and pnpm test:e2e, plus production builds of api and gateway.

Activity

  1. added
    Priority: Low
    Chore
    Difficulty: Very High
    Area: API
    Area: Gateway
    Upstream
    on Oct 5, 2026
  2. joshunrau commented on Oct 26, 2026

    @joshunrau
    CollaboratorAuthor

    Still blocked on main (d86740e), where both apps resolve prisma and @prisma/client 6.19.3. For the API the title's target is wrong. Step 1 has an answer now: "Prisma ORM 7 has no MongoDB connector, so Prisma ORM 8 is the successor path" (v6 to v8 MongoDB guide). There is also a deadline. Prisma 6 gets security patches only until 19 November 2026, while Prisma 7 keeps getting them for 18 months after 8 goes GA (release status).

    The API needs Prisma 8, which is not ready

    prisma's npm latest is 8.0.0-rc.27, and @prisma/orm-mongo is at 8.0.0-rc.20. MongoDB is "Early access", with transactions and extensions both "Not yet" (supported databases). The client becomes mongo({ contract, url, dbName }) from @prisma/orm-mongo/runtime, so this is a rewrite, not a bump. Blockers the issue doesn't list:

    • $transaction (apps/api/src/instrument-records/instrument-records.service.ts:169, apps/api/src/subjects/subjects.service.ts:146) becomes mongodb driver sessions, with { session } passed to every operation. Any operation that misses it silently runs outside the transaction. Item 5 of Performance: bulk record upload is N+1 on sessions and returns every record in the group #1414 would add a third use.
    • $extends(LibnestPrismaExtension) (apps/api/src/core/prisma.ts:182) supplies exists(), which has 7 call sites, and __modelName, which CASL subject detection reads (apps/api/src/auth/ability.utils.ts:14).
    • omit keeps user.hashedPassword out of reads, both globally (apps/api/src/core/prisma.ts:177-181) and per query in apps/api/src/users/users.service.ts. The v8 guide has no omit, so the port must exclude the hash some other way.
    • $runCommandRaw has no v8 equivalent, so ensureDatabaseIndexes (apps/api/src/core/prisma.ts:112,143,147), apps/api/src/demo/demo.service.ts:172 and apps/api/src/setup/setup.service.ts:135 need their own MongoClient.
    • @casl/prisma: 1.6.2 (main) and 2.0.2 (build: upgrade dependencies held back by breaking changes #1660) peer @prisma/client up to ^7.0.0, and both type conditions from @prisma/client's Prisma.TypeMap. accessibleQuery needs a CASL release for Prisma 8 or a replacement.
    • libnest reads Prisma.ModelName from @prisma/client at runtime (src/modules/prisma/prisma.module.ts:11 and prisma.extensions.ts:24 in 9.0.0). Its build plugin (src/meta/plugins/prisma.ts) throws when it finds no libquery_engine-*.node. 10.0.0, which build: upgrade dependencies held back by breaking changes #1660 installs, still peers ^6.9.0. The release libnest needs is for Prisma 8, not 7.
    • MongoDB 8.0+ is required, but .env.template:25 defaults MONGODB_VERSION=7.0.
    • prisma-json-types-generator: v8 replaces prisma generate with prisma contract emit, and the guide's setup has no generator block. The /// [AuditLogMetadata] and /// [ComputedMeasures] typings (apps/api/prisma/schema.prisma:57,163) need another mechanism, so the bump to 5.x in step 3 does not apply.

    The gateway can move to Prisma 7 now

    It doesn't use libnest or the JSON types generator, 7.10.1 supports SQLite, and patients reach it. The plan has these gaps:

    • The SQLite file persists across releases (docker-compose.yaml:86). The adapter needs timestampFormat: 'unixepoch-ms', which Prisma calls "Required for migrating from Prisma's native driver" (SQLite). Without it, the adapter misreads the stored createdAt/completedAt/expiresAt (apps/gateway/prisma/schema.prisma:17-19).
    • @prisma/adapter-better-sqlite3 is a new dependency and needs sign-off. It pulls in better-sqlite3, a native addon that needs an allowBuilds entry. The runner stage (apps/gateway/Dockerfile:26-37) ships dist/ without node_modules, so the build has to carry the addon.
    • db:push passes --skip-generate (apps/gateway/package.json:12), a flag Prisma 7 removed. apps/gateway/Dockerfile:24 and the gateway build in turbo.json both run db:push.
    • Delete esbuild-plugin-prisma rather than port it. It only copies the query engine (src/index.js:25-34 in 1.0.1), and a Prisma 7 client has none. Remove along with it: apps/gateway/Dockerfile:33, binaryTargets (apps/gateway/prisma/schema.prisma:7), its catalog entry, apps/gateway/AGENTS.md:89-90, .agents/docs/packages/esbuild-plugin-prisma.md, and the "11 packages" lists in AGENTS.md:149-150 and .agents/docs/packages/index.md:3,14.
    • If the required output leaves node_modules/@prisma/generated-client, update the db:generate outputs (turbo.json:18) and .agents/docs/architecture/testing-strategy.md:183.
    • Both apps share one Prisma range in the catalog, so the gateway needs a named catalog, as react19 already has.

    Recommendation

    1. Split the gateway into its own issue: Prisma 7, the adapter with unixepoch-ms, and removing the plugin. Land it after build: upgrade dependencies held back by breaking changes #1660, which also edits apps/gateway/package.json and the catalog. For tests, repoint the mock in apps/gateway/src/lib/__tests__/prisma.test.ts and add a unit test that the adapter gets unixepoch-ms. Run testing/src/specs/gateway-assignment.spec.ts, and boot a production image against a gateway.db written by 6.19.3.
    2. Retitle this issue to the API's move to Prisma 8. Gate it on four things: MongoDB leaving early access, transactions and extensions landing, a libnest release, and a @casl/prisma answer.
    3. Move the default MongoDB to 8.0 separately. mongodb-memory-server 11.3.0 already gives the apps/api/test/ suite and the Playwright stack 8.2.6. Existing deployments must be on 7.0 with featureCompatibilityVersion "7.0" before switching (upgrade notes).

    Decision needed: is it acceptable to run the API on unpatched 6.19.3 after 19 November, until Prisma 8's MongoDB support is ready? The alternative is to use the mongodb driver directly (apps/api/package.json:51), which is a larger rewrite.

    Triage note written with Claude Code. Code references point at main @ d86740e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: APIArea: GatewayChoreDifficulty: Very HighPriority: LowUpstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions