Files
football-next/prisma/schema.prisma
a.alinaghipour aa9ed69dd2 first commit
2026-04-05 15:53:20 +03:30

253 lines
6.2 KiB
Plaintext

generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum Role {
USER
ADMIN
}
enum Position {
GK
DEF
MID
FWD
}
enum MatchStage {
GROUP
ROUND_OF_16
QUARTER_FINAL
SEMI_FINAL
THIRD_PLACE
FINAL
}
enum MatchStatus {
SCHEDULED
LIVE
FINISHED
}
enum TeamStatus {
ACTIVE
INACTIVE
}
enum PaymentStatus {
PENDING
SUCCESS
FAILED
}
enum EventType {
GOAL
ASSIST
YELLOW_CARD
RED_CARD
SECOND_YELLOW
SUBSTITUTION_IN
SUBSTITUTION_OUT
INJURY_NO_SUB
CLEAN_SHEET
PENALTY_SAVED
PENALTY_MISSED
OWN_GOAL
EXTRA_TIME_BONUS
MOTM
}
model Country {
id String @id @default(cuid())
name String @unique
code String @unique
flagUrl String?
defaultFormation String @default("4-3-3")
group Group? @relation(fields: [groupId], references: [id])
groupId String?
isEliminated Boolean @default(false)
players Player[]
homeMatches Match[] @relation("HomeTeam")
awayMatches Match[] @relation("AwayTeam")
}
model Group {
id String @id @default(cuid())
name String @unique
countries Country[]
}
model Player {
id String @id @default(cuid())
name String
position Position
countryId String
country Country @relation(fields: [countryId], references: [id])
price Float @default(5.0)
totalPoints Int @default(0)
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
matchStats PlayerMatchStat[]
teamPlayers TeamPlayer[]
events MatchEvent[]
}
model Match {
id String @id @default(cuid())
homeTeamId String
awayTeamId String
homeTeam Country @relation("HomeTeam", fields: [homeTeamId], references: [id])
awayTeam Country @relation("AwayTeam", fields: [awayTeamId], references: [id])
homeScore Int?
awayScore Int?
stage MatchStage @default(GROUP)
status MatchStatus @default(SCHEDULED)
matchDate DateTime
roundId String?
round Round? @relation(fields: [roundId], references: [id])
playerStats PlayerMatchStat[]
events MatchEvent[]
lineups MatchLineup[]
createdAt DateTime @default(now())
}
model Round {
id String @id @default(cuid())
number Int @unique
name String
isActive Boolean @default(false)
deadline DateTime
matches Match[]
createdAt DateTime @default(now())
}
model MatchEvent {
id String @id @default(cuid())
matchId String
playerId String
match Match @relation(fields: [matchId], references: [id], onDelete: Cascade)
player Player @relation(fields: [playerId], references: [id], onDelete: Cascade)
type EventType
minute Int?
extraInfo String?
createdAt DateTime @default(now())
}
model MatchLineup {
id String @id @default(cuid())
matchId String
countryId String
match Match @relation(fields: [matchId], references: [id], onDelete: Cascade)
formation String
playerIds String[]
}
model PlayerMatchStat {
id String @id @default(cuid())
playerId String
matchId String
player Player @relation(fields: [playerId], references: [id], onDelete: Cascade)
match Match @relation(fields: [matchId], references: [id], onDelete: Cascade)
goals Int @default(0)
assists Int @default(0)
yellowCards Int @default(0)
redCards Int @default(0)
minutesPlayed Int @default(0)
cleanSheet Boolean @default(false)
penaltySaved Int @default(0)
penaltyMissed Int @default(0)
ownGoals Int @default(0)
isMotm Boolean @default(false)
extraTimeBonus Int @default(0)
points Int @default(0)
@@unique([playerId, matchId])
}
model ScoringRule {
id String @id @default(cuid())
position Position
eventType EventType
points Int
updatedAt DateTime @updatedAt
updatedBy String?
@@unique([position, eventType])
}
model User {
id String @id @default(cuid())
name String?
email String @unique
password String
role Role @default(USER)
createdAt DateTime @default(now())
team Team?
sessions Session[]
payments Payment[]
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model Team {
id String @id @default(cuid())
name String
userId String @unique
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
budget Float @default(100.0)
totalPoints Int @default(0)
formation String @default("4-3-3")
status TeamStatus @default(INACTIVE)
createdAt DateTime @default(now())
players TeamPlayer[]
}
model TeamPlayer {
teamId String
playerId String
isCaptain Boolean @default(false)
isViceCaptain Boolean @default(false)
isBench Boolean @default(false)
positionIndex Int @default(0)
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
player Player @relation(fields: [playerId], references: [id], onDelete: Cascade)
@@id([teamId, playerId])
}
model Package {
id String @id @default(cuid())
name String
budgetBonus Float
price Int
description String?
isActive Boolean @default(true)
payments Payment[]
}
model Payment {
id String @id @default(cuid())
userId String
packageId String
user User @relation(fields: [userId], references: [id])
package Package @relation(fields: [packageId], references: [id])
amount Int
authority String? @unique
refId String?
status PaymentStatus @default(PENDING)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}