Skip to content

Commit c58045f

Browse files
github-actions[bot]Marfuenclaude
authored
refactor: simplify prisma schema sharing using native v7 multi-file schemas
* refactor: simplify prisma schema sharing using native v7 multi-file schemas Replace combine-schemas.js-based pipeline with Prisma v7's native directory support. Each app now has its own prisma/schema/ dir with a local schema.prisma (committed) and copies model files from packages/db/prisma/schema/ at generate time (gitignored). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor: simplify prisma schema sharing and fix Docker build - Use native Prisma v7 multi-file schema (--schema=prisma/schema directory) - Each app has its own prisma/schema/schema.prisma with correct generator - generate-prisma-client-js.js creates temp dir with model files instead of combine-schemas - Remove PoolConfig import from pg (not a direct dependency) - Keep bun:1.2.8 for builder (compatible with workspace resolution), node:22 for production - Restore original COPY order in Dockerfile (no node_modules restore needed) --------- Co-authored-by: Mariano Fuentes <marfuen98@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fab6693 commit c58045f

27 files changed

Lines changed: 125 additions & 104 deletions

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ jobs:
3737
- name: Build DB package
3838
working-directory: ./packages/db
3939
run: bun run build
40-
- name: Copy schema to api and generate client
40+
- name: Copy model files to api schema dir and generate client
4141
working-directory: ./apps/api
4242
run: |
43-
mkdir -p prisma
44-
cp ../../packages/db/dist/schema.prisma prisma/schema.prisma
45-
node scripts/patch-schema-generator.js
46-
bunx prisma generate
43+
find ../../packages/db/prisma/schema -name '*.prisma' ! -name 'schema.prisma' -exec cp {} prisma/schema/ \;
44+
bunx prisma generate --schema=prisma/schema
4745
- name: 🚀 Deploy Trigger.dev
4846
working-directory: ./apps/api
4947
timeout-minutes: 20

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ jobs:
4343
working-directory: ./packages/db
4444
run: bun run build
4545

46-
- name: Copy schema to api and generate client
46+
- name: Copy model files to api schema dir and generate client
4747
working-directory: ./apps/api
4848
run: |
49-
mkdir -p prisma
50-
cp ../../packages/db/dist/schema.prisma prisma/schema.prisma
51-
node scripts/patch-schema-generator.js
52-
bunx prisma generate
49+
find ../../packages/db/prisma/schema -name '*.prisma' ! -name 'schema.prisma' -exec cp {} prisma/schema/ \;
50+
bunx prisma generate --schema=prisma/schema
5351
5452
- name: 🚀 Deploy Trigger.dev
5553
working-directory: ./apps/api

apps/api/.gitignore

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

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

5453
# temp directory
5554
.temp
@@ -65,6 +64,8 @@ pids
6564
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
6665

6766

68-
prisma/schema.prisma
67+
# Model files are copied here by db:getschema — only schema.prisma is committed
68+
prisma/schema/*.prisma
69+
!prisma/schema/schema.prisma
6970
trigger.config.js
7071
test/**/*.js

apps/api/Dockerfile.multistage

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# =============================================================================
22
# STAGE 1: Dependencies - Install only what the API needs
33
# =============================================================================
4-
FROM oven/bun:1.3.11 AS deps
4+
FROM oven/bun:1.2.8 AS deps
55

66
WORKDIR /app
77

@@ -35,7 +35,7 @@ RUN bun install --ignore-scripts
3535
# =============================================================================
3636
# STAGE 2: Builder - Build workspace packages and NestJS app
3737
# =============================================================================
38-
FROM oven/bun:1.3.11 AS builder
38+
FROM oven/bun:1.2.8 AS builder
3939

4040
WORKDIR /app
4141

@@ -46,7 +46,8 @@ COPY --from=deps /app/node_modules ./node_modules
4646
COPY --from=deps /app/package.json ./package.json
4747
COPY --from=deps /app/bun.lock ./bun.lock
4848

