Skip to content

Refresh: Building a REST API with NestJS and Prisma (Prisma 7 / NestJS 11)#7977

Open
vanrensbird wants to merge 3 commits into
mainfrom
blog/refresh-nestjs-prisma-rest-api
Open

Refresh: Building a REST API with NestJS and Prisma (Prisma 7 / NestJS 11)#7977
vanrensbird wants to merge 3 commits into
mainfrom
blog/refresh-nestjs-prisma-rest-api

Conversation

@vanrensbird

@vanrensbird vanrensbird commented Jun 25, 2026

Copy link
Copy Markdown

What this is

A content refresh of the existing post Building a REST API with NestJS and Prisma (/blog/nestjs-prisma-rest-api-7D056s1BmOL0). Same URL, same author, updated for the current stack.

Why

  • The post is from June 2022 and its code targets Prisma 3.x / Postgres 13.5 — significantly out of date.
  • It ranks page 2 (pos ~11) for high-intent evergreen terms (nestjs prisma, prisma nestjs, nestjs prisma postgres) with real search demand. A modern, working version is a strong candidate to move up.

What changed (all verified by running it)

Area Before After (Prisma 7 / NestJS 11)
Generator prisma-client-js prisma-client + output + moduleFormat = "cjs"
Config URL in schema prisma.config.ts (URL + dotenv)
Client connection bare new PrismaClient() driver adapter @prisma/adapter-pg (now required)
Env loading engine read .env @nestjs/config ConfigModule
Seeding package.json + ts-node prisma.config.ts migrations.seed + tsx
Imports @prisma/client ../../generated/prisma/client
Swagger @nestjs/swagger + swagger-ui-express @nestjs/swagger only (bundled in v11)
Database Docker postgres:13.5 leads with Prisma Postgres / npx prisma dev; Docker bumped to postgres:17

Verification

Built and ran the full tutorial end-to-end on NestJS 11.0, Prisma 7.8, @prisma/adapter-pg 7.8, @nestjs/swagger 11.4, Node 24. All CRUD endpoints (GET /articles, /articles/drafts, /articles/:id, POST, PATCH, DELETE) and the Swagger UI / OpenAPI JSON were confirmed working.

Note

One untested path: prisma migrate dev was not run end-to-end locally — the local prisma dev server only exposes template1, which rejects the migration shadow-DB step (P1017). The schema/client path was verified with prisma db push instead. migrate dev is the correct command for readers on Docker Postgres or cloud Prisma Postgres and is what the post documents; it just wasn't observed succeeding here. Worth a reviewer confirming against a standard Postgres.

Preserved / notes for reviewers

  • URL/slug unchanged — keeps the page's ranking history.
  • Author unchanged (Tasin Ishmam) and publish date kept (2022-06-03) with a prominent "Updated (June 2026)" note, matching the existing refresh convention. Consider whether to also bump a lastUpdated/sitemap date for the freshness signal.
  • Images unchanged — reuses the existing imgs/ assets; no new images needed.
  • metaTitle / metaDescription updated to mention Prisma 7.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Updated the tutorial to target newer Prisma ORM and NestJS versions.
    • Refreshed PostgreSQL setup (including Docker), Prisma configuration, migrations, and seeding to match the latest workflows.
    • Updated Prisma schema and generated client guidance for the current driver-adapter approach.
    • Revised CRUD instructions and Swagger/OpenAPI examples, including response schema typing and endpoint documentation.

@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blog Ready Ready Preview, Comment Jun 26, 2026 12:24pm
docs Ready Ready Preview, Comment Jun 26, 2026 12:24pm
eclipse Ready Ready Preview, Comment Jun 26, 2026 12:24pm
site Ready Ready Preview, Comment Jun 26, 2026 12:24pm

Request Review

@vanrensbird vanrensbird requested a review from ankur-arch June 25, 2026 08:02
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 928ae066-800f-45cc-9cfa-380576f2bc89

📥 Commits

Reviewing files that changed from the base of the PR and between 20d5fcc and db05b4e.

📒 Files selected for processing (1)
  • apps/blog/content/blog/nestjs-prisma-rest-api-7D056s1BmOL0/index.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/blog/content/blog/nestjs-prisma-rest-api-7D056s1BmOL0/index.mdx

Walkthrough

The tutorial was updated for Prisma 7 and NestJS 11. It replaces older Prisma setup, seeding, service, CRUD, and Swagger instructions with Prisma config, the PostgreSQL driver adapter, generated-client imports, updated NestJS bootstrap, and revised API response typing.

Changes

Prisma 7 tutorial refresh

