Skip to content
This repository was archived by the owner on Jun 9, 2026. It is now read-only.

chore(prisma): isolate client into per-package output dir (monorepo prep) - #187

Merged
oakinh merged 3 commits into
developfrom
chore/monorepo-prep-prisma-client
Jun 4, 2026
Merged

oakinh merged 3 commits into
developfrom
chore/monorepo-prep-prisma-client

Conversation

@oakinh

@oakinh oakinh commented Jun 4, 2026 •

Copy link
Copy Markdown
Collaborator

Monorepo prep

Behavior-preserving upstream normalization ahead of the omni monorepo migration. The monorepo sync is additive/deterministic, so we fix upstream here first where CI validates in the real environment.

What

  • prisma/schema/schema.prisma: add output = "../../src/generated/prisma" to the generator client block (existing provider/binaryTargets/previewFeatures unchanged) so each package owns an isolated generated Prisma client.
  • .gitignore: ignore src/generated/.
  • Rewrote the bare @prisma/client import specifier to the relative generated path across 20 sites / 20 files (validated codemod). @prisma/client/... subpath imports are intentionally left alone — they still resolve to the real npm package the generated client depends on.

Validation

  • npx prisma generate → confirmed output to src/generated/prisma.
  • npm run build ✅ (zero Prisma-resolution errors).
  • npm test → 116 passed, 1 skipped; the only failing suite is a DB integration test (election_api_test does not exist on localhost) — environment-only, unrelated to this change. Notably it resolves the new client from src/generated/prisma/runtime/library.js, confirming runtime resolution works.
  • src/generated/ confirmed git-ignored; not committed.

Made with Cursor


Note

Medium Risk
Changes how the Prisma client is built and shipped (CI, Docker, and all DB type imports); a missed prisma generate or wrong Docker copy would break builds or production DB access, though runtime behavior is intended to stay the same.

Overview
Moves the Prisma client from the default @prisma/client package into a gitignored per-package output at src/generated/prisma, ahead of monorepo work so each package can own its own generated client.

Schema & imports: generator client now sets output = "../../src/generated/prisma". Application code that imported Prisma, PrismaClient, and model enums from @prisma/client now uses relative paths like ../generated/prisma (many modules under src/).

Tooling: .gitignore ignores src/generated/. PR CI runs npx prisma generate after npm ci and before tsc / tests so type-checking sees the generated client. Docker stops copying node_modules/.prisma and instead copies the built src/generated/prisma tree into dist/src/generated/prisma so compiled Nest code can load the client and query engine at runtime.

Reviewed by Cursor Bugbot for commit a5ba99c. Configure here.

…rep)

Set the Prisma client generator `output` to a per-package
`src/generated/prisma` directory and rewrite the bare `@prisma/client`
import specifier to the relative generated path (20 sites). `@prisma/client`
subpath imports (e.g. runtime/library) are left untouched.

Monorepo prep: behavior-preserving upstream normalization ahead of the omni
monorepo migration, where each package needs its own isolated generated
Prisma client.

Co-authored-by: Cursor <cursoragent@cursor.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Comment thread src/prisma/prisma.service.ts
@delegate-reviewer

delegate-reviewer Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

1 blocker. Reply delegate review after fixing.

Inline comments could not be posted (file not in diff). Findings below.

.github/workflows/main.yml:42-43 — deploy pipeline missing prisma generate before tests

The deploy pipeline runs npm run test immediately after npm ci with no prisma generate step. The Prisma client is output to src/generated/prisma (per prisma/schema/schema.prisma line 5), which is listed in .gitignore line 6. Twenty-three source files — including test files — import from that generated path. Without generation, every test run in the deploy pipeline will fail at module resolution.

pull-request.yml already has the correct fix (line 23: npx prisma generate); the same step is simply missing here.

      - run: npm ci
      - run: npx prisma generate
      - run: npm run test

Follow-up to the per-package Prisma output dir (src/generated/prisma).

Dockerfile: the generated client (client JS + bundled runtime + query
engine binary) lives in src/generated/prisma, which `nest build` does not
emit into dist, and node_modules/.prisma is no longer produced in custom-
output mode (the old COPY of it would fail). Copy the generated dir to the
exact path the compiled code resolves at runtime (dist/src/generated/prisma).
Verified locally: `node dist/src/main.js` boots, loads the engine from
dist/src/generated/prisma/runtime/library.js, and only fails on DB auth.

CI (pull-request.yml): add an explicit `npx prisma generate` step before
type-check/tests so generation no longer relies on @prisma/client's
implicit postinstall side effect.

Addresses delegate review blockers and Bugbot finding on #187.

Co-authored-by: Cursor <cursoragent@cursor.com>
@oakinh

oakinh commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

Both blockers + the Bugbot finding addressed in a5ba99c:

  1. Runtime image missing the generated client / query engine — nest build doesn't emit src/generated/prisma into dist, and node_modules/.prisma is no longer produced in custom-output mode (so the old COPY node_modules/.prisma would itself fail). The generated client is fully self-contained (client JS + bundled runtime/ + libquery_engine-linux-musl.so.node). I now copy it to the exact path the compiled code resolves at runtime: COPY --from=builder /app/src/generated/prisma ./dist/src/generated/prisma. Verified locally: node -r ./dist/src/otel.js dist/src/main.js boots, loads the engine from dist/src/generated/prisma/runtime/library.js, and only fails on DB auth (env-only) — i.e., no module-resolution/engine error.

  2. CI missing prisma generate — added an explicit npx prisma generate step before tsc --noEmit/tests. (Note: the PR-validation job was already green because @prisma/client's postinstall auto-generates during npm ci; the explicit step removes reliance on that implicit side effect.)

delegate review

@oakinh

oakinh commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a5ba99c. Configure here.

main.yml runs `npm run test` after `npm ci` without generating the
Prisma client (output to the gitignored src/generated/prisma). Add an
explicit `npx prisma generate` step, mirroring pull-request.yml, so test
runs don't rely on @prisma/client's implicit postinstall generation.

Addresses delegate review blocker on #187.

Co-authored-by: Cursor <cursoragent@cursor.com>
@oakinh

oakinh commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed in 8d39bf6: added the same explicit npx prisma generate step to main.yml (deploy pipeline) before npm run test, mirroring the fix already in pull-request.yml. Both pipelines now generate the client into src/generated/prisma before type-check/tests rather than relying on @prisma/client's implicit postinstall.

delegate review

@delegate-reviewer delegate-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

@oakinh
oakinh merged commit e3c7042 into develop Jun 4, 2026
5 checks passed
@oakinh
oakinh deleted the chore/monorepo-prep-prisma-client branch June 4, 2026 20:46
oakinh added a commit that referenced this pull request Jun 4, 2026
Resolve package-lock.json conflict (siblings #187/#188/#190 merged to
develop and moved package.json/package-lock.json). package.json
auto-merged cleanly, preserving this PR's typescript ^5.9.3 +
typescript-eslint ^8.60.0 alongside develop's changes. Lockfile
regenerated via npm install (umbrella typescript-eslint -> 8.60.1) so it
matches the merged package.json; strict npm ci resolves with no ERESOLVE,
build + lint green.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant