traintrape-moi/server/prisma/schema.prisma

120 lines
4.2 KiB
Plaintext
Raw Permalink Normal View History

generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
2024-12-08 12:41:37 +00:00
model Player {
2024-12-12 20:03:42 +00:00
id Int @id @default(autoincrement())
name String @unique
password String
money Int @default(0)
activeChallenge ChallengeAction? @relation("ActiveChallenge", fields: [activeChallengeId], references: [id], onDelete: SetNull)
2024-12-12 20:03:42 +00:00
activeChallengeId Int? @unique
actions ChallengeAction[]
geolocations Geolocation[]
moneyUpdates MoneyUpdate[]
trips TrainTrip[]
runs PlayerRun[]
2024-12-08 15:34:06 +00:00
}
model Game {
id Int @id @default(autoincrement())
started Boolean @default(false)
currentRun PlayerRun? @relation("CurrentRun", fields: [currentRunId], references: [id], onDelete: SetNull)
currentRunId Int? @unique
runs PlayerRun[] @relation("GameRuns")
}
model PlayerRun {
id Int @id @default(autoincrement())
game Game @relation("GameRuns", fields: [gameId], references: [id], onDelete: Cascade)
runningGame Game? @relation("CurrentRun")
gameId Int
runner Player @relation(fields: [runnerId], references: [id], onDelete: Cascade)
runnerId Int
start DateTime @default(now()) @db.Timestamptz(3)
end DateTime? @db.Timestamptz(3)
moneyUpdate MoneyUpdate?
challengeActions ChallengeAction[]
trains TrainTrip[]
}
model Geolocation {
2024-12-07 14:11:47 +00:00
id Int @id @default(autoincrement())
player Player @relation(fields: [playerId], references: [id], onDelete: Cascade)
2024-12-08 12:41:37 +00:00
playerId Int
2024-12-07 14:11:47 +00:00
longitude Float
latitude Float
speed Float
accuracy Float
altitude Float
altitudeAccuracy Float
timestamp DateTime @db.Timestamptz(3)
}
model Challenge {
id Int @id @default(autoincrement())
title String @unique
description String
reward Int
action ChallengeAction?
}
model ChallengeAction {
id Int @id @default(autoincrement())
player Player @relation(fields: [playerId], references: [id], onDelete: Restrict)
2024-12-08 12:41:37 +00:00
playerId Int
challenge Challenge @relation(fields: [challengeId], references: [id], onDelete: Cascade)
challengeId Int @unique
success Boolean @default(false)
start DateTime @default(now()) @db.Timestamptz(3)
end DateTime? @db.Timestamptz(3)
penaltyStart DateTime? @db.Timestamptz(3)
penaltyEnd DateTime? @db.Timestamptz(3)
run PlayerRun @relation(fields: [runId], references: [id], onDelete: Restrict)
runId Int
2024-12-12 20:03:42 +00:00
activePlayer Player? @relation("ActiveChallenge")
moneyUpdate MoneyUpdate?
}
model TrainTrip {
id String @id
player Player @relation(fields: [playerId], references: [id], onDelete: Restrict)
2024-12-08 12:41:37 +00:00
playerId Int
distance Float
from String
to String
departureTime DateTime @db.Timestamptz(3)
arrivalTime DateTime @db.Timestamptz(3)
infoJson Json
run PlayerRun @relation(fields: [runId], references: [id], onDelete: Restrict)
runId Int
moneyUpdate MoneyUpdate?
}
model MoneyUpdate {
id Int @id @default(autoincrement())
player Player @relation(fields: [playerId], references: [id], onDelete: Restrict)
2024-12-08 12:41:37 +00:00
playerId Int
amount Int
reason MoneyUpdateType
action ChallengeAction? @relation(fields: [actionId], references: [id], onDelete: Cascade)
actionId Int? @unique
trip TrainTrip? @relation(fields: [tripId], references: [id], onDelete: Cascade)
tripId String? @unique
run PlayerRun? @relation(fields: [runId], references: [id], onDelete: Cascade)
runId Int? @unique
timestamp DateTime @default(now()) @db.Timestamptz(3)
}
enum MoneyUpdateType {
START
NEW_RUN
CHALLENGE
BUY_TRAIN
}