2025-05-12 13:10:51 +01:00
|
|
|
datasource db {
|
|
|
|
|
provider = "sqlserver"
|
|
|
|
|
url = env("DATABASE_URL")
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-19 13:57:27 +01:00
|
|
|
generator client {
|
|
|
|
|
provider = "prisma-client-js"
|
|
|
|
|
output = "../src/generated/prisma/client"
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 13:10:51 +01:00
|
|
|
// User model
|
|
|
|
|
model User {
|
2025-05-27 13:48:32 +01:00
|
|
|
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
|
|
|
|
|
purchasedOrders Order[] @relation("UserOrders")
|
|
|
|
|
requests Request[] @relation("UserRequests")
|
|
|
|
|
earthquakes Earthquake[] @relation("UserEarthquakeCreator")
|
|
|
|
|
observatories Observatory[] @relation("UserObservatoryCreator")
|
|
|
|
|
artefacts Artefact[] @relation("UserArtefactCreator")
|
2025-05-19 12:42:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Request {
|
2025-05-19 13:00:10 +01:00
|
|
|
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])
|
2025-05-19 12:42:13 +01:00
|
|
|
requestingUserId Int
|
2025-05-19 13:00:10 +01:00
|
|
|
outcome String @default("IN_PROGRESS") @db.VarChar(20) // Allowed: FULFILLED, REJECTED, IN_PROGRESS, CANCELLED, OTHER
|
2025-05-12 13:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Scientist model
|
|
|
|
|
model Scientist {
|
2025-05-27 13:48:32 +01:00
|
|
|
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")
|
2025-05-12 13:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Earthquake {
|
2025-05-20 13:53:25 +01:00
|
|
|
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?
|
2025-05-26 14:27:28 +01:00
|
|
|
creator User? @relation("UserEarthquakeCreator", fields: [creatorId], references: [id])
|
2025-05-12 13:10:51 +01:00
|
|
|
artefacts Artefact[]
|
|
|
|
|
observatories Observatory[] @relation("EarthquakeObservatory")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Observatory {
|
|
|
|
|
id Int @id @default(autoincrement())
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
name String
|
|
|
|
|
location String
|
2025-05-25 18:54:00 +01:00
|
|
|
longitude Float
|
|
|
|
|
latitude Float
|
2025-05-25 11:37:05 +01:00
|
|
|
dateEstablished DateTime
|
2025-05-19 15:38:24 +01:00
|
|
|
isFunctional Boolean
|
2025-05-12 13:10:51 +01:00
|
|
|
seismicSensorOnline Boolean @default(true)
|
|
|
|
|
creatorId Int?
|
2025-05-26 14:27:28 +01:00
|
|
|
creator User? @relation("UserObservatoryCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
2025-05-12 13:10:51 +01:00
|
|
|
earthquakes Earthquake[] @relation("EarthquakeObservatory")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Artefact {
|
2025-05-19 12:51:46 +01:00
|
|
|
id Int @id @default(autoincrement())
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
2025-05-19 15:38:24 +01:00
|
|
|
name String
|
2025-05-19 12:51:46 +01:00
|
|
|
type String @db.VarChar(50) // Lava, Tephra, Ash, Soil
|
2025-05-19 13:00:10 +01:00
|
|
|
warehouseArea String
|
2025-05-19 12:51:46 +01:00
|
|
|
description String
|
2025-05-22 17:59:20 +01:00
|
|
|
imageName String
|
2025-05-19 12:51:46 +01:00
|
|
|
earthquakeId Int
|
|
|
|
|
earthquake Earthquake @relation(fields: [earthquakeId], references: [id])
|
|
|
|
|
creatorId Int?
|
2025-05-26 14:27:28 +01:00
|
|
|
creator User? @relation("UserArtefactCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
2025-05-27 13:48:32 +01:00
|
|
|
isRequired Boolean @default(true) @map("isRequired")
|
2025-05-19 12:51:46 +01:00
|
|
|
dateAddedToShop DateTime?
|
2025-05-19 13:00:10 +01:00
|
|
|
shopPrice Float?
|
2025-05-19 15:38:24 +01:00
|
|
|
isSold Boolean @default(false)
|
2025-05-26 14:07:07 +01:00
|
|
|
orderId Int?
|
|
|
|
|
order Order? @relation("OrderArtefacts", fields: [orderId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
2025-05-19 15:38:24 +01:00
|
|
|
isCollected Boolean @default(false)
|
2025-05-19 12:51:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Pallet {
|
|
|
|
|
id Int @id @default(autoincrement())
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
2025-05-19 13:00:10 +01:00
|
|
|
warehouseArea String
|
2025-05-19 12:51:46 +01:00
|
|
|
palletNote String
|
2025-05-12 13:10:51 +01:00
|
|
|
}
|
2025-05-20 13:53:25 +01:00
|
|
|
|
|
|
|
|
model Order {
|
2025-05-26 14:07:07 +01:00
|
|
|
id Int @id @default(autoincrement())
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
2025-05-20 13:53:25 +01:00
|
|
|
orderNumber String
|
2025-05-26 14:07:07 +01:00
|
|
|
userId Int
|
|
|
|
|
user User @relation("UserOrders", fields: [userId], references: [id])
|
|
|
|
|
artefacts Artefact[] @relation("OrderArtefacts")
|
2025-05-20 13:53:25 +01:00
|
|
|
}
|
2025-05-30 13:27:57 +01:00
|
|
|
// todo make user optional for if details aren't saved
|
|
|
|
|
// todo add email field to link order to user if created later on
|