nextjs-add-prisma-db
Setup Prisma ORM with PostgreSQL in a Next.js project with schema, migrations, and seed data
- License 许可
- MIT
- 所属仓库
- zuzu59/z-skills
- 最近更新
- 2026-09-30
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- nextjs-add-prisma-db
- description
- Setup Prisma ORM with PostgreSQL in a Next.js project with schema, migrations, and seed data
03 SKILL.md 正文
<objective> Setup Prisma in the current Next.js project with a production-ready database configuration.
This creates a complete database layer including schema, migrations, client helper, seed script, and API routes for verification. Designed for projects using Neon PostgreSQL. </objective>
<context>
Project structure: !ls -la
Package manager: !cat package.json | grep -A2 '"packageManager"'
Existing prisma config: !ls prisma/ 2>/dev/null || echo "No prisma folder yet"
TypeScript config: !cat tsconfig.json | head -30
</context>
<process>
Phase 1: Information Gathering
-
Ask for table structure - Prompt user to describe ONE simple table to verify Prisma works:
- Table name and purpose
- Fields with types (String, Int, DateTime, Boolean)
- Example: "Post table with id, title, content, published, createdAt"
-
Inspect existing structure - Before coding:
- Check if
src/folder exists - Read
tsconfig.jsonfor path aliases - Identify where
lib/folder should be created
- Check if
Phase 2: Installation
-
Install dependencies:
pnpm add prisma @prisma/client pnpm add -D tsx npx prisma init -
Configure database provider - Update
prisma/schema.prisma:- Set provider to "postgresql"
- Configure generator output path based on project structure
Phase 3: Schema & Configuration
-
Create schema - Add the user-defined table with:
idas String with@id @default(cuid())- User-specified fields
createdAt DateTime @default(now())updatedAt DateTime @updatedAt
-
Configure exclusions:
- Add generated folder to
.eslintignore - Add generated folder to
tsconfig.jsonexclude array
- Add generated folder to
-
Create Prisma client helper - Create singleton pattern in
lib/prisma.ts:import { PrismaClient } from "@/generated/client"; const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined; }; export const prisma = globalForPrisma.prisma ?? new PrismaClient(); if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; -
Create prisma.config.ts - Root configuration:
import path from "node:path"; import { defineConfig } from "prisma/config"; export default defineConfig({ schema: path.join("prisma", "schema.prisma"), migrations: { seed: `tsx prisma/seed.ts`, }, });
Phase 4: Data & Verification
-
Create seed script -
prisma/seed.tswith 5-10 realistic records -
Run migrations:
npx prisma generate npx prisma migrate dev --name init npx prisma db seed -
Create example API route -
app/api/example/route.ts:- GET endpoint fetching all records
- POST endpoint creating new record
- Proper error handling
-
Add package.json scripts:
{ "db:generate": "prisma generate", "db:push": "prisma db push", "db:migrate": "prisma migrate dev", "db:studio": "prisma studio", "db:seed": "prisma db seed" }
Phase 5: Documentation
- Update CLAUDE.md with:
- Database provider and connection info
- Schema overview
- Available db scripts </process>
<constraints> FORBIDDEN - Do not create:
- User, Account, Session, VerificationToken tables (auth tables)
- Any user-related fields or foreign keys
- More than ONE table (keep it minimal for verification)
REQUIRED:
- Adapt paths to existing project structure
- Use cuid() for IDs, not uuid or auto-increment
- Configure generator output path correctly
- Create seed data with realistic values </constraints>
<success_criteria>
pnpm prisma generatecompletes without errorspnpm prisma migrate devcreates migration successfullypnpm prisma db seedpopulates database- API route returns data when called
- No TypeScript or ESLint errors in generated files </success_criteria>
04 同仓库更多 Skills
writing-great-skills
Reference for writing and editing skills well — the vocabulary and principles that make a skill predictable.
use-style
Apply named visual style guides to landing pages, app shells, and UI. Use for $use-style, /useskill, list styles, or styles like ios-app, grid, vercel, black-grid, stripe, linear, raycast, gumroad, dusk, or luma.
use-goal
Use when the user asks to create, draft, set, start, or refine a Codex or Claude Code `/goal` objective for persistent multi-turn work.
use-fable
Orchestrator mode for Fable: Fable thinks, plans, and reviews while Codex CLI and subagents execute all heavy work. Use when the user invokes /use-fable, says 'use fable', 'fable mode', 'orchestrator mode', or wants to save Fable tokens/rate limits.
use-delegate
Delegation mode: the host agent (Claude or Codex) plans and reviews while heavy work runs on cheap executors: OpenCode Kimi K3, Codex GPT-5.6 terra/sol. Use when the user invokes /use-delegate, says 'use delegate', 'delegate mode', 'orchestrator mode', or wants to save tokens/rate limits.
use-artifacts
Create Claude-style local HTML artifacts under ~/.agents/artifacts. Use for plans, prototypes, visualizations, dashboards, diagrams, options, or substantial reusable content, with a portable local runtime and no Anthropic API.