49-
# Copy workspace packages source
49+
# Copy workspace packages source (node_modules excluded by .dockerignore,
50+
# but COPY replaces directories so workspace node_modules from deps get wiped)
5051
COPY packages/auth ./packages/auth
5152
COPY packages/db ./packages/db
5253
COPY packages/utils ./packages/utils
@@ -58,7 +59,7 @@ COPY packages/company ./packages/company
5859
# Copy API source
5960
COPY apps/api ./apps/api
6061

61-
# Build db first — generates Prisma client needed by other packages
62+
# Build db — generates Prisma client + compiles dist/ for @trycompai/db consumers
6263
RUN cd packages/db && bun run build
6364

6465
# Build remaining workspace packages
@@ -67,11 +68,9 @@ RUN cd packages/auth && bun run build \
6768
&& cd ../email && bun run build \
6869
&& cd ../company && bun run build
6970

70-
# Generate Prisma schema for API and build NestJS app
71-
RUN cd packages/db && node scripts/combine-schemas.js \
72-
&& cp /app/packages/db/dist/schema.prisma /app/apps/api/prisma/schema.prisma \
73-
&& node /app/apps/api/scripts/patch-schema-generator.js \
74-
&& cd /app/apps/api && /app/node_modules/.bin/prisma generate && bunx nest build
71+
# Copy model files to api schema dir and generate Prisma client, then build NestJS app
72+
RUN find /app/packages/db/prisma/schema -name '*.prisma' ! -name 'schema.prisma' -exec cp {} /app/apps/api/prisma/schema/ \; \
73+
&& cd /app/apps/api && /app/node_modules/.bin/prisma generate --schema=prisma/schema && bunx nest build
7574

7675
# =============================================================================
7776
# STAGE 3: Production Runtime

apps/api/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@
122122
"private": true,
123123
"scripts": {
124124
"build": "nest build",
125-
"build:docker": "bunx prisma generate && nest build",
126-
"db:generate": "bun run db:getschema && bunx prisma generate",
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",
125+
"build:docker": "bunx prisma generate --schema=prisma/schema && nest build",
126+
"db:generate": "bun run db:getschema && bunx prisma generate --schema=prisma/schema",
127+
"db:getschema": "find ../../packages/db/prisma/schema -name '*.prisma' ! -name 'schema.prisma' -exec cp {} prisma/schema/ \\;",
128128
"db:migrate": "cd ../../packages/db && bunx prisma migrate dev && cd ../../apps/api",
129129
"deploy:trigger-prod": "npx trigger.dev@4.4.3 deploy",
130130
"dev": "bunx concurrently --kill-others --names \"nest,trigger\" --prefix-colors \"green,blue\" \"nest start --watch\" \"trigger dev\"",

apps/api/prisma.config.ts

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

apps/api/prisma/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PrismaClient } from '@prisma/client';
22
import { PrismaPg } from '@prisma/adapter-pg';
3-
import type { PoolConfig } from 'pg';
3+
44

55
const globalForPrisma = global as unknown as { prisma: PrismaClient };
66

@@ -26,7 +26,7 @@ const globalForPrisma = global as unknown as { prisma: PrismaClient };
2626
* root CA store, so rejectUnauthorized: false is required. The connection
2727
* is still TLS-encrypted — only identity verification is skipped.
2828
*/
29-
function getSslConfig(url: string): PoolConfig['ssl'] {
29+
function getSslConfig(url: string): boolean | { rejectUnauthorized: boolean } | undefined {
3030
const match = url.match(/sslmode=(\w[\w-]*)/);
3131
if (!match) return undefined;
3232

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
generator client {
2+
provider = "prisma-client-js"
3+
previewFeatures = ["postgresqlExtensions"]
4+
}
5+
6+
datasource db {
7+
provider = "postgresql"
8+
extensions = [pgcrypto]
9+
}

apps/api/scripts/patch-schema-generator.js

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

apps/app/.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ next-env.d.ts
5353
# Generated Prisma Client
5454
prisma/generated
5555
src/generated/
56-
# Copied schema from @trycompai/db package - always generate fresh
57-
prisma/schema.prisma
56+
# Model files are copied here by db:getschema — only schema.prisma is committed
57+
prisma/schema/*.prisma
58+
!prisma/schema/schema.prisma

0 commit comments

Comments
 (0)