Choose your preferred database setup method. We'll walk through each option.
Pros:
- ✅ Easiest setup (one command)
- ✅ No PostgreSQL installation needed
- ✅ Easy to reset/recreate
- ✅ Works on all operating systems
Prerequisites:
- Docker Desktop installed (Download here)
# Navigate to your project directory
cd raff-setup
# Start PostgreSQL container
docker-compose up -d
# Verify it's running
docker psExpected output:
CONTAINER ID IMAGE STATUS PORTS
abc123def456 postgres:16-alpine Up 10 seconds 0.0.0.0:5432->5432/tcp
# Copy the template
cp .env.local.template .env.localYour .env.local already has the correct credentials:
DATABASE_URL="postgresql://raff:raff_dev_password_2024@localhost:5432/raff"# Generate a random secret
openssl rand -base64 32Copy the output and paste it in .env.local:
NEXTAUTH_SECRET="your_generated_secret_here"# Install dependencies
npm install
# Generate Prisma Client
npm run db:generate
# Create database tables
npm run db:pushExpected output:
✔ Generated Prisma Client
✔ Database synchronized
# Open Prisma Studio
npm run db:studioOpens browser at http://localhost:5555 - you should see your database tables!
# Start database
docker-compose up -d
# Stop database
docker-compose down
# Stop and remove all data (reset)
docker-compose down -v
# View logs
docker-compose logs postgres
# Connect to database directly
docker exec -it raff-postgres psql -U raff -d raffPros:
- ✅ No local setup
- ✅ Free tier (500MB storage)
- ✅ Already hosted and managed
- ✅ Web-based SQL editor
Cons:
⚠️ Requires internet connection⚠️ Slight latency (cloud-based)
- Go to https://supabase.com
- Click "Start your project"
- Sign up with GitHub/Google
- Click "New Project"
Fill in the details:
- Name:
raff-dev - Database Password: Create a strong password (save it!)
- Region: Choose closest to Saudi Arabia (e.g., Singapore)
- Pricing Plan: Free
Click "Create new project" (takes ~2 minutes)
- In your Supabase project, go to Settings → Database
- Scroll to Connection String → URI
- Copy the connection string
It looks like:
postgresql://postgres.xxxxxxxxxxxxx:[YOUR-PASSWORD]@aws-0-ap-southeast-1.pooler.supabase.com:6543/postgres
# Create .env.local
cp .env.local.template .env.localReplace the DATABASE_URL with your Supabase connection string:
DATABASE_URL="postgresql://postgres.xxxxx:[PASSWORD]@aws-0-ap-southeast-1.pooler.supabase.com:6543/postgres"Important: Add ?pgbouncer=true&connection_limit=1 at the end:
DATABASE_URL="postgresql://postgres.xxxxx:[PASSWORD]@aws-0-ap-southeast-1.pooler.supabase.com:6543/postgres?pgbouncer=true&connection_limit=1"openssl rand -base64 32Add to .env.local:
NEXTAUTH_SECRET="your_generated_secret"npm install
npm run db:generate
npm run db:pushGo to Supabase Dashboard → Table Editor - you should see your tables!
Pros:
- ✅ Full control
- ✅ Fastest (no Docker overhead)
- ✅ Professional setup
Cons:
⚠️ Requires PostgreSQL installation⚠️ OS-specific installation
# Install with Homebrew
brew install postgresql@16
# Start PostgreSQL
brew services start postgresql@16
# Create user and database
createuser -s raff
createdb -O raff raff# Install PostgreSQL
sudo apt update
sudo apt install postgresql postgresql-contrib
# Start service
sudo systemctl start postgresql
# Create user and database
sudo -u postgres createuser -s raff
sudo -u postgres createdb -O raff raff- Download PostgreSQL from https://www.postgresql.org/download/windows/
- Run installer (keep default port 5432)
- Remember the password you set for
postgresuser - Open pgAdmin 4 or use command line to create database
Update .env.local:
DATABASE_URL="postgresql://raff:@localhost:5432/raff"Then run:
npm install
npm run db:generate
npm run db:push| Option | Best For | Setup Time |
|---|---|---|
| Docker | Most developers | 2 minutes |
| Supabase | Quick start, no local setup | 5 minutes |
| Local PostgreSQL | Production-like environment | 10 minutes |
After setup, verify everything works:
# 1. Check database connection
npm run db:studio
# 2. Start dev server
npm run dev
# 3. In another terminal, test database
npx tsx -e "
import { PrismaClient } from '@prisma/client';
const p = new PrismaClient();
p.\$connect().then(() => console.log('✅ Connected!')).catch(e => console.error('❌', e));
"Expected: "✅ Connected!"
Docker:
docker-compose ps # Check if running
docker-compose up -d # Start if not runningSupabase:
- Check connection string has no spaces
- Verify password is correct
- Ensure
?pgbouncer=trueis at the end
Local:
# macOS/Linux
sudo systemctl status postgresql # Check if running
# Windows
services.msc # Check if PostgreSQL service is running# For Docker
docker-compose down -v
docker-compose up -d
npm run db:push
# For local PostgreSQL
createdb raff
npm run db:push# Find what's using it
lsof -i :5432 # macOS/Linux
netstat -ano | findstr :5432 # Windows
# Kill it or change Docker port in docker-compose.yml:
ports:
- "5433:5432" # Use 5433 instead
# Update .env.local
DATABASE_URL="postgresql://raff:raff_dev_password_2024@localhost:5433/raff"Once database is working:
- ✅ Database running
- ✅
.env.localconfigured - ✅
npm run db:pushsuccessful - ✅
npm run db:studioopens
You're ready for development! 🚀
Continue with the main setup guide: STEP_1_SETUP_CHECKLIST_NEXTJS15.md