114 lines
4.3 KiB
Plaintext
114 lines
4.3 KiB
Plaintext
datasource db {
|
|
provider = "sqlserver"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
output = "../src/generated/prisma/client"
|
|
}
|
|
|
|
// User model
|
|
model User {
|
|
id Int @id @default(autoincrement())
|
|
createdAt DateTime @default(now())
|
|
name String
|
|
email String @unique
|
|
passwordHash String
|
|
role String @default("GUEST") @db.VarChar(10) // Allowed: ADMIN, SCIENTIST, GUEST
|
|
scientist Scientist? @relation
|
|
purchasedArtefacts Artefact[] @relation("UserPurchasedArtefacts")
|
|
requests Request[] @relation("UserRequests")
|
|
}
|
|
|
|
model Request {
|
|
id Int @id @default(autoincrement())
|
|
createdAt DateTime @default(now())
|
|
requestType String @db.VarChar(20) // Allowed: NEW_USER, CHANGE_LEVEL, DELETE
|
|
requestingUser User @relation("UserRequests", fields: [requestingUserId], references: [id])
|
|
requestingUserId Int
|
|
outcome String @default("IN_PROGRESS") @db.VarChar(20) // Allowed: FULFILLED, REJECTED, IN_PROGRESS, CANCELLED, OTHER
|
|
}
|
|
|
|
// Scientist model
|
|
model Scientist {
|
|
id Int @id @default(autoincrement())
|
|
createdAt DateTime @default(now())
|
|
name String
|
|
level String @db.VarChar(10) // JUNIOR, SENIOR
|
|
user User @relation(fields: [userId], references: [id])
|
|
userId Int @unique
|
|
superior Scientist? @relation("SuperiorRelation", fields: [superiorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
|
superiorId Int?
|
|
subordinates Scientist[] @relation("SuperiorRelation")
|
|
earthquakes Earthquake[] @relation("ScientistEarthquakeCreator")
|
|
observatories Observatory[] @relation("ScientistObservatoryCreator")
|
|
artefacts Artefact[] @relation("ScientistArtefactCreator")
|
|
}
|
|
|
|
model Earthquake {
|
|
id Int @id @default(autoincrement())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
date DateTime
|
|
code String @unique
|
|
magnitude Float
|
|
type String // e.g. 'volcanic'
|
|
latitude Float
|
|
longitude Float
|
|
location String
|
|
depth String
|
|
|
|
creatorId Int?
|
|
creator Scientist? @relation("ScientistEarthquakeCreator", fields: [creatorId], references: [id])
|
|
|
|
artefacts Artefact[]
|
|
observatories Observatory[] @relation("EarthquakeObservatory")
|
|
}
|
|
|
|
model Observatory {
|
|
id Int @id @default(autoincrement())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
name String
|
|
location String
|
|
longitude String
|
|
latitude String
|
|
dateEstablished Int?
|
|
isFunctional Boolean
|
|
seismicSensorOnline Boolean @default(true)
|
|
creatorId Int?
|
|
creator Scientist? @relation("ScientistObservatoryCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
|
earthquakes Earthquake[] @relation("EarthquakeObservatory")
|
|
}
|
|
|
|
model Artefact {
|
|
id Int @id @default(autoincrement())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
name String
|
|
type String @db.VarChar(50) // Lava, Tephra, Ash, Soil
|
|
warehouseArea String
|
|
description String
|
|
earthquakeId Int
|
|
earthquake Earthquake @relation(fields: [earthquakeId], references: [id])
|
|
creatorId Int?
|
|
creator Scientist? @relation("ScientistArtefactCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
|
isRequired Boolean @default(true)
|
|
dateAddedToShop DateTime?
|
|
shopPrice Float?
|
|
isSold Boolean @default(false)
|
|
purchasedById Int?
|
|
purchasedBy User? @relation("UserPurchasedArtefacts", fields: [purchasedById], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
|
isCollected Boolean @default(false)
|
|
}
|
|
|
|
model Pallet {
|
|
id Int @id @default(autoincrement())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
warehouseArea String
|
|
palletNote String
|
|
}
|