Docs
    Database Configuration

    Database Configuration

    A quick overview on setting up Prisma with a PostgreSQL database.

    This guide provides a basic overview of using Prisma with a PostgreSQL database in your Next.js SaaS Starter.

    Prerequisites

    This guide assumes you have a PostgreSQL database set up and running. If you need help setting up a PostgreSQL database, refer to the official documentation.

    1. Install Prisma

    bun install -D prisma
    bun install @prisma/client

    2. Initialize Prisma

    Run the following command to initialize Prisma in your project:

    bunx prisma init

    This creates a prisma directory with the following files:

    prisma/
    └── schema.prisma
    .env
     

    3. Configure Schema

    Edit the schema.prisma file to define your database schema:

    prisma/schema.prisma
     
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
     
    generator client {
      provider = "prisma-client-js"
    }
     
    model User {
      id        Int      @id @default(autoincrement())
      email     String   @unique
      name      String?
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    }
     

    4. Set Database URL

    Add your database URL to the .env file:

    .env
    DATABASE_URL="postgresql://user:password@localhost:5432/dbname"

    5. Run Migrations

    Run the following command to create the database tables:

     
    bunx prisma migrate dev --name init

    6. Prisma Studio

    Run the following command to open Prisma Studio:

    bunx prisma studio

    Additional Resources