Created
June 30, 2023 15:30
-
-
Save cfigueiroa/a599828f18c3a19f38eb5362cb36aecf to your computer and use it in GitHub Desktop.
prisma schema example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is your Prisma schema file, | |
// learn more about it in the docs: https://pris.ly/d/prisma-schema | |
generator client { | |
provider = "prisma-client-js" | |
} | |
datasource db { | |
provider = "postgresql" | |
url = env("DATABASE_URL") | |
} | |
model User { | |
id String @id @default(uuid()) | |
age Int | |
name String | |
email String @unique | |
role Role @default(BASIC) | |
writtenPosts Post[] @relation("writtenPosts") | |
favoritPosts Post[] @relation("FavoritePosts") | |
userPreference UserPreference? | |
@@unique([name, email]) | |
@@index([email]) | |
} | |
model UserPreference { | |
id String @id @default(uuid()) | |
emailUpdates Boolean | |
user User @relation(fields: [userId], references: [id]) | |
userId String @unique | |
} | |
model Post { | |
id String @id @default(uuid()) | |
title String | |
averageRating Float | |
createdAt DateTime @default(now()) | |
updatedAt DateTime @updatedAt | |
author User @relation("writtenPosts", fields: [authorId], references: [id]) | |
authorId String | |
favoritedBy User? @relation("FavoritePosts", fields: [favoritedById], references: [id]) | |
favoritedById String? | |
categories Category[] | |
} | |
model Category { | |
id String @id @default(uuid()) | |
name String @unique | |
posts Post[] | |
} | |
enum Role { | |
BASIC | |
EDITOR | |
ADMIN | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment