Prisma Setup & Migrations
How to set up Prisma, run database migrations, and manage schema changes.
Last updated:
Prisma configuration
BloggFast uses Prisma 7 with the driverAdapters preview feature enabled. This allows Prisma to use Neon's serverless WebSocket driver (@neondatabase/serverless) via @prisma/adapter-neon, which is required for serverless and edge environments.
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
datasource db {
provider = "postgresql"
}The DATABASE_URL is read from your environment. Notice the datasource does not hardcode the URL — it's always pulled from the environment variable at runtime.
Generate the Prisma client
After installing dependencies and setting DATABASE_URL, generate the typed client:
npm run db:generate
# Runs: prisma generateThis creates the typed client in node_modules/.prisma/client based on your schema. This step is automatically run during npm run build.
Run migrations
Apply the initial schema to your Neon database:
npm run db:migrate
# Runs: prisma migrate devThis creates all the tables defined in prisma/schema.prisma. You'll see output confirming each migration was applied. For a quick schema sync without migration history (useful in early development):
npm run db:push
# Runs: prisma db pushWarning
DATABASE_URL_UNPOOLED for migrations. The pooled connection string (via pgBouncer) does not support the persistent connections Prisma needs during migrations. Make sure your .env.local has both connection strings set.Prisma Studio
Open the visual database browser:
npm run db:studio
# Opens at http://localhost:5555Studio lets you create, read, update, and delete records directly — useful for seeding test data, granting admin roles to users, or debugging database state.
Schema overview
The BloggFast Prisma schema (prisma/schema.prisma) includes these models:
| Model | Purpose |
|---|---|
User | Authenticated users with roles (USER, EDITOR, ADMIN) |
Author | Article bylines with bio, avatar, social links, and specialties |
Category | Article categories with slug and color |
Tag | Article tags for fine-grained classification |
Article | Core article model — title, subtitle, body (markdown), status, SEO fields, cover image, and social counts |
ArticleTag | Many-to-many join table for article ↔ tag relationships |
Comment | User comments on articles with moderation status |
SavedArticle | User-saved articles (bookmarks) |
LikedArticle | User-liked articles |
UserInterest | User interest categories (for personalization onboarding) |
ArticleView | Article view analytics with session IDs |
ArticleGenerationRequest | AI generation history — prompt, status, result data |
AuditLog | Admin action audit trail |
SiteSettings | Singleton site config (name, description, logo, social links) |
AiSettings | Singleton AI config (model, image model, system prompt, tone, word count) |
Subscriber | Email newsletter subscribers with full status tracking |
SubscriberEvent | Email event log (subscribed, confirmed, bounced, etc.) |
Making schema changes
- Edit
prisma/schema.prisma - Run
npm run db:migrateto generate and apply a migration - Run
npm run db:generateif you need updated TypeScript types immediately
Production migrations
On Vercel, migrations run automatically during the build step via the build command:
# Build command in package.json scripts:
prisma generate && next buildFor applying pending migrations in production, use prisma migrate deploy (not prisma migrate dev). You can add this to your Vercel build command or run it manually from the CLI with production environment variables:
# Run from your local machine with production DATABASE_URL
DATABASE_URL="your-production-db-url" npx prisma migrate deploy