Database Setup with Neon

How to create a Neon Postgres project and connect it to BloggFast.

Last updated:

What is Neon?

Neon is a serverless Postgres platform that scales to zero when not in use, making it cost-effective for new or low-traffic projects. BloggFast uses Neon for two things:

  • Primary database — stores articles, categories, authors, tags, users, subscribers, analytics, AI settings, and audit logs via Prisma 7
  • Authentication — via Neon Auth, which provides cookie-based session management integrated with your Neon project

BloggFast uses the @prisma/adapter-neon driver adapter with @neondatabase/serverless for WebSocket-based connections, which is required for serverless environments like Vercel Edge Functions.

Create a Neon project

  1. Sign up at neon.tech
  2. Click New Project
  3. Name it (e.g., my-blog), choose a region close to your users, and select Postgres 16
  4. Click Create Project

Neon will provision a new Postgres instance and show you the connection details.

Connection strings (pooled vs direct)

Neon provides two types of connection strings — both are needed:

TypeVariableWhen to use
Pooled (with pgBouncer)DATABASE_URLRuntime queries in production and development — efficient connection pooling for serverless
Direct (no pgBouncer)DATABASE_URL_UNPOOLEDPrisma migrations, seeding, and Prisma Studio — requires a persistent connection

From your Neon dashboard → Connection Details, copy both strings:

.env.local
# Pooled (hostname contains -pooler)
DATABASE_URL=postgresql://user:pass@ep-xxx-pooler.region.aws.neon.tech/neondb?channel_binding=require&sslmode=require

# Direct (no -pooler in hostname)
DATABASE_URL_UNPOOLED=postgresql://user:pass@ep-xxx.region.aws.neon.tech/neondb?sslmode=require

Warning

Never use the pooled connection string for Prisma migrations. The pooled connection goes through pgBouncer in transaction mode, which doesn't support the persistent connections Prisma needs for migrate dev. Always use DATABASE_URL_UNPOOLEDfor migrations.

Run Prisma migrations

With your connection strings configured, apply the schema to your Neon database:

bash
npm run db:migrate
# This runs: prisma migrate dev

This creates all database tables defined in prisma/schema.prisma. You'll see output confirming each migration was applied. The schema includes 17 models covering everything from articles to email subscribers.

Alternatively, for a quick schema push without migration history:

bash
npm run db:push
# This runs: prisma db push

Tip

After any schema change, regenerate the Prisma client types: npm run db:generate (runs prisma generate). This is done automatically during npm run build.

Seed the database

BloggFast includes a comprehensive seed script that creates starter categories, authors, AI settings, and site settings:

bash
npm run db:seed
# This runs: npx tsx prisma/seed.ts

Run this after your initial migration. It's safe to re-run — the seed script uses upsert operations to avoid duplicates.