Docs
Database Customization

Database Customization

NextAdmin uses Prisma as its ORM, which provides a powerful and flexible way to manage your database schema. This allows you to easily customize the database structure to fit your specific needs.

Customizing the Database Schema

You can modify the Prisma schema file located at prisma/schema.prisma to add new models, fields, or relationships. For example, if you want to add a Profile model that is related to the User model, you can do it like this:

prisma/schema.prisma
generator client {
  provider = "prisma-client"
  output   = "./generated/prisma"
}
 
datasource db {
  provider = "postgresql"
}
 
model User {
  id            String    @id
  name          String
  email         String
  emailVerified Boolean   @default(false)
  coverImage    String?
  phone         String?
  sessions      Session[]
  accounts      Account[]
 
  @@unique([email])
  @@map("user")
}
 
// ... other models
 
model Profile {
  id    String @id @default(cuid())
  user  User   @relation(fields: [userId], references: [id])
  userId String
}

Using Separate Schema Files

If you prefer to keep your schema organized, you can create separate Prisma schema files into the prisma/schema directory and Prisma will automatically merge them. For example, you can create a profile.prisma file for the Profile model:

prisma/schema/profile.prisma
model Profile {
  id    String @id @default(cuid())
  user  User   @relation(fields: [userId], references: [id])
  userId String
}
prisma/schema.prisma
generator client {
  provider = "prisma-client"
  output   = "./generated/prisma"
}
 
datasource db {
  provider = "postgresql"
}