Skip to content

feat(prisma)!: Prisma v7#1337

Merged
Tobbe merged 96 commits intomainfrom
tobbe-major-prisma-v7-upgrade
Mar 17, 2026
Merged

feat(prisma)!: Prisma v7#1337
Tobbe merged 96 commits intomainfrom
tobbe-major-prisma-v7-upgrade

Conversation

@Tobbe
Copy link
Member

@Tobbe Tobbe commented Mar 8, 2026

Upgrading to Prisma v7 for their TypeScript query engine.

If you're using Cedar's experimental Storage support, you need to update your code to look something like this:

import { PrismaClient } from './generated/prisma/client'
import { createUploadsExtension } from '@cedarjs/storage'

const uploadsExtension = createUploadsExtension<PrismaClient>(
  {
    user: { fields: ['avatar'] },
  },
  storageAdapter,
  urlSigner,
)

Pay attention to how directUrl isn't supported anymore, and what you should do instead: https://www.prisma.io/docs/guides/upgrade-prisma-orm/v7#schema-changes and prisma/prisma#28700

Some "directUrl"-related PRs on the RW repo:

Note that we no longer support TEST_DIRECT_URL (that was never documented). Instead we expect users to handle switching the db url themselves, for example by looking at process.env.NODE_ENV, now that this is all configured in a JavaScript-file where having logic for this is much easier

TODO:

@netlify
Copy link

netlify bot commented Mar 8, 2026

Deploy Preview for cedarjs ready!

Name Link
🔨 Latest commit 2c0466d
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/69b99f9bf0e33d000814da5b
😎 Deploy Preview https://deploy-preview-1337--cedarjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added this to the next-release-major milestone Mar 8, 2026
@nx-cloud
Copy link

nx-cloud bot commented Mar 8, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 2c0466d

Command Status Duration Result
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 2s View ↗
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 3m 35s View ↗
nx run-many -t build ✅ Succeeded 3s View ↗
nx run-many -t test:types ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-17 18:58:59 UTC

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 8, 2026

Greptile Summary

This PR upgrades CedarJS from Prisma v6 to Prisma v7, migrating to the new TypeScript query engine, driver adapter pattern, and prisma.config.cjs-based datasource URL configuration. It touches 129 files across templates, fixtures, testing infrastructure, storage, CLI, and internal packages.

Key changes include:

  • All schema.prisma files updated to provider = "prisma-client" with a custom output path, and url removed from the datasource block (moved to prisma.config.cjs via env())
  • New getPrismaSchemas / getPrismaSchemasAtPath helpers in @cedarjs/project-config centralise schema reading, replacing scattered getSchemaWithPath calls
  • resolveGeneratedPrismaClient is now async and probes multiple candidate paths to find the generated client
  • Storage extension types are made generic over TClient, removing the dependency on @prisma/client's global PrismaClient type
  • directUrl support removed from testing setup (correct for Prisma v7)
  • validateUniqueness now requires an explicit db argument instead of silently creating a new PrismaClient()

Issues found:

  • packages/project-config/src/prisma.ts ships with 16 console.log debug statements that will pollute production logs and expose schema/file-path details on every invocation
  • packages/internal/src/project.ts uses RegExp.escape (available only in Node.js ≥24) without a polyfill or guard, and can pass undefined to it when the PrismaClient import regex doesn't match — both will throw TypeError at runtime on older LTS Node.js versions
  • The SQLite driver adapter (PrismaBetterSqlite3) is hardcoded unconditionally in all four db.ts/db.js templates; users who switch to PostgreSQL or MySQL will get a confusing runtime failure from the SQLite adapter receiving a non-file: URL

