chore(db): generate prisma client on postinstall#512
Merged
Conversation
Fresh clones (and any schema change) left a stale generated client, so `tsc`/`test`/`dev` failed with `Property 'groomingRun' is missing on PrismaClient` until you manually ran `prisma generate`. Add a `postinstall` hook so `npm install` always regenerates it. The hook is guarded (`test -f prisma/schema.prisma && prisma generate || true`) so it no-ops in Docker's dependency-only stages, which run `npm ci` before the schema is copied — the builder stage still generates explicitly with the schema present. `prisma generate` needs only the schema, but prisma.config.ts threw when DATABASE_URL was unset (which would break postinstall on a machine with no env); drop the throw and supply datasource.url only when present. Runtime still enforces DATABASE_URL via src/lib/prisma.ts; migrate/deploy still read it from env. Closes #499
d63138f to
cc43e65
Compare
Contributor
There was a problem hiding this comment.
AI Automated Review
Full PR review.
Analysis engine: MiniMax-M2.7@https://litellm.jory.dev/v1 (anthropic) — escalated (fast_low_confidence)
Recommendation
Approve. This PR correctly implements the fix for issue PR 499, addressing the real problem where fresh clones fail on npm install because prisma generate (run during postinstall) threw when DATABASE_URL was not set. The solution is well-reasoned, internally consistent, and properly documented.
Change-by-Change Findings
prisma.config.ts
- Removes the hard throw when
DATABASE_URLis unset and makes thedatasourceconfig conditional via spread operator. - Rationale:
prisma generateonly needs the schema file to produce client types — it does not need a live database connection. Throwing here broke thenpm install→ postinstall → generate flow on fresh clones. - Runtime safety preserved:
src/lib/prisma.ts(verified via tool harness) still enforcesDATABASE_URL(orDISPATCH_DATABASE_URL) at runtime viainitClient(), so the app will fail with a clear error if the env var is missing when it actually tries to connect. - The explanatory comment is thorough and accurately describes the design rationale.
package.json
- Adds
"postinstall": "test -f prisma/schema.prisma && prisma generate || true"script. - The guard (
test -f prisma/schema.prisma) ensures it only runs when the schema exists (e.g., not during package publication). - The
|| trueprevents install failure if generate fails for any unexpected reason (graceful degradation). - Uses POSIX shell syntax appropriate for the documented Debian bookworm-slim Docker target.
AGENTS.md
- Updates documentation to reflect the new workflow:
npm installnow notes it runsprisma generatevia postinstall.- Replaces
npx prisma generatewithnpm run db:generateand clarifies it also runs on postinstall.
- Aligns with the actual package.json scripts.
Standards Compliance
- No secrets committed: ✅ No credentials or env vars added.
- Prisma schema conventions: ✅ No schema changes; config change is consistent with the Prisma notes in AGENTS.md.
- Error handling: ✅ Runtime error handling in
src/lib/prisma.tsremains intact with meaningful error messages. - Environment variable resolution: ✅ Follows the documented order (
DATABASE_URL>DISPATCH_DATABASE_URL) as enforced at runtime ininitClient(). - Documentation: ✅ AGENTS.md updated to reflect the new behavior.
Linked Issue Fit
Issue PR 499 acceptance criteria fully met:
- ✅ Added
"postinstall": "prisma generate"to package.json. - ✅ Fixed
prisma.config.tsto not throw whenDATABASE_URLis unset. - ✅ Documented the ordering in AGENTS.md.
- ✅ Verification stated in PR body:
prisma generatenow succeeds withoutDATABASE_URL.
CI Check Results
All checks passed:
- Lint: ✅ success
- Build: ✅ success
- Tests: ✅ success
- Typecheck: ✅ success
- Docker Build: ✅ success
Tool Harness Findings
- Verified
src/lib/prisma.tscontains the runtimeDATABASE_URLenforcement viainitClient()— the safety net is intact. - Verified
prisma.config.tscontains the updated conditional datasource configuration. - Verified
package.jsoncontains the new postinstall script.
Unknowns or Needs Verification
- Windows compatibility: The
postinstallscript uses POSIX shell syntax (test -f ... && ... || true). This works on Linux/macOS and in the Docker container. If Windows development is a requirement, this could be addressed separately (e.g., via a JS-based postinstall script or a platform-conditional approach). Not blocking for the current Debian-based target documented in the repository.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
"postinstall": "prisma generate"so a fresh clone / any schema change never leaves a stale client.prisma.config.tsthrowing whenDATABASE_URLis unset (it's loaded byprisma generate, which needs only the schema) — supplydatasource.urlonly when present.Why
On a fresh checkout,
tsc/test/devfailed withProperty 'groomingRun' is missing on PrismaClient(stale generated client) until you manuallynpm run db:generate. The throw inprisma.config.tsalso meantgenerateitself failed on a machine with no env. Runtime still enforcesDATABASE_URLviasrc/lib/prisma.ts; migrate/deploy still read it from env.Verification
DATABASE_URLunset:prisma generatenow succeeds (previously threw).tsc --noEmit→ exit 0.Closes #499