Back to articles
Next.js 16 SaaS Database Schema with Prisma: Users, Subscriptions, and AI Chat
How-ToSystems

Next.js 16 SaaS Database Schema with Prisma: Users, Subscriptions, and AI Chat

via Dev.to Tutorialhuangyongshan46-a11y

A good database schema is the foundation of any SaaS. Here's the complete Prisma schema I use for every new project — handling users, OAuth accounts, subscriptions, and AI chat. The full schema generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") } model User { id String @id @default(cuid()) name String? email String @unique emailVerified DateTime? image String? password String? role Role @default(USER) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt accounts Account[] sessions Session[] subscription Subscription? conversations Conversation[] } model Account { userId String type String provider String providerAccountId String refresh_token String? access_token String? expires_at Int? token_type String? scope String? id_token String? session_state String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@id([provider

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
2 views

Related Articles