Skip to content

Commit 59e0db9

Browse files
github-actions[bot]Marfuenclaude
authored
feat: migrate prisma from v6 to v7
* chore(db): update prisma schema for v7 (provider, output, remove url) * chore(db): rewrite prisma.config.ts for v7 stable API * chore(db): update client/index to use generated prisma-client path * chore(db): bump prisma to v7, add adapter-pg, update scripts and dist templates * chore(db): update postinstall sentinel for prisma-client output path * chore(db): add previewFeatures postgresqlExtensions to generator for prisma v7 compat * chore(auth): replace PrismaClient import with PrismaLike structural type for prisma v7 - Remove @prisma/client import and peerDependency - Replace PrismaClient type with PrismaLike interface (duck typing) - Make CreateAuthServerOptions generic with TDb extends PrismaLike - Define PrismaLike with $connect, $disconnect, and organization model methods - Removes direct coupling to @prisma/client for Prisma v7 custom output compatibility Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(auth): simplify PrismaLike to minimal structural interface * chore(api): add patch-schema-generator script for prisma-client-js in v7 * chore(api): unignore patch-schema-generator.js from scripts gitignore * chore(api): update prisma config, client, index for v7 + add adapter-pg Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: prisma PrismaPg constructor requires PoolConfig object, not raw string * chore(api): fix patch-schema to include postgresqlExtensions previewFeature and add prisma/generated to gitignore Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(api): migrate @trycompai/db imports to @db * chore(api): migrate @prisma/client imports to @db * fix(api): use default prisma-client-js output to resolve dist/ module issue prisma-client-js without custom output generates to node_modules/@prisma/client, which Node.js resolves from any directory. This avoids the ./generated import that fails at runtime because tsc doesn't copy .js files to dist/. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore(app): update prisma to v7 (schema, config, client, remove monorepo plugin) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(app): migrate @trycompai/db and @prisma/client imports to @db Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore(portal): update prisma to v7 (schema, config, client, imports) - Switch generator from prisma-client-js to prisma-client with output to src/generated/prisma - Add prisma.config.ts with defineConfig + env datasource URL - Update client.ts to use PrismaPg adapter with PoolConfig pattern - Update index.ts to re-export from generated client - Add @prisma/adapter-pg 7.6.0 and bump @prisma/client + prisma to 7.6.0 - Add src/generated/ to .gitignore Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(api): update Dockerfile for prisma v7 (patch step, remove openssl) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(ci): add schema patch step to trigger.dev deploy workflows for prisma v7 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: bump @prisma/adapter-pg to 7.6.0 at root Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(framework-editor): bump prisma to v7, add prisma.config.ts * fix(db): update seed script to use PrismaPg adapter instead of removed datasourceUrl * fix(app): split prisma exports into browser-safe types and server-only db prisma-client v7's PrismaPg adapter imports pg which requires dns (Node.js only). Client components importing types from @db would pull in the entire server chain. Fix: @db now exports from browser.ts (types/enums only), @db/server exports the db instance and full client types. 102 server files migrated to @db/server. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(app): migrate remaining multi-line db import to @db/server * fix(db): dist templates use ../src/generated path and browser.ts for types * fix(db): remove db export from dist/index and use browser.ts for all barrel exports * fix(db): point exports to src/index.ts, use browser.ts for barrel export * fix(app): add resolveExtensions to turbopack for .js→.ts resolution in generated prisma files * fix: add post-generate script to rewrite .js→.ts imports in prisma generated files * fix(db): remove db export from index.ts — server-only, must be imported from client.ts directly * fix(db): add .ts extension to browser import for Node.js ESM resolution * fix(db): keep .js extensions in packages/db for tsc compat, only fix for Turbopack apps * fix(db): use combined schema (dist/schema.prisma) for prisma generate to include all models and enums * fix(app): migrate remaining db and Prisma imports to @db/server * perf(db): re-export from @prisma/client, skip compiling generated files in build @prisma/client has browser-safe exports with all enums and proper browser/server conditions. No need to compile hundreds of generated .ts files to dist/ — build goes from 6+ min in Docker to ~3s. * perf(db): fast build — generate prisma-client-js to @prisma/client, skip tsc of generated files * fix: add @trycompai/db to db:generate filter, use generate-prisma-client-js in db:generate * fix(app): update trigger.dev config and custom prisma extension for v7 * fix(api): update trigger.dev config and custom prisma extension for v7 * fix: change @trycompai/db from npm pinned version to workspace:* across all packages * fix(portal): split prisma exports into browser-safe types and server-only db * fix(framework-editor): update prisma client for v7, add adapter-pg, split browser/server exports * fix(portal): use session cookies instead of JWT for API calls (API supports cookies via HybridAuthGuard) * fix(portal): remove unnecessary X-Organization-Id header, API gets it from session * fix(api): add localhost:3008 (trust app) to CORS trusted origins * fix(api): update jest mocks from @trycompai/db to @db, add missing @db mocks for test files * chore: commit pre-existing spec and openapi changes * fix: address bugbot issues (test mocks, duplicate mocks, build:docker prisma step) - policies.controller.spec.ts: change require('@trycompai/db') to require('@db') to match the mocked module - invitations route.test.ts: change vi.mock('@db') to vi.mock('@db/server') to match the import in the test - risks/comments/devices controller specs: remove duplicate jest.mock('@db') blocks, keeping one per file - apps/app/package.json: add fix-generated-extensions.js step to build:docker script Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: add db:generate task dependency to prevent race condition in Vercel builds * chore: update bun.lock * fix(db): import PrismaClient from @prisma/client in src/client.ts (matches build output) * fix(portal): migrate fleet-policies route db import to @db/server * fix: remove duplicate jest.mock, fix fragile prisma-client regex in trigger extensions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: scope sed output deletion to generator directive only (prevents deleting model fields) * fix: prevent PrismaPg adapter pool leak during dev hot-reload * fix(app): import Prisma from @db/server in connect-cloud action * fix(api): migrate new @trycompai/db imports from merged PR to @db * fix: make schema patching surgical (replace provider + remove output only, preserve other settings) --------- Co-authored-by: Mariano Fuentes <marfuen98@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 30516d4 commit 59e0db9

