180 lines
4.5 KiB
Plaintext
180 lines
4.5 KiB
Plaintext
|
// 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")
|
|||
|
}
|
|||
|
|
|||
|
enum Role {
|
|||
|
ADMIN
|
|||
|
CLUB_AADMIN
|
|||
|
DRIVER
|
|||
|
GUEST
|
|||
|
}
|
|||
|
|
|||
|
enum Gender {
|
|||
|
MALE
|
|||
|
FEMALE
|
|||
|
}
|
|||
|
|
|||
|
model User {
|
|||
|
id String @id @default(cuid())
|
|||
|
username String @unique
|
|||
|
password String
|
|||
|
role Role @default(GUEST)
|
|||
|
driver Driver?
|
|||
|
createdAt DateTime @default(now())
|
|||
|
updatedAt DateTime @updatedAt
|
|||
|
deletedAt DateTime?
|
|||
|
|
|||
|
@@index([deletedAt])
|
|||
|
}
|
|||
|
|
|||
|
model Club {
|
|||
|
id String @id @default(cuid())
|
|||
|
name String
|
|||
|
description String
|
|||
|
parentId String?
|
|||
|
parent Club? @relation("ClubHierarchy", fields: [parentId], references: [id], onDelete: Cascade)
|
|||
|
children Club[] @relation("ClubHierarchy")
|
|||
|
drivers Driver[]
|
|||
|
cars Car[]
|
|||
|
games Game[]
|
|||
|
comments Comment[]
|
|||
|
terms Term[]
|
|||
|
createdAt DateTime @default(now())
|
|||
|
updatedAt DateTime @updatedAt
|
|||
|
deletedAt DateTime?
|
|||
|
|
|||
|
@@index([parentId])
|
|||
|
@@index([deletedAt])
|
|||
|
}
|
|||
|
|
|||
|
model Driver {
|
|||
|
id String @id @default(cuid())
|
|||
|
name String?
|
|||
|
gender Gender
|
|||
|
age Int
|
|||
|
bio String?
|
|||
|
clubId String
|
|||
|
club Club @relation(fields: [clubId], references: [id])
|
|||
|
sorties Sortie[]
|
|||
|
comment Comment[]
|
|||
|
terms Term[]
|
|||
|
user User? @relation(fields: [userId], references: [id])
|
|||
|
createdAt DateTime @default(now())
|
|||
|
updatedAt DateTime @updatedAt
|
|||
|
deletedAt DateTime?
|
|||
|
userId String? @unique
|
|||
|
|
|||
|
@@index([clubId])
|
|||
|
@@index([deletedAt])
|
|||
|
}
|
|||
|
|
|||
|
model Car {
|
|||
|
id String @id @default(cuid())
|
|||
|
model String
|
|||
|
number String
|
|||
|
name String
|
|||
|
clubId String
|
|||
|
club Club @relation(fields: [clubId], references: [id])
|
|||
|
sorties Sortie[]
|
|||
|
comments Comment[]
|
|||
|
terms Term[]
|
|||
|
createdAt DateTime @default(now())
|
|||
|
updatedAt DateTime @updatedAt
|
|||
|
deletedAt DateTime?
|
|||
|
|
|||
|
@@index([clubId])
|
|||
|
@@index([deletedAt])
|
|||
|
}
|
|||
|
|
|||
|
model Game {
|
|||
|
id String @id @default(cuid())
|
|||
|
name String
|
|||
|
startTime DateTime
|
|||
|
clubs Club[]
|
|||
|
sorties Sortie[]
|
|||
|
comments Comment[]
|
|||
|
terms Term[]
|
|||
|
createdAt DateTime @default(now())
|
|||
|
updatedAt DateTime @updatedAt
|
|||
|
deletedAt DateTime?
|
|||
|
}
|
|||
|
|
|||
|
model Sortie {
|
|||
|
id String @id @default(cuid())
|
|||
|
totalTime Float
|
|||
|
score Float
|
|||
|
driverId String
|
|||
|
driver Driver @relation(fields: [driverId], references: [id])
|
|||
|
carId String
|
|||
|
car Car @relation(fields: [carId], references: [id])
|
|||
|
gameID String
|
|||
|
game Game @relation(fields: [gameID], references: [id])
|
|||
|
createdAt DateTime @default(now())
|
|||
|
updatedAt DateTime @updatedAt
|
|||
|
deletedAt DateTime?
|
|||
|
|
|||
|
@@index([deletedAt])
|
|||
|
}
|
|||
|
|
|||
|
model Comment {
|
|||
|
id String @id @default(cuid())
|
|||
|
content String
|
|||
|
clubId String
|
|||
|
club Club @relation(fields: [clubId], references: [id])
|
|||
|
driverId String
|
|||
|
driver Driver @relation(fields: [driverId], references: [id])
|
|||
|
carId String
|
|||
|
car Car @relation(fields: [carId], references: [id])
|
|||
|
gameId String
|
|||
|
game Game @relation(fields: [gameId], references: [id])
|
|||
|
createdAt DateTime @default(now())
|
|||
|
updatedAt DateTime @updatedAt
|
|||
|
deletedAt DateTime?
|
|||
|
|
|||
|
@@index([deletedAt])
|
|||
|
@@index([clubId])
|
|||
|
@@index([gameId])
|
|||
|
@@index([driverId])
|
|||
|
}
|
|||
|
|
|||
|
model Taxonomy {
|
|||
|
id String @id @default(cuid())
|
|||
|
name String @unique
|
|||
|
deletedAt DateTime?
|
|||
|
createdAt DateTime @default(now())
|
|||
|
terms Term[]
|
|||
|
|
|||
|
@@index([deletedAt])
|
|||
|
@@map("taxonomy")
|
|||
|
}
|
|||
|
|
|||
|
model Term {
|
|||
|
id String @id @default(cuid())
|
|||
|
name String
|
|||
|
taxonomy Taxonomy? @relation(fields: [taxonomyId], references: [id])
|
|||
|
taxonomyId String?
|
|||
|
parentId String?
|
|||
|
parent Term? @relation("ChildParent", fields: [parentId], references: [id], onDelete: Cascade)
|
|||
|
children Term[] @relation("ChildParent")
|
|||
|
createdAt DateTime @default(now())
|
|||
|
updatedAt DateTime @updatedAt
|
|||
|
deletedAt DateTime?
|
|||
|
createdBy String?
|
|||
|
club Club[]
|
|||
|
driver Driver[]
|
|||
|
car Car[]
|
|||
|
game Game[]
|
|||
|
|
|||
|
@@index([name]) // 对name字段建立索引,以加快基于name的查找速度
|
|||
|
@@index([parentId]) // 对parentId字段建立索引,以加快基于parentId的查找速度
|
|||
|
@@map("term")
|
|||
|
}
|