tremor-tracker/prisma/schema.prisma

114 lines
4.3 KiB
Plaintext
Raw Normal View History

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 {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
name String
email String @unique
passwordHash String
2025-05-19 13:00:10 +01:00
role String @default("GUEST") @db.VarChar(10) // Allowed: ADMIN, SCIENTIST, GUEST
2025-05-12 13:10:51 +01:00
scientist Scientist? @relation
purchasedArtefacts Artefact[] @relation("UserPurchasedArtefacts")
2025-05-19 12:42:13 +01:00
requests Request[] @relation("UserRequests")
}
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 {
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 {
2025-05-19 13:25:10 +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?
creator Scientist? @relation("ScientistEarthquakeCreator", 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
longitude String
latitude String
dateEstablished Int?
2025-05-19 15:38:24 +01:00
isFunctional Boolean
2025-05-12 13:10:51 +01:00
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
2025-05-19 15:38:24 +01:00
name String
type String @db.VarChar(50) // Lava, Tephra, Ash, Soil
2025-05-19 13:00:10 +01:00
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)
2025-05-19 15:38:24 +01:00
isRequired Boolean @default(true)
dateAddedToShop DateTime?
2025-05-19 13:00:10 +01:00
shopPrice Float?
2025-05-19 15:38:24 +01:00
isSold Boolean @default(false)
purchasedById Int?
purchasedBy User? @relation("UserPurchasedArtefacts", fields: [purchasedById], references: [id], onDelete: NoAction, onUpdate: NoAction)
2025-05-19 15:38:24 +01:00
isCollected Boolean @default(false)
}
model Pallet {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
2025-05-19 13:00:10 +01:00
warehouseArea String
palletNote String
2025-05-12 13:10:51 +01:00
}