304 files changed

Lines changed: 810 additions & 493 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/trigger-api-tasks-deploy-main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
run: |
4343
mkdir -p prisma
4444
cp ../../packages/db/dist/schema.prisma prisma/schema.prisma
45+
node scripts/patch-schema-generator.js
4546
bunx prisma generate
4647
- name: 🚀 Deploy Trigger.dev
4748
working-directory: ./apps/api

.github/workflows/trigger-api-tasks-deploy-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
run: |
4949
mkdir -p prisma
5050
cp ../../packages/db/dist/schema.prisma prisma/schema.prisma
51+
node scripts/patch-schema-generator.js
5152
bunx prisma generate
5253
5354
- name: 🚀 Deploy Trigger.dev

apps/api/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ lerna-debug.log*
4747
.env.production.local
4848
.env.local
4949

50-
# Local scripts
50+
# Local scripts (tracked scripts are explicitly excluded below)
5151
scripts/
52+
!scripts/patch-schema-generator.js
5253

5354
# temp directory
5455
.temp

apps/api/Dockerfile.multistage

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ RUN cd packages/auth && bun run build \
7070
# Generate Prisma schema for API and build NestJS app
7171
RUN cd packages/db && node scripts/combine-schemas.js \
7272
&& cp /app/packages/db/dist/schema.prisma /app/apps/api/prisma/schema.prisma \
73+
&& node /app/apps/api/scripts/patch-schema-generator.js \
7374
&& cd /app/apps/api && bunx prisma generate && bunx nest build
7475

7576
# =============================================================================
@@ -84,7 +85,7 @@ WORKDIR /app
8485
RUN chown nestjs:nestjs /app
8586

