Skip to content

Instantly share code, notes, and snippets.

@knezdusan
Last active August 13, 2024 14:11
Show Gist options
  • Save knezdusan/7b5baa7f22fc434fa32ca91476672256 to your computer and use it in GitHub Desktop.
Save knezdusan/7b5baa7f22fc434fa32ca91476672256 to your computer and use it in GitHub Desktop.
Prisma schema.prisma example
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Client {
id String @id @default(cuid())
name String @unique
website String
status Status @default(TRIAL)
users User[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("client")
}
model User {
id String @id @default(cuid())
name String
email String @unique
password String @default("test1234")
role Role @default(USER)
posts Post[]
profile Profile?
client Client @relation(fields: [clientId], references: [id], onDelete: Cascade, onUpdate: Cascade)
clientId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([name])
@@index([role])
@@map("user")
}
model Profile {
id String @id @default(cuid())
bio String
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
userId String @unique
@@map("profile")
}
model Post {
id String @id @default(cuid())
title String
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id], onDelete: Cascade, onUpdate: Cascade)
authorId String
categories Category[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("post")
}
model Category {
id String @id @default(cuid())
name String
posts Post[]
@@map("category")
}
enum Role {
USER
ADMIN
}
enum Status {
ACTIVE
INACTIVE
TRIAL
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment