tremor-tracker/schema.prisma

67 lines
2.7 KiB
Plaintext
Raw Normal View History

2025-04-07 13:13:51 +01:00
// Datasource configuration
2025-03-03 14:52:15 +00:00
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}
2025-04-07 13:13:51 +01:00
// User model
2025-03-03 14:52:15 +00:00
model User {
2025-04-07 13:13:51 +01:00
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
email String @unique
passwordHash String
firstname String
surname String
role String @default("USER") @db.VarChar(10)
scientist Scientist? @relation // Optional relation to Scientist
2025-03-03 14:52:15 +00:00
}
2025-04-07 13:13:51 +01:00
// Earthquake model
2025-03-03 14:52:15 +00:00
model Earthquake {
2025-04-07 13:13:51 +01:00
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @db.VarChar(255)
date DateTime
location String
magnitude Float
depth Float
casualties Int
creatorId Int? // Creator's ID (Foreign Key referencing Scientist)
creator Scientist? @relation("ScientistEarthquakeCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction) // Points back to Scientist
2025-03-03 14:52:15 +00:00
}
2025-04-07 13:13:51 +01:00
// Observatory model
2025-03-03 14:52:15 +00:00
model Observatory {
2025-04-07 13:13:51 +01:00
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @db.VarChar(255)
location String
longitude String
latitude String
dateEstablished Int?
functional Boolean
description String? @db.Text
creatorId Int? // Creator's ID (Foreign Key referencing Scientist)
creator Scientist? @relation("ScientistObservatoryCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction) // Points back to Scientist
2025-03-03 14:52:15 +00:00
}
2025-04-07 13:13:51 +01:00
// Scientist model
model Scientist {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
level String @db.VarChar(10) // Junior or Senior
user User @relation(fields: [userId], references: [id]) // Relates to the User model
userId Int @unique
// Self-referencing relation: superior and subordinates
superior Scientist? @relation("SuperiorRelation", fields: [superiorId], references: [id], onDelete: NoAction, onUpdate: NoAction) // Parent scientist
superiorId Int?
subordinates Scientist[] @relation("SuperiorRelation") // Scientists who view this one as a superior
// Earthquake and Observatory relations
earthquakes Earthquake[] @relation("ScientistEarthquakeCreator") // Scientists can create earthquakes
observatories Observatory[] @relation("ScientistObservatoryCreator") // Scientists can create observatories
2025-03-03 14:52:15 +00:00
}