task-board/prisma/schema.prisma
2025-06-24 14:26:42 +04:00

250 lines
7.1 KiB
Plaintext

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id String @id @default(cuid())
name String?
email String @unique
emailVerified DateTime?
image String?
hashedPassword String?
accounts Account[]
sessions Session[]
workspaces Workspace[] @relation("WorkspaceOwner")
memberships Member[]
comments Comment[]
mentions Mention[] @relation("MentionedUser")
createdMentions Mention[] @relation("MentionCreator")
notifications Notification[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String?
access_token String?
expires_at Int?
token_type String?
scope String?
id_token String?
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model VerificationToken {
id String @id @default(cuid())
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
model Workspace {
id String @id @default(cuid())
name String
imageUrl String
inviteCode String @unique
userId String
owner User @relation(fields: [userId], references: [id], name: "WorkspaceOwner")
members Member[]
projects Project[]
tasks Task[]
epics Epic[]
mentions Mention[]
notifications Notification[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Member {
id String @id @default(cuid())
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspaceId String
user User @relation(fields: [userId], references: [id])
userId String
role MemberRole
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([workspaceId, userId])
Task Task[]
Epic Epic[]
}
model Project {
id String @id @default(cuid())
name String
imageUrl String
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspaceId String
tasks Task[]
epics Epic[]
boards Board[]
labels Label[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Board {
id String @id @default(cuid())
name String
description String?
project Project @relation(fields: [projectId], references: [id])
projectId String
tasks Task[]
position Float @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Label {
id String @id @default(cuid())
labels String[]
projectId String
project Project @relation(fields: [projectId], references: [id])
}
model Epic {
id String @id @default(cuid())
name String
description String?
status TaskStatus @default(BACKLOG)
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspaceId String
assignee Member? @relation(fields: [assigneeId], references: [id])
assigneeId String?
project Project? @relation(fields: [projectId], references: [id])
projectId String?
dueDate DateTime?
labels String[]
tasks Task[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Task {
id String @id @default(cuid())
name String
status TaskStatus @default(BACKLOG)
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspaceId String
assignee Member? @relation(fields: [assigneeId], references: [id])
assigneeId String?
project Project? @relation(fields: [projectId], references: [id])
projectId String?
board Board? @relation(fields: [boardId], references: [id])
boardId String?
epic Epic? @relation(fields: [epicId], references: [id])
epicId String?
position Float
dueDate DateTime?
labels String[]
attachments String[]
description String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
comments Comment[]
mentions Mention[]
notifications Notification[]
}
model Comment {
id String @id @default(cuid())
content String
taskId String
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
authorId String
author User @relation(fields: [authorId], references: [id])
attachments String[]
mentions Mention[]
notifications Notification[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Mention {
id String @id @default(cuid())
mentionedUserId String
mentionedUser User @relation(fields: [mentionedUserId], references: [id], name: "MentionedUser")
createdById String
createdBy User @relation(fields: [createdById], references: [id], name: "MentionCreator")
workspaceId String
workspace Workspace @relation(fields: [workspaceId], references: [id])
taskId String?
task Task? @relation(fields: [taskId], references: [id], onDelete: Cascade)
commentId String?
comment Comment? @relation(fields: [commentId], references: [id], onDelete: Cascade)
isRead Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([mentionedUserId, taskId, commentId])
}
model Notification {
id String @id @default(cuid())
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
workspaceId String
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
taskId String?
task Task? @relation(fields: [taskId], references: [id], onDelete: Cascade)
commentId String?
comment Comment? @relation(fields: [commentId], references: [id], onDelete: Cascade)
type NotificationType
title String
message String
data Json?
isRead Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([userId, isRead])
@@index([workspaceId])
}
enum MemberRole {
ADMIN
MEMBER
}
enum TaskStatus {
BACKLOG
TODO
IN_PROGRESS
IN_REVIEW
DONE
}
enum NotificationType {
MENTION
TASK_ASSIGNED
WORKSPACE_ADDED
COMMENT_REPLY
}