Setting Up PostgreSQL
Local Development
The starter kit includes a setup script that uses Docker to quickly set up your local database:
pnpm setup-db
What does the setup script do?
- Stops and removes existing database container (if any)
- Creates a new PostgreSQL container with:
- Database name:
starter-kit
- User:
postgres
- Password:
postgres
- Port:
5432
- Database name:
- Waits for database to be ready
- Runs all migrations automatically
The script ensures a clean, consistent development environment.
Manual Setup Options
Using Docker Manually
docker run --name starter-kit-db \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_DB=starter-kit \
-p 5432:5432 \
-d postgres
Update your .env.local
:
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/starter-kit"
Local PostgreSQL Installation
- Download from PostgreSQL website
- Create a new database:
createdb starter-kit
- Update your
.env.local
with the connection string
Production Database
Using Neon
Neon provides serverless PostgreSQL with a generous free tier:
- Create account at neon.tech
- Create new project
- Copy the connection string
- Update your production environment:
DATABASE_URL="postgresql://[user]:[password]@[host]/[database]"
Alternative Providers
Migrations
After setting up your database, run migrations:
# Generate migration
pnpm drizzle-kit generate:pg
# Apply migration
pnpm db:push
Development Workflow
- Make changes to
schema.ts
- Generate migration
- Apply migration
- Test your changes
Production Deployments
Always backup your database before running migrations in production!