8687
# Install runtime dependencies
87-
RUN apt-get update && apt-get install -y --no-install-recommends wget openssl && rm -rf /var/lib/apt/lists/*
88+
RUN apt-get update && apt-get install -y --no-install-recommends wget && rm -rf /var/lib/apt/lists/*
8889

8990
# Copy built NestJS app
9091
COPY --from=builder --chown=nestjs:nestjs /app/apps/api/dist ./dist

apps/api/customPrismaExtension.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export class PrismaExtension implements BuildExtension {
3333
constructor(private options: PrismaExtensionOptions) {
3434
this.moduleExternals = [
3535
'@prisma/client',
36-
'@prisma/engines',
37-
'@trycompai/db', // Add the published package to externals
36+
'@trycompai/db',
3837
];
3938
}
4039

@@ -123,7 +122,12 @@ export class PrismaExtension implements BuildExtension {
123122
await mkdir(schemaDestinationDir, { recursive: true });
124123
await cp(schemaPath, schemaDestinationPath);
125124

126-
// Add prisma generate command to generate the client from the copied schema
125+
// Patch the schema to use prisma-client-js (populates @prisma/client at runtime)
126+
commands.push(
127+
`sed -i 's/provider.*=.*"prisma-client"/provider = "prisma-client-js"/' ./prisma/schema.prisma && sed -i '/output.*=.*"/d' ./prisma/schema.prisma`,
128+
);
129+
130+
// Add prisma generate command to generate the client from the patched schema
127131
commands.push(
128132
`${binaryForRuntime(manifest.runtime)} node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma`,
129133
);
@@ -192,6 +196,14 @@ export class PrismaExtension implements BuildExtension {
192196
await mkdir(schemaDir, { recursive: true });
193197
await cp(schemaSourcePath, schemaDestinationPath);
194198

199+
// Patch schema to use prisma-client-js (default output → @prisma/client)
200+
const { readFileSync, writeFileSync } = await import('node:fs');
201+
let schemaContent = readFileSync(schemaDestinationPath, 'utf8');
202+
schemaContent = schemaContent
203+
.replace(/provider\s*=\s*"prisma-client"/g, 'provider = "prisma-client-js"')
204+
.replace(/\s*output\s*=\s*"[^"]*"\n?/g, '\n');
205+
writeFileSync(schemaDestinationPath, schemaContent);
206+
195207
const clientEntryPoint = resolve(context.workingDir, 'node_modules/.prisma/client/default.js');
196208

197209
if (existsSync(clientEntryPoint) && !process.env.TRIGGER_PRISMA_FORCE_GENERATE) {

apps/api/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@
2121
"@nestjs/platform-express": "^11.1.5",
2222
"@nestjs/swagger": "^11.2.0",
2323
"@nestjs/throttler": "^6.5.0",
24-
"@prisma/client": "6.18.0",
25-
"@prisma/instrumentation": "^6.13.0",
24+
"@prisma/adapter-pg": "7.6.0",
25+
"@prisma/client": "7.6.0",
26+
"@prisma/instrumentation": "7.6.0",
2627
"@react-email/components": "^0.0.41",
2728
"@react-email/render": "^2.0.4",
2829
"@thallesp/nestjs-better-auth": "^2.4.0",
2930
"@trigger.dev/build": "4.4.3",
3031
"@trigger.dev/sdk": "4.4.3",
3132
"@trycompai/auth": "workspace:*",
3233
"@trycompai/company": "workspace:*",
33-
"@trycompai/db": "1.3.22",
34+
"@trycompai/db": "workspace:*",
3435
"@trycompai/email": "workspace:*",
3536
"@trycompai/integration-platform": "workspace:*",
3637
"@upstash/ratelimit": "^2.0.8",
@@ -54,7 +55,7 @@
5455
"nanoid": "^5.1.6",
5556
"pdf-lib": "^1.17.1",
5657
"playwright-core": "^1.57.0",
57-
"prisma": "6.18.0",
58+
"prisma": "7.6.0",
5859
"react": "^19.1.1",
5960
"react-dom": "^19.1.0",
6061
"reflect-metadata": "^0.2.2",
@@ -123,7 +124,7 @@
123124
"build": "nest build",
124125
"build:docker": "bunx prisma generate && nest build",
125126
"db:generate": "bun run db:getschema && bunx prisma generate",
126-
"db:getschema": "node ../../packages/db/scripts/combine-schemas.js && cp ../../packages/db/dist/schema.prisma prisma/schema.prisma",
127+
"db:getschema": "node ../../packages/db/scripts/combine-schemas.js && cp ../../packages/db/dist/schema.prisma prisma/schema.prisma && node scripts/patch-schema-generator.js",
127128
"db:migrate": "cd ../../packages/db && bunx prisma migrate dev && cd ../../apps/api",
128129
"deploy:trigger-prod": "npx trigger.dev@4.4.3 deploy",
129130
"dev": "bunx concurrently --kill-others --names \"nest,trigger\" --prefix-colors \"green,blue\" \"nest start --watch\" \"trigger dev\"",

apps/api/prisma.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import "dotenv/config";
2+
import { defineConfig, env } from "prisma/config";
3+
4+
export default defineConfig({
5+
schema: "prisma/schema.prisma",
6+
datasource: {
7+
url: env("DATABASE_URL"),
8+
},
9+
});

apps/api/prisma/client.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

apps/api/prisma/client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { PrismaClient } from '@prisma/client';
2+
import { PrismaPg } from '@prisma/adapter-pg';
23

34
const globalForPrisma = global as unknown as { prisma: PrismaClient };
45

5-
export const db = globalForPrisma.prisma || new PrismaClient();
6+
function createPrismaClient(): PrismaClient {
7+
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL! });
8+
return new PrismaClient({ adapter });
9+
}
10+
11+
export const db = globalForPrisma.prisma || createPrismaClient();
612

713
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = db;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const schemaPath = path.join(__dirname, '../prisma/schema.prisma');
6+
let schema = fs.readFileSync(schemaPath, 'utf8');
7+
8+
// Surgically patch the generator block: swap provider and remove output line.
9+
// Preserves all other generator settings (previewFeatures, etc.).
10+
schema = schema
11+
.replace(/provider\s*=\s*"prisma-client"/g, 'provider = "prisma-client-js"')
12+
.replace(/\s*output\s*=\s*"[^"]*"\n?/g, '\n');
13+
14+
fs.writeFileSync(schemaPath, schema);
15+
console.log('[patch-schema] Set generator to prisma-client-js (default output)');

0 commit comments

Comments
 (0)