194 lines
4.9 KiB
Plaintext
194 lines
4.9 KiB
Plaintext
generator client {
|
|
provider = "prisma-client-js"
|
|
binaryTargets = ["native", "debian-openssl-3.0.x", "linux-musl-openssl-3.0.x"]
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
enum EntityKind {
|
|
CHARACTER
|
|
HOME
|
|
PLACE
|
|
COMPANY
|
|
PREMISES
|
|
SCENARIO
|
|
EDUCATION
|
|
PET
|
|
}
|
|
|
|
enum MapKind {
|
|
GEO
|
|
IMAGE
|
|
}
|
|
|
|
enum WeekPattern {
|
|
ALL
|
|
ODD
|
|
EVEN
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
// "<provider>:<subject>", t.ex. "authentik:abc123"
|
|
externalId String @unique
|
|
email String?
|
|
name String?
|
|
createdAt DateTime @default(now())
|
|
books Book[]
|
|
}
|
|
|
|
model Book {
|
|
id String @id @default(cuid())
|
|
ownerId String
|
|
title String
|
|
subtitle String?
|
|
genre String?
|
|
description String? @db.Text
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
|
entities Entity[]
|
|
relations Relation[]
|
|
shifts Shift[]
|
|
maps BookMap[]
|
|
templates Template[]
|
|
|
|
@@index([ownerId])
|
|
}
|
|
|
|
// Karaktärer, bostäder, platser, företag, lokaler, scenarier och husdjur.
|
|
// Mallfälten ligger i `data` (nyckel = fältets key i mallen).
|
|
model Entity {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
kind EntityKind
|
|
name String
|
|
summary String? @db.Text
|
|
imageFile String?
|
|
code String?
|
|
tags String[]
|
|
data Json @default("{}")
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
outgoing Relation[] @relation("RelationFrom")
|
|
incoming Relation[] @relation("RelationTo")
|
|
shifts Shift[] @relation("ShiftPerson")
|
|
hostedShifts Shift[] @relation("ShiftWorkplace")
|
|
markers Marker[]
|
|
memberOf RelationMember[]
|
|
|
|
@@index([bookId, kind])
|
|
@@index([bookId, code])
|
|
}
|
|
|
|
model Relation {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
fromId String
|
|
toId String
|
|
type String
|
|
description String? @db.Text
|
|
data Json @default("{}")
|
|
createdAt DateTime @default(now())
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
from Entity @relation("RelationFrom", fields: [fromId], references: [id], onDelete: Cascade)
|
|
to Entity @relation("RelationTo", fields: [toId], references: [id], onDelete: Cascade)
|
|
// Fler deltagare utöver from/to, t.ex. i en vännergrupp
|
|
members RelationMember[]
|
|
|
|
@@index([bookId])
|
|
@@index([fromId])
|
|
@@index([toId])
|
|
}
|
|
|
|
// Arbetspass. weekday: 0 = måndag ... 6 = söndag.
|
|
model Shift {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
personId String
|
|
workplaceId String?
|
|
weekday Int
|
|
startTime String
|
|
endTime String
|
|
weeks WeekPattern @default(ALL)
|
|
label String?
|
|
createdAt DateTime @default(now())
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
person Entity @relation("ShiftPerson", fields: [personId], references: [id], onDelete: Cascade)
|
|
workplace Entity? @relation("ShiftWorkplace", fields: [workplaceId], references: [id], onDelete: SetNull)
|
|
|
|
@@index([bookId])
|
|
@@index([personId])
|
|
@@index([workplaceId])
|
|
}
|
|
|
|
model BookMap {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
name String
|
|
kind MapKind
|
|
imageFile String?
|
|
centerLat Float?
|
|
centerLng Float?
|
|
zoom Int?
|
|
createdAt DateTime @default(now())
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
markers Marker[]
|
|
|
|
@@index([bookId])
|
|
}
|
|
|
|
// GEO-karta: lat/lng i grader. IMAGE-karta: lat = y och lng = x i bildens pixlar (y uppåt från nederkanten).
|
|
model Marker {
|
|
id String @id @default(cuid())
|
|
mapId String
|
|
entityId String?
|
|
label String
|
|
note String? @db.Text
|
|
color String @default("blue")
|
|
lat Float
|
|
lng Float
|
|
createdAt DateTime @default(now())
|
|
|
|
map BookMap @relation(fields: [mapId], references: [id], onDelete: Cascade)
|
|
entity Entity? @relation(fields: [entityId], references: [id], onDelete: SetNull)
|
|
|
|
@@index([mapId])
|
|
@@index([entityId])
|
|
}
|
|
|
|
// Egen mall för en typ i en bok. Saknas raden används standardmallen.
|
|
model Template {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
// EntityKind eller "RELATION"
|
|
kind String
|
|
fields Json
|
|
updatedAt DateTime @updatedAt
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([bookId, kind])
|
|
}
|
|
|
|
model RelationMember {
|
|
id String @id @default(cuid())
|
|
relationId String
|
|
entityId String
|
|
|
|
relation Relation @relation(fields: [relationId], references: [id], onDelete: Cascade)
|
|
entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([relationId, entityId])
|
|
@@index([entityId])
|
|
}
|