Confidence Score: 2/5

  • Not safe to merge without removing debug logging, fixing the RegExp.escape compatibility issue, and validating the incomplete fallback logic in resolveGeneratedPrismaClient.
  • The core migration strategy (driver adapters, custom output paths, config-file datasource URL) is architecturally sound, but packages/project-config/src/prisma.ts is visibly work-in-progress: 16 console.log calls and two TODO comments explicitly flag unvalidated code. The RegExp.escape usage in packages/internal/src/project.ts is a hard runtime breakage on Node.js 18/20 LTS. These issues together prevent a safe release.
  • packages/project-config/src/prisma.ts (debug logging + unvalidated fallbacks) and packages/internal/src/project.ts (RegExp.escape compatibility + potential null-dereference) require attention before merging.

Important Files Changed

Filename Overview
packages/project-config/src/prisma.ts Rewrites resolveGeneratedPrismaClient to async and adds Prisma v7 schema introspection helpers, but ships with 16 debug console.log calls and multiple TODO comments flagging unvalidated fallback logic.
packages/internal/src/project.ts Updates dbReexportsPrismaClient to detect the new generated client import pattern, but uses RegExp.escape (Node.js ≥24 only) without a guard and can pass undefined to it when the import regex doesn't match.
packages/create-cedar-app/templates/ts/api/src/lib/db.ts Migrates to Prisma v7 driver adapter pattern for SQLite, but hardcodes PrismaBetterSqlite3 unconditionally, which will fail if a user later switches to PostgreSQL or MySQL.
packages/internal/src/generate/graphqlCodeGen.ts Refactors getPrismaClient to handle both v6 and v7 module shapes via getModelName helper and removes the hasGenerated boolean indirection — clean improvement.
packages/storage/src/prismaExtension.ts Makes ModelNamesFor, UploadsConfig, and related types generic over TClient so users supply their own generated PrismaClient type — correct approach for Prisma v7 where @prisma/client no longer ships a global client type.
packages/testing/src/api/directUrlHelpers.ts Deleted — directUrl is no longer supported in Prisma v7 schema, so the helpers and their tests are correctly removed.
packages/testing/src/api/vitest/CedarApiVitestEnv.ts Removes directUrl handling and @prisma/internals schema introspection during test setup; inlines the default SQLite path, simplifying the environment setup.
packages/api/src/validations/validations.ts Removes the new PrismaClient() fallback in validateUniqueness — now throws a clear error when db is not passed, which is the correct behaviour for Prisma v7.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["resolveGeneratedPrismaClient()"] --> B["getSchemaPath(prismaConfigPath)"]
    B --> C["getPrismaSchemasAtPath(schemaPath)"]
    C --> D["getConfig({ datamodel: schemas })"]
    D --> E{"generator output found?"}
    E -- yes --> F["generatorOutputPath = resolved output"]
    E -- no --> G["catch: getGeneratorOutputPathFromSchema(schemaPath)\n(regex fallback)"]
    F --> H["candidateEntries list\n1. generatorOutputPath/client.ext\n2. schemaDir/generated/client/client.ext\n3. schemaDir/generated/prisma/client.ext\n4. node_modules/.prisma/client/index.js"]
    G --> H
    H --> I{"find first entry\nthat exists on disk"}
    I -- found --> J["return entry"]
    I -- not found + mustExist --> K["throw Error (lists all checked paths)"]
    I -- not found --> L["return candidateEntries[0] (best guess)"]

    subgraph "Template db.ts (SQLite only)"
      M["process.env.DATABASE_URL"] --> N["resolveSqliteUrl()"]
      N --> O["new PrismaBetterSqlite3({ url })"]
      O --> P["new PrismaClient({ adapter })"]
    end
Loading

Last reviewed commit: e8b91ae

@Tobbe Tobbe merged commit 446abbc into main Mar 17, 2026
42 checks passed
@Tobbe Tobbe deleted the tobbe-major-prisma-v7-upgrade branch March 17, 2026 19:02
@github-actions
Copy link

The changes in this PR are now available on npm.

Try them out by running yarn cedar upgrade -t 3.0.0-canary.13597

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.

1 participant