2025-05-12 13:10:51 +01:00
|
|
|
// Datasource configuration
|
|
|
|
|
datasource db {
|
|
|
|
|
provider = "sqlserver"
|
|
|
|
|
url = env("DATABASE_URL")
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-19 12:42:13 +01:00
|
|
|
// Enums for Request
|
|
|
|
|
enum RequestType {
|
|
|
|
|
NEW_USER
|
|
|
|
|
CHANGE_LEVEL
|
|
|
|
|
DELETE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum RequestOutcome {
|
|
|
|
|
FULFILLED
|
|
|
|
|
REJECTED
|
|
|
|
|
IN_PROGRESS
|
|
|
|
|
CANCELLED
|
|
|
|
|
OTHER
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 13:10:51 +01:00
|
|
|
// 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) // ADMIN, SCIENTIST, GUEST
|
|
|
|
|
scientist Scientist? @relation
|
|
|
|
|
purchasedArtefacts Artefact[] @relation("UserPurchasedArtefacts")
|
2025-05-19 12:42:13 +01:00
|
|
|
requests Request[] @relation("UserRequests")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Request model
|
|
|
|
|
model Request {
|
|
|
|
|
id Int @id @default(autoincrement())
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
requestType RequestType
|
|
|
|
|
requestingUser User @relation("UserRequests", fields: [requestingUserId], references: [id])
|
|
|
|
|
requestingUserId Int
|
|
|
|
|
outcome RequestOutcome @default(IN_PROGRESS)
|
2025-05-12 13:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Earthquake model
|
|
|
|
|
model Earthquake {
|
|
|
|
|
id Int @id @default(autoincrement())
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
date DateTime
|
|
|
|
|
location String
|
|
|
|
|
latitude String
|
|
|
|
|
longitude String
|
|
|
|
|
magnitude Float
|
|
|
|
|
depth Float
|
|
|
|
|
creatorId Int?
|
|
|
|
|
creator Scientist? @relation("ScientistEarthquakeCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
|
|
|
|
artefacts Artefact[]
|
|
|
|
|
observatories Observatory[] @relation("EarthquakeObservatory")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Observatory model
|
|
|
|
|
model Observatory {
|
|
|
|
|
id Int @id @default(autoincrement())
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
name String
|
|
|
|
|
location String
|
|
|
|
|
longitude String
|
|
|
|
|
latitude String
|
|
|
|
|
dateEstablished Int?
|
|
|
|
|
functional Boolean
|
|
|
|
|
seismicSensorOnline Boolean @default(true)
|
|
|
|
|
creatorId Int?
|
|
|
|
|
creator Scientist? @relation("ScientistObservatoryCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
|
|
|
|
earthquakes Earthquake[] @relation("EarthquakeObservatory")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Artefact model
|
|
|
|
|
model Artefact {
|
2025-05-19 12:51:46 +01:00
|
|
|
id Int @id @default(autoincrement())
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
type String @db.VarChar(50) // Lava, Tephra, Ash, Soil
|
|
|
|
|
warehouseArea String // Examples: "ZoneA-Shelf1", "ZoneB-Rack2", "ZoneC-Bin3"
|
|
|
|
|
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)
|
|
|
|
|
required Boolean @default(true)
|
|
|
|
|
dateAddedToShop DateTime?
|
|
|
|
|
shopPrice Float? // In Euros
|
|
|
|
|
purchased Boolean @default(false)
|
|
|
|
|
purchasedById Int?
|
|
|
|
|
purchasedBy User? @relation("UserPurchasedArtefacts", fields: [purchasedById], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
|
|
|
|
pickedUp Boolean @default(false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Pallet {
|
|
|
|
|
id Int @id @default(autoincrement())
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
2025-05-12 13:10:51 +01:00
|
|
|
warehouseArea String // Examples: "ZoneA-Shelf1", "ZoneB-Rack2", "ZoneC-Bin3"
|
2025-05-19 12:51:46 +01:00
|
|
|
palletNote String
|
2025-05-12 13:10:51 +01:00
|
|
|
}
|