Skip to main content

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?
  1. Stops and removes existing database container (if any)
  2. Creates a new PostgreSQL container with:
    • Database name: starter-kit
    • User: postgres
    • Password: postgres
    • Port: 5432
  3. Waits for database to be ready
  4. 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
  1. Download from PostgreSQL website
  2. Create a new database:
createdb starter-kit
  1. Update your .env.local with the connection string

Production Database

Using Neon

Neon provides serverless PostgreSQL with a generous free tier:

  1. Create account at neon.tech
  2. Create new project
  3. Copy the connection string
  4. 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
  1. Make changes to schema.ts
  2. Generate migration
  3. Apply migration
  4. Test your changes
Production Deployments

Always backup your database before running migrations in production!