Skip to main content

Overview

Home Manager uses PostgreSQL as its database and Prisma as the ORM (Object-Relational Mapping) tool. This guide covers database setup, schema management, and migrations.

Database Requirements

Minimum Requirements:
  • PostgreSQL 12 or higher
  • At least 100MB storage (scales with usage)
  • Support for UUID generation

PostgreSQL Setup

Option 1: Local PostgreSQL Installation

1

Install PostgreSQL

brew install postgresql@15
brew services start postgresql@15
2

Create Database

# Connect to PostgreSQL
psql -U postgres

# Create database
CREATE DATABASE homemanager;

# Create user (optional)
CREATE USER homemanager_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE homemanager TO homemanager_user;

# Exit psql
\q
3

Set DATABASE_URL

.env.local
DATABASE_URL="postgresql://postgres:password@localhost:5432/homemanager"

Option 2: Cloud PostgreSQL Providers

1

Create Project

  1. Sign up at supabase.com
  2. Click New Project
  3. Choose your organization
  4. Enter project details and password
  5. Select a region close to your users
2

Get Connection String

  1. Go to Project SettingsDatabase
  2. Copy the Connection string under Connection info
  3. Replace [YOUR-PASSWORD] with your database password
DATABASE_URL="postgresql://postgres:[YOUR-PASSWORD]@db.example.supabase.co:5432/postgres"
3

Enable Connection Pooling (Recommended)

For production, use Supabase’s connection pooler:
DATABASE_URL="postgresql://postgres:[YOUR-PASSWORD]@db.example.supabase.co:6543/postgres?pgbouncer=true"
Supabase offers a generous free tier with 500MB database storage.

Prisma Schema Overview

Home Manager’s database schema includes the following models:
prisma/schema.prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model ShoppingItem {
  id           String   @id @default(uuid())
  householdId  String
  name         String
  category     String
  position     Int      @default(0)
  checked      Boolean  @default(false)
  createdAt    DateTime @default(now())
}

model BillsItem {
  id           String   @id @default(uuid())
  householdId  String
  name         String
  amount       Float
  dueDate      DateTime
  category     String
  position     Int      @default(0)
  checked      Boolean  @default(false)
  createdAt    DateTime @default(now())
}

model ChoresItem {
  id           String   @id @default(uuid())
  householdId  String
  name         String
  assignee     String
  description  String
  position     Int      @default(0)
  checked      Boolean  @default(false)
  recurrence   String   @default("none")
  createdAt    DateTime @default(now())
}

model MaintenanceItem {
  id           String   @id @default(uuid())
  householdId  String
  title        String
  category     String
  description  String
  position     Int      @default(0)
  checked      Boolean  @default(false)
  recurrence   String   @default("none")
  createdAt    DateTime @default(now())
}

model Notification {
  id           String   @id @default(uuid())
  householdId  String
  type         String
  title        String
  body         String
  read         Boolean  @default(false)
  createdAt    DateTime @default(now())
}

model Household {
  id        String             @id @default(cuid())
  name      String
  members   HouseholdMember[]
  createdAt DateTime           @default(now())
}

model HouseholdMember {
  id           String     @id @default(cuid())
  householdId  String
  userId       String?
  invitedEmail String?
  role         String
  status       String?    @default("pending")
  Household    Household  @relation(fields: [householdId], references: [id])

  @@unique([householdId, userId])
}

model AuditLog {
  id        String   @id @default(cuid())
  userId    String
  userName  String
  action    String
  itemType  String
  itemName  String
  createdAt DateTime @default(now())
}

Key Models

  • ShoppingItem - Shopping list items
  • BillsItem - Bill tracking with amounts and due dates
  • ChoresItem - Household chores with assignees
  • MaintenanceItem - Home maintenance tasks
  • Notification - User notifications and activity feed
  • Household - Household groups
  • HouseholdMember - Members and invitations
  • AuditLog - Activity tracking and audit trail

Database Initialization

First-Time Setup

1

Install Dependencies

npm install
This automatically runs prisma generate via the postinstall script.
2

Push Schema to Database

For development and quick setup:
npx prisma db push
This command:
  • Creates all tables based on your schema
  • Updates existing tables if schema changed
  • Generates Prisma Client
  • Does NOT create migration files
db push is great for development but should not be used in production. Use migrations instead.
3

Verify Database

npx prisma studio
Opens Prisma Studio at http://localhost:5555 where you can:
  • View all tables
  • Inspect data
  • Manually add/edit records

Using Migrations (Production)

For production deployments, use migrations to track schema changes:
1

Create Initial Migration

npx prisma migrate dev --name init
This command:
  • Creates a prisma/migrations directory
  • Generates SQL migration files
  • Applies the migration to your database
  • Generates Prisma Client
2

Apply Migrations in Production

npx prisma migrate deploy
Use this in your production deployment:
  • Applies pending migrations
  • Does NOT generate new migrations
  • Safe for CI/CD pipelines

Common Prisma Commands

# Generate Prisma Client after schema changes
npx prisma generate

Build Script Integration

Home Manager’s package.json includes Prisma in the build process:
package.json
{
  "scripts": {
    "dev": "next dev --turbopack",
    "build": "prisma generate && next build",
    "start": "next start",
    "postinstall": "prisma generate"
  }
}
  • build: Generates Prisma Client before building Next.js
  • postinstall: Auto-generates client after npm install
No manual Prisma commands needed during normal development. The scripts handle it automatically.

Production Deployment Workflow

1

Set Environment Variables

Configure DATABASE_URL in your hosting platform.
2

Apply Migrations

npx prisma migrate deploy
Add this to your deployment script or CI/CD pipeline before starting the application.
3

Build Application

npm run build
Prisma Client is automatically generated during the build.
4

Start Application

npm start

Database Connection Pooling

For production environments with high traffic, use connection pooling:
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
  directUrl = env("DIRECT_DATABASE_URL") // Optional: for migrations
}
Most cloud providers (Supabase, Neon, Railway) offer built-in connection pooling.

Troubleshooting

Cannot Connect to Database

Error: Can't reach database server at host:portSolutions:
  • Check DATABASE_URL is correct
  • Verify database server is running
  • Check firewall/security group settings
  • For cloud databases, ensure IP is allowlisted
  • Test connection with psql or database client

Migration Issues

Error: Migration failed to applySolutions:
  • Check database permissions
  • Ensure no conflicting schema changes
  • Review migration SQL files in prisma/migrations
  • Use prisma migrate resolve for stuck migrations
  • Reset database with prisma migrate reset (development only)

Prisma Client Generation Fails

Error: Prisma Client could not be generatedSolutions:
  • Run npm install to ensure dependencies are installed
  • Check prisma/schema.prisma syntax
  • Verify DATABASE_URL is set
  • Delete node_modules/.prisma and regenerate
  • Clear npm cache: npm cache clean --force

Schema Drift

Error: Database schema is out of syncSolutions:
  • Run prisma db pull to sync schema from database
  • Run prisma migrate dev to apply pending migrations
  • Use prisma migrate deploy in production
  • Check migration history: prisma migrate status

Best Practices

Use Migrations in Production

Always use prisma migrate deploy instead of db push for production databases to maintain schema history.

Connection Pooling

Enable connection pooling for production to handle multiple concurrent requests efficiently.

Regular Backups

Set up automated backups for your PostgreSQL database. Most cloud providers offer this built-in.

Monitor Performance

Use database monitoring tools to track query performance and connection usage.

Next Steps

Environment Variables

Configure all required environment variables

Deployment Guide

Deploy your application to production

Build docs developers (and LLMs) love