140 lines
3.6 KiB
Plaintext
140 lines
3.6 KiB
Plaintext
generator client {
|
||
provider = "prisma-client"
|
||
output = "../generated/prisma"
|
||
engineType = "client"
|
||
generatedFileExtension = "ts"
|
||
importFileExtension = "ts"
|
||
moduleFormat = "esm"
|
||
runtime = "nodejs"
|
||
}
|
||
|
||
datasource db {
|
||
provider = "postgresql"
|
||
}
|
||
|
||
model User {
|
||
nwkennung String @id
|
||
email String? @unique
|
||
arbeitsname String?
|
||
firstName String?
|
||
lastName String?
|
||
passwordHash String?
|
||
groupId String?
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
devicesCreated Device[] @relation("DeviceCreatedBy")
|
||
devicesUpdated Device[] @relation("DeviceUpdatedBy")
|
||
historyEntries DeviceHistory[] @relation("DeviceHistoryChangedBy")
|
||
|
||
// UserGroup hat ein Feld "id" – also darauf referenzieren
|
||
group UserGroup? @relation(fields: [groupId], references: [id])
|
||
|
||
roles UserRole[]
|
||
|
||
@@index([groupId])
|
||
}
|
||
|
||
model Role {
|
||
id String @id @default(uuid())
|
||
name String @unique
|
||
users UserRole[]
|
||
}
|
||
|
||
model UserRole {
|
||
userId String
|
||
roleId String
|
||
assignedAt DateTime @default(now())
|
||
|
||
role Role @relation(fields: [roleId], references: [id])
|
||
user User @relation(fields: [userId], references: [nwkennung])
|
||
|
||
@@id([userId, roleId])
|
||
}
|
||
|
||
model UserGroup {
|
||
id String @id @default(uuid())
|
||
name String @unique
|
||
users User[]
|
||
}
|
||
|
||
model DeviceGroup {
|
||
id String @id @default(uuid())
|
||
name String @unique
|
||
devices Device[]
|
||
}
|
||
|
||
model Location {
|
||
id String @id @default(uuid())
|
||
name String @unique
|
||
devices Device[]
|
||
}
|
||
|
||
model Device {
|
||
inventoryNumber String @id
|
||
name String
|
||
manufacturer String
|
||
model String
|
||
serialNumber String?
|
||
productNumber String?
|
||
comment String?
|
||
ipv4Address String? @unique
|
||
ipv6Address String? @unique
|
||
macAddress String? @unique
|
||
username String? @unique
|
||
passwordHash String? @unique
|
||
groupId String?
|
||
locationId String?
|
||
loanedTo String?
|
||
loanedFrom DateTime?
|
||
loanedUntil DateTime?
|
||
loanComment String?
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
createdById String?
|
||
updatedById String?
|
||
|
||
// 🔹 Self-Relation Hauptgerät/Zubehör
|
||
parentDeviceId String?
|
||
parentDevice Device? @relation(name: "DeviceAccessories", fields: [parentDeviceId], references: [inventoryNumber], onDelete: SetNull)
|
||
accessories Device[] @relation("DeviceAccessories")
|
||
|
||
createdBy User? @relation("DeviceCreatedBy", fields: [createdById], references: [nwkennung])
|
||
updatedBy User? @relation("DeviceUpdatedBy", fields: [updatedById], references: [nwkennung])
|
||
|
||
group DeviceGroup? @relation(fields: [groupId], references: [id])
|
||
location Location? @relation(fields: [locationId], references: [id])
|
||
|
||
history DeviceHistory[]
|
||
tags Tag[] @relation("DeviceToTag")
|
||
|
||
@@index([inventoryNumber])
|
||
@@index([groupId])
|
||
@@index([locationId])
|
||
@@index([parentDeviceId])
|
||
}
|
||
|
||
model Tag {
|
||
id String @id @default(uuid())
|
||
name String @unique
|
||
devices Device[] @relation("DeviceToTag")
|
||
}
|
||
|
||
model DeviceHistory {
|
||
id String @id @default(uuid())
|
||
deviceId String?
|
||
changeType DeviceChangeType
|
||
snapshot Json
|
||
changedAt DateTime @default(now())
|
||
changedById String?
|
||
|
||
changedBy User? @relation("DeviceHistoryChangedBy", fields: [changedById], references: [nwkennung])
|
||
device Device? @relation(fields: [deviceId], references: [inventoryNumber], onDelete: SetNull)
|
||
}
|
||
|
||
enum DeviceChangeType {
|
||
CREATED
|
||
UPDATED
|
||
DELETED
|
||
}
|