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
- PostgreSQL database (local or hosted)
- Prisma CLI
- Database URL added to your
.envfile
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/client2. Initialize Prisma
Run the following command to initialize Prisma in your project:
bunx prisma initThis 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:
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:
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 init6. Prisma Studio
Run the following command to open Prisma Studio:
bunx prisma studio