Appearance
PostgreSQL
By default, NextSaasPilot uses MongoDB as its database. However, if you prefer PostgreSQL, you can easily switch to it and manage your database with Prisma. This guide explains how to use PostgreSQL with NextSaasPilot.
Quick Start with PostgreSQL Branch
NextSaasPilot provides a dedicated PostgreSQL branch for quick setup. You can checkout this branch to get started with PostgreSQL immediately
1. Update Prisma Schema (prisma/schema.prisma)
Edit your prisma/schema.prisma file so that the datasource provider is set to postgresql. Make sure your models are using types and settings that work well with PostgreSQL.
prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id String @id @default(uuid())
name String?
email String? @unique
emailVerified DateTime?
password String?
image String?
accounts Account[]
customerId String?
priceId String?
isAdmin Boolean @default(false)
hasAccess Boolean @default(false)
subscribedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("users")
}
model Account {
id String @id @default(uuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@map("accounts")
}
model VerificationToken {
id String @id @default(uuid())
identifier String
token String
expires DateTime
@@unique([identifier, token])
@@map("verification_tokens")
}
model PasswordResetToken {
id String @id @default(uuid())
email String
token String @unique
expires DateTime
createdAt DateTime @default(now())
@@map("password_reset_tokens")
}2. Configure Your MongoDB Connection (.env)
Update the
DATABASE_URLin your.envfile to use your PostgreSQL connection string.Replace placeholders with your actual PostgreSQL connection details.
txt
# Example PostgreSQL connection string
DATABASE_URL="postgresql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]"