Skip to content

Commit cf9990b

Browse files
github-actions[bot]Marfuenclaude
authored
[dev] [Marfuen] mariano/fix-strip-sslmode-from-connection-string (#2437)
* fix: strip sslmode from DATABASE_URL to avoid conflict with explicit ssl option PrismaPg receives both `sslmode=require` in the connection string and an explicit `ssl` option. This double-SSL configuration can cause intermittent connection failures on staging (ECS + RDS). Uses the URL API to safely remove the sslmode param instead of the old buggy regex approach. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: exclude test files from tsc compilation in packages/db The bun:test import in strip-ssl-mode.test.ts breaks the Docker build which uses tsc (not bun) to compile packages/db. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: remove redundant prisma generate from Docker build The @prisma/client is already generated by packages/db build step (generate-prisma-client-js.js). The second prisma generate in the API build step was redundant and failing with an empty error in Docker. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: update Trigger.dev extensions to copy entire schema directory Both customPrismaExtension.ts files (api + app) now copy the full multi-file schema directory instead of a single file. This ensures prisma generate sees all model files, not just the generator/datasource. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Mariano Fuentes <marfuen98@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 64e7e0a commit cf9990b

3 files changed

Lines changed: 44 additions & 34 deletions

File tree

apps/api/Dockerfile.multistage

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ RUN cd packages/auth && bun run build \
6868
&& cd ../email && bun run build \
6969
&& cd ../company && bun run build
7070

71-
# Copy model files to api schema dir and generate Prisma client, then build NestJS app
71+
# Copy model files to api schema dir, then build NestJS app
72+
# Note: @prisma/client is already generated by packages/db build (generate-prisma-client-js.js)
7273
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
74+
&& cd /app/apps/api && bunx nest build
7475

7576
# =============================================================================
7677
# STAGE 3: Production Runtime

apps/api/customPrismaExtension.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,23 @@ export class PrismaExtension implements BuildExtension {
114114
const env: Record<string, string | undefined> = {};
115115

116116
// Copy the prisma schema from the published package to the build output path
117-
const schemaDestinationPath = join(manifest.outputPath, 'prisma', 'schema.prisma');
118-
const schemaDestinationDir = dirname(schemaDestinationPath);
117+
// Copy the entire schema directory (multi-file schema)
118+
const sourceDir = dirname(schemaPath);
119+
const schemaDestinationDir = join(manifest.outputPath, 'prisma', 'schema');
119120
context.logger.debug(
120-
`Copying the prisma schema from ${schemaPath} to ${schemaDestinationPath}`,
121+
`Copying the prisma schema directory from ${sourceDir} to ${schemaDestinationDir}`,
121122
);
122123
await mkdir(schemaDestinationDir, { recursive: true });
123-
await cp(schemaPath, schemaDestinationPath);
124+
await cp(sourceDir, schemaDestinationDir, { recursive: true });
124125

125-
// Patch the schema to use prisma-client-js (populates @prisma/client at runtime)
126+
// Patch schema.prisma to use prisma-client-js (populates @prisma/client at runtime)
126127
commands.push(
127-
`sed -i 's/provider.*=.*"prisma-client"/provider = "prisma-client-js"/' ./prisma/schema.prisma && sed -i '/output.*=.*"/d' ./prisma/schema.prisma`,
128+
`sed -i 's/provider.*=.*"prisma-client"/provider = "prisma-client-js"/' ./prisma/schema/schema.prisma && sed -i '/output.*=.*"/d' ./prisma/schema/schema.prisma`,
128129
);
129130

130-
// Add prisma generate command to generate the client from the patched schema
131+
// Generate client from the multi-file schema directory
131132
commands.push(
132-
`${binaryForRuntime(manifest.runtime)} node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma`,
133+
`${binaryForRuntime(manifest.runtime)} node_modules/prisma/build/index.js generate --schema=./prisma/schema`,
133134
);
134135

135136
// Only handle migrations if requested
@@ -190,19 +191,22 @@ export class PrismaExtension implements BuildExtension {
190191
context: ExtendedBuildContext,
191192
schemaSourcePath: string,
192193
): Promise<void> {
193-
const schemaDir = resolve(context.workingDir, 'prisma');
194-
const schemaDestinationPath = resolve(schemaDir, 'schema.prisma');
194+
// schemaSourcePath points to a file inside the schema directory.
195+
// Copy the entire directory (multi-file schema) to the local prisma/schema/ dir.
196+
const sourceDir = dirname(schemaSourcePath);
197+
const localSchemaDir = resolve(context.workingDir, 'prisma', 'schema');
195198

196-
await mkdir(schemaDir, { recursive: true });
197-
await cp(schemaSourcePath, schemaDestinationPath);
199+
await mkdir(localSchemaDir, { recursive: true });
200+
await cp(sourceDir, localSchemaDir, { recursive: true });
198201

199-
// Patch schema to use prisma-client-js (default output → @prisma/client)
202+
// Patch schema.prisma to use prisma-client-js (default output → @prisma/client)
203+
const localSchemaFile = resolve(localSchemaDir, 'schema.prisma');
200204
const { readFileSync, writeFileSync } = await import('node:fs');
201-
let schemaContent = readFileSync(schemaDestinationPath, 'utf8');
205+
let schemaContent = readFileSync(localSchemaFile, 'utf8');
202206
schemaContent = schemaContent
203207
.replace(/provider\s*=\s*"prisma-client"/g, 'provider = "prisma-client-js"')
204208
.replace(/\s*output\s*=\s*"[^"]*"\n?/g, '\n');
205-
writeFileSync(schemaDestinationPath, schemaContent);
209+
writeFileSync(localSchemaFile, schemaContent);
206210

207211
const clientEntryPoint = resolve(context.workingDir, 'node_modules/.prisma/client/default.js');
208212

@@ -221,7 +225,7 @@ export class PrismaExtension implements BuildExtension {
221225
}
222226

223227
context.logger.log('Prisma client missing. Generating before Trigger indexing.');
224-
await this.runPrismaGenerate(context, prismaBinary, schemaDestinationPath);
228+
await this.runPrismaGenerate(context, prismaBinary, localSchemaDir);
225229
}
226230

227231
private runPrismaGenerate(

apps/app/customPrismaExtension.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,23 @@ export class PrismaExtension implements BuildExtension {
114114
const env: Record<string, string | undefined> = {};
115115

116116
// Copy the prisma schema from the published package to the build output path
117-
const schemaDestinationPath = join(manifest.outputPath, 'prisma', 'schema.prisma');
117+
// Copy the entire schema directory (multi-file schema)
118+
const sourceDir = dirname(schemaPath);
119+
const schemaDestinationDir = join(manifest.outputPath, 'prisma', 'schema');
118120
context.logger.debug(
119-
`Copying the prisma schema from ${schemaPath} to ${schemaDestinationPath}`,
121+
`Copying the prisma schema directory from ${sourceDir} to ${schemaDestinationDir}`,
120122
);
121-
await cp(schemaPath, schemaDestinationPath);
123+
await mkdir(schemaDestinationDir, { recursive: true });
124+
await cp(sourceDir, schemaDestinationDir, { recursive: true });
122125

123-
// Patch the schema to use prisma-client-js (CJS-compatible, populates @prisma/client)
124-
// The published schema uses prisma-client provider which generates .ts files — not suitable for Node.js runtime
126+
// Patch schema.prisma to use prisma-client-js (populates @prisma/client at runtime)
125127
commands.push(
126-
`sed -i 's/provider.*=.*"prisma-client"/provider = "prisma-client-js"/' ./prisma/schema.prisma && sed -i '/output.*=.*"/d' ./prisma/schema.prisma`,
128+
`sed -i 's/provider.*=.*"prisma-client"/provider = "prisma-client-js"/' ./prisma/schema/schema.prisma && sed -i '/output.*=.*"/d' ./prisma/schema/schema.prisma`,
127129
);
128130

129-
// Add prisma generate command to generate the client from the patched schema
131+
// Generate client from the multi-file schema directory
130132
commands.push(
131-
`${binaryForRuntime(manifest.runtime)} node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma`,
133+
`${binaryForRuntime(manifest.runtime)} node_modules/prisma/build/index.js generate --schema=./prisma/schema`,
132134
);
133135

134136
// Only handle migrations if requested
@@ -189,19 +191,22 @@ export class PrismaExtension implements BuildExtension {
189191
context: ExtendedBuildContext,
190192
schemaSourcePath: string,
191193
): Promise<void> {
192-
const schemaDir = resolve(context.workingDir, 'prisma');
193-
const schemaDestinationPath = resolve(schemaDir, 'schema.prisma');
194+
// schemaSourcePath points to a file inside the schema directory.
195+
// Copy the entire directory (multi-file schema) to the local prisma/schema/ dir.
196+
const sourceDir = dirname(schemaSourcePath);
197+
const localSchemaDir = resolve(context.workingDir, 'prisma', 'schema');
194198

195-
await mkdir(schemaDir, { recursive: true });
196-
await cp(schemaSourcePath, schemaDestinationPath);
199+
await mkdir(localSchemaDir, { recursive: true });
200+
await cp(sourceDir, localSchemaDir, { recursive: true });
197201

198-
// Patch schema to use prisma-client-js (default output → @prisma/client)
202+
// Patch schema.prisma to use prisma-client-js (default output → @prisma/client)
203+
const localSchemaFile = resolve(localSchemaDir, 'schema.prisma');
199204
const { readFileSync, writeFileSync } = await import('node:fs');
200-
let schemaContent = readFileSync(schemaDestinationPath, 'utf8');
205+
let schemaContent = readFileSync(localSchemaFile, 'utf8');
201206
schemaContent = schemaContent
202207
.replace(/provider\s*=\s*"prisma-client"/g, 'provider = "prisma-client-js"')
203208
.replace(/\s*output\s*=\s*"[^"]*"\n?/g, '\n');
204-
writeFileSync(schemaDestinationPath, schemaContent);
209+
writeFileSync(localSchemaFile, schemaContent);
205210

206211
const clientEntryPoint = resolve(context.workingDir, 'node_modules/.prisma/client/default.js');
207212

@@ -220,7 +225,7 @@ export class PrismaExtension implements BuildExtension {
220225
}
221226

222227
context.logger.log('Prisma client missing. Generating before Trigger indexing.');
223-
await this.runPrismaGenerate(context, prismaBinary, schemaDestinationPath);
228+
await this.runPrismaGenerate(context, prismaBinary, localSchemaDir);
224229
}
225230

226231
private runPrismaGenerate(

0 commit comments

Comments
 (0)