New

5 demos, 10+ applications, 50+ blocks, 30+ pages & much more

Documentation

Browse and explore docs

Prisma Schema

The database schema is defined in prisma/schema.prisma. It contains five models and two enums:

ModelTableDescription
PermissionpermissionsNamed permission definitions
RoleDefinitionrole_definitionsRole hierarchy with assigned permission names
ProfileprofilesUser profiles — id matches Supabase auth.users UUID
ProductproductsProduct catalog with price and stock
OrderordersPurchase orders linked to a Profile and a Product

Role Enum

Each profile is assigned one of the following roles:

USERADMINEDITORCOMMENTOR

Full Schema

generator client {
  provider = "prisma-client"
  output   = "../lib/generated/prisma"
}

datasource db {
  provider = "postgresql"
}

model Profile {
  id        String   @id           // same as Supabase auth.users id (UUID)
  email     String   @unique
  name      String?
  role      Role     @default(USER)
  orders    Order[]
  createdAt DateTime @default(now()) @map("created_at")

  @@map("profiles")
}

model Order {
  id           String      @id @default(cuid())
  productId    String      @map("product_id")
  product      Product     @relation(fields: [productId], references: [id])
  price        Float
  status       OrderStatus @default(PENDING)
  purchaseDate DateTime    @default(now()) @map("purchase_date")
  expireDate   DateTime    @map("expire_date")
  userId       String      @map("user_id")
  user         Profile     @relation(fields: [userId], references: [id], onDelete: Cascade)
  createdAt    DateTime    @default(now()) @map("created_at")
  review       Int?

  @@map("orders")
}

model Product {
  id          String   @id @default(cuid())
  name        String   @unique
  description String?
  price       Float
  stock       Int      @default(0)
  image       String?
  orders      Order[]
  createdAt   DateTime @default(now()) @map("created_at")
  updatedAt   DateTime @updatedAt @map("updated_at")

  @@map("products")
}

model Permission {
  id        String   @id @default(cuid())
  name      String   @unique
  createdAt DateTime @default(now()) @map("created_at")

  @@map("permissions")
}

model RoleDefinition {
  id          String   @id @default(cuid())
  name        String   @unique
  hierarchy   Int
  permissions String[]
  createdAt   DateTime @default(now()) @map("created_at")

  @@map("role_definitions")
}

enum Role {
  USER
  ADMIN
  COMMENTOR
  EDITOR
}

enum OrderStatus {
  PENDING
  PROCESSING
  COMPLETE
  CANCELLED
}