Layer / File(s) Summary
Project framing and Prisma setup
apps/blog/.../index.mdx
Metadata, intro copy, prerequisites, scaffold text, PostgreSQL provisioning, Prisma config, and Prisma setup guidance are updated for Prisma 7 and NestJS 11.
Schema and migration flow
apps/blog/.../index.mdx
The schema walkthrough, migration command, and generated-client output are updated to match Prisma 7 configuration and output paths.
Seeding with PrismaPg
apps/blog/.../index.mdx
The seeding section adds the PostgreSQL adapter, updates prisma/seed.ts, moves seed config into prisma.config.ts, and refreshes the seed output.
Nest bootstrap and Prisma service
apps/blog/.../index.mdx
PrismaService now uses PrismaPg and connects on module init, while AppModule, main.ts, and module import paths are updated for the new bootstrap flow.
Article CRUD methods
apps/blog/.../index.mdx
Article handlers and service methods now use Prisma-backed published, draft, lookup, create, update, and delete queries.
Swagger and response typing
apps/blog/.../index.mdx
Article entity typing, route response decorators, and the closing summary are updated for the generated Prisma client and OpenAPI flow.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: a tutorial refresh for NestJS 11 and Prisma 7.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@argos-ci

argos-ci Bot commented Jun 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No changes detected - Jun 26, 2026, 12:31 PM

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/blog/content/blog/nestjs-prisma-rest-api-7D056s1BmOL0/index.mdx`:
- Around line 240-256: The `prisma.config.ts` example in the blog post is out of
sync with the current Prisma 7 scaffold. Update the snippet in the section
around the `prisma.config.ts` walkthrough to match the generated shape by using
`env` from `prisma/config` and `url: env("DATABASE_URL")` instead of
`process.env.DATABASE_URL`, and make the same alignment in the later duplicate
example so readers see the exact current output from `prisma init`.
- Around line 325-338: The “Migrate the database” section currently tells
readers to run prisma migrate dev without accounting for Prisma 7’s required
shadow database, so local migrations will fail. Update this workflow by either
instructing readers to export SHADOW_DATABASE_URL from the prisma dev output and
wire it into prisma.config.ts alongside DATABASE_URL, or replace the local
example command with prisma db push and keep migrate dev for the
docker/local-postgres path. Make sure the guidance in the migration section
matches the Prisma 7 setup shown earlier in the article.
- Around line 383-387: The Prisma 7 install snippet in the NestJS Prisma REST
API article only mentions `@prisma/adapter-pg`, which can leave readers missing
the pg driver at runtime. Update the installation guidance in the section
describing Prisma Client and the PostgreSQL adapter to include pg alongside
`@prisma/adapter-pg`, and mention `@types/pg` for TypeScript projects if needed.
Keep the advice aligned with the Prisma Client setup shown in this part of the
article so readers install the adapter and its driver together.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 261014d5-bcda-48b3-9242-2eb4f6df0e83

📥 Commits

Reviewing files that changed from the base of the PR and between 7ad9022 and 20d5fcc.

📒 Files selected for processing (1)
  • apps/blog/content/blog/nestjs-prisma-rest-api-7D056s1BmOL0/index.mdx

Comment thread apps/blog/content/blog/nestjs-prisma-rest-api-7D056s1BmOL0/index.mdx Outdated
Verified the whole tutorial against Prisma 7.8 / NestJS 11 with a real
Prisma Postgres database (npx create-db): scaffolded the app, ran
migrate dev + seed, and exercised all CRUD endpoints + Swagger.

Changes from that validation and the review:
- Add the missing `@prisma/client` install. The generated Client imports
  `@prisma/client/runtime/client` at runtime; without it the app fails
  with "Cannot find module '@prisma/client/runtime/client'". (Found by
  running it; not flagged in review.)
- prisma.config.ts: match the actual `prisma init` output
  (`process.env["DATABASE_URL"]` + generated header comment). The review
  suggested the `env()` helper, but 7.8 scaffolds `process.env`.
- Make `migrate dev` work on the recommended path: lead Option A with
  `npx create-db` (cloud Prisma Postgres, where migrate dev works), and
  note that the local `npx prisma dev` server needs `db push` instead
  (migrate dev fails P1017 there even with a shadow URL).
- Note that `@prisma/adapter-pg` pulls in `pg` + `@types/pg`, so no
  separate `pg` install is needed (review suggested adding it; it ships
  as a dependency in 7.8).
- Add a closing "What's next: Prisma Next" callout (the next major
  version, Prisma 8) inviting readers to try it.
- Remove em/en dashes from prose per the docs writing style.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants