78 lines
2.0 KiB
Plaintext
78 lines
2.0 KiB
Plaintext
// This is your Prisma schema file,
|
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
|
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
generator typegraphql {
|
|
provider = "typegraphql-prisma-nestjs"
|
|
output = "../src/type-graphql/generated"
|
|
}
|
|
|
|
datasource db {
|
|
// provider = "postgresql"
|
|
provider = "sqlite"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
model User {
|
|
id Int @id @default(autoincrement())
|
|
email String @unique
|
|
password String @omit
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @default(now())
|
|
role UsersRoles[]
|
|
product Product[]
|
|
|
|
@@allow("create,read", true)
|
|
@@allow("update", auth() == this && future().email == email)
|
|
}
|
|
|
|
model Role {
|
|
id Int @id @default(autoincrement())
|
|
name String @unique
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @default(now())
|
|
permission Permission[]
|
|
user UsersRoles[]
|
|
}
|
|
|
|
model Permission {
|
|
id Int @id @default(autoincrement())
|
|
name String @unique
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @default(now())
|
|
role Role @relation(fields: [roleId], references: [id])
|
|
roleId Int
|
|
}
|
|
|
|
model UsersRoles {
|
|
user User @relation(fields: [userId], references: [id])
|
|
userId Int
|
|
role Role @relation(fields: [roleId], references: [id])
|
|
roleId Int
|
|
assignedAt DateTime @default(now())
|
|
assignedBy String
|
|
@@id([userId, roleId])
|
|
}
|
|
|
|
model Product {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
title String
|
|
published Boolean @default(false)
|
|
author User @relation(fields: [authorId], references: [id])
|
|
authorId Int
|
|
|
|
// author has full access
|
|
@@allow('all', auth() == author)
|
|
|
|
// logged-in users can view published posts
|
|
@@allow('read', auth() != null && published)
|
|
}
|