tremor-tracker/prisma/schema.prisma

122 lines
4.8 KiB
Plaintext
Raw Permalink 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 {
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?
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
longitude Float
latitude Float
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?
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 {
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
imageName String
earthquakeId Int
earthquake Earthquake @relation(fields: [earthquakeId], references: [id])
creatorId Int?
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")
dateAddedToShop DateTime?
2025-05-19 13:00:10 +01:00
shopPrice Float?
2025-05-19 15:38:24 +01:00
isSold Boolean @default(false)
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)
}
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
}
2025-05-20 13:53:25 +01:00
model Order {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
2025-05-20 13:53:25 +01:00
orderNumber String
userId Int?
user User? @relation("UserOrders", fields: [userId], references: [id], onDelete: SetNull)
email String? // Non-account email for orders without a user account
artefacts Artefact[] @relation("OrderArtefacts")
}