Böcker kan delas med en inbjudningslänk (roll, giltighetstid, en eller flera personer, bara en hash sparas). Inloggningen går tillbaka till inbjudan. Kartregistrets markeringar kan få position genom uppslag mot karttjänsten, ett i sekunden. Redigeringsformulär och listor visar vem som har något öppet för redigering. Migrering 0009. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
400 lines
11 KiB
Plaintext
400 lines
11 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
|
|
VEHICLE
|
|
RESEARCH
|
|
REFERENCE
|
|
SKETCH
|
|
APP
|
|
WEBSITE
|
|
}
|
|
|
|
enum MapKind {
|
|
GEO
|
|
IMAGE
|
|
}
|
|
|
|
enum WeekPattern {
|
|
ALL
|
|
ODD
|
|
EVEN
|
|
}
|
|
|
|
// Släktband på en relation. PARENT: från-posten är förälder till till-posten (och till extra deltagare).
|
|
// PARTNER och SIBLING gäller alla deltagare i relationen.
|
|
enum FamilyBond {
|
|
PARENT
|
|
PARTNER
|
|
SIBLING
|
|
}
|
|
|
|
// Roll i en delad bok. Ägaren (Book.ownerId) har alltid full behörighet och står inte i BookMember.
|
|
enum BookRole {
|
|
ADMIN
|
|
EDITOR
|
|
VIEWER
|
|
}
|
|
|
|
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[]
|
|
trash TrashItem[]
|
|
memberships BookMember[]
|
|
presence Presence[]
|
|
}
|
|
|
|
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
|
|
updatedById String?
|
|
|
|
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
|
entities Entity[]
|
|
relations Relation[]
|
|
shifts Shift[]
|
|
maps BookMap[]
|
|
templates Template[]
|
|
counters IdCounter[]
|
|
versions EntityVersion[]
|
|
events StoryEvent[]
|
|
members BookMember[]
|
|
invites BookInvite[]
|
|
presence Presence[]
|
|
|
|
@@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?
|
|
// Vem som senast ändrade posten (användar-id, utan främmande nyckel så att historiken överlever en borttagen användare)
|
|
updatedById String?
|
|
// Skapas automatiskt, t.ex. KI-0001 (se src/lib/ids.ts)
|
|
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[]
|
|
events EventParticipant[]
|
|
|
|
@@unique([bookId, code])
|
|
@@index([bookId, kind])
|
|
}
|
|
|
|
model Relation {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
code String?
|
|
fromId String
|
|
toId String
|
|
type String
|
|
description String? @db.Text
|
|
data Json @default("{}")
|
|
// Släktband för släktträdet, tomt för vanliga relationer
|
|
bond FamilyBond?
|
|
// Period som relationen gällde, "ÅÅÅÅ", "ÅÅÅÅ-MM" eller "ÅÅÅÅ-MM-DD" (se src/lib/story-date.ts)
|
|
startDate String?
|
|
endDate String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @default(now()) @updatedAt
|
|
updatedById String?
|
|
|
|
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[]
|
|
|
|
@@unique([bookId, code])
|
|
@@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?
|
|
// Schema-ID (SCI-0001), delas av en persons alla pass hos samma arbetsplats
|
|
scheduleCode 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
|
|
code 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[]
|
|
|
|
@@unique([bookId, code])
|
|
@@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
|
|
// Placerings-ID, t.ex. PI-0001
|
|
code String?
|
|
entityId String?
|
|
label String
|
|
note String? @db.Text
|
|
color String @default("blue")
|
|
lat Float
|
|
lng Float
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @default(now()) @updatedAt
|
|
updatedById String?
|
|
|
|
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
|
|
updatedById String?
|
|
|
|
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])
|
|
}
|
|
|
|
// Delning av en bok med en annan användare.
|
|
model BookMember {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
userId String
|
|
role BookRole @default(EDITOR)
|
|
createdAt DateTime @default(now())
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([bookId, userId])
|
|
@@index([userId])
|
|
}
|
|
|
|
// Inbjudningslänk till en bok. Länken (token) visas bara när den skapas, i databasen finns bara en hash.
|
|
model BookInvite {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
tokenHash String @unique
|
|
role BookRole
|
|
createdById String?
|
|
createdAt DateTime @default(now())
|
|
expiresAt DateTime
|
|
// Antal personer som får gå med, tomt = obegränsat så länge länken gäller
|
|
maxUses Int?
|
|
usedCount Int @default(0)
|
|
revokedAt DateTime?
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([bookId])
|
|
}
|
|
|
|
// Vem som har något öppet för redigering just nu. Raderna uppdateras med jämna mellanrum och räknas som gamla efter en kort stund.
|
|
model Presence {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
userId String
|
|
// "entity", "relation", "event", "template" eller "book"
|
|
kind String
|
|
targetId String
|
|
seenAt DateTime @default(now())
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([userId, kind, targetId])
|
|
@@index([bookId, kind, seenAt])
|
|
}
|
|
|
|
// Händelse på tidslinjen. Datum skrivs som "ÅÅÅÅ", "ÅÅÅÅ-MM" eller "ÅÅÅÅ-MM-DD".
|
|
model StoryEvent {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
title String
|
|
date String
|
|
endDate String?
|
|
description String? @db.Text
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @default(now()) @updatedAt
|
|
updatedById String?
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
participants EventParticipant[]
|
|
|
|
@@index([bookId])
|
|
}
|
|
|
|
model EventParticipant {
|
|
id String @id @default(cuid())
|
|
eventId String
|
|
entityId String
|
|
|
|
event StoryEvent @relation(fields: [eventId], references: [id], onDelete: Cascade)
|
|
entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([eventId, entityId])
|
|
@@index([entityId])
|
|
}
|
|
|
|
// Löpande nummer per bok och ID-typ, t.ex. key "KI" eller "KD-R"
|
|
model IdCounter {
|
|
bookId String
|
|
key String
|
|
next Int @default(0)
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
|
|
@@id([bookId, key])
|
|
}
|
|
|
|
// Cache för namnstatistik från SCB och Skatteverket. entries = [[namn, antal], ...] sorterat på antal.
|
|
model NameStat {
|
|
kind String // "given-female", "given-male" eller "surname"
|
|
year Int // födelseår, 0 för efternamn
|
|
source String
|
|
entries Json
|
|
fetchedAt DateTime @default(now())
|
|
|
|
@@id([kind, year])
|
|
}
|
|
|
|
// Borttagna poster och böcker. Posten sparas som en ögonblicksbild (payload) och boken som en zip-fil (file)
|
|
// tills den återställs eller rensas efter 30 dagar.
|
|
model TrashItem {
|
|
id String @id @default(cuid())
|
|
ownerId String
|
|
bookId String? // boken en post hörde till, tom för borttagna böcker
|
|
kind String // "entity" eller "book"
|
|
label String
|
|
detail String? // t.ex. typ av post
|
|
payload Json?
|
|
file String?
|
|
deletedAt DateTime @default(now())
|
|
|
|
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([ownerId])
|
|
@@index([bookId])
|
|
@@index([deletedAt])
|
|
}
|
|
|
|
// Tidigare versioner av en post. entityId är medvetet ingen främmande nyckel, så att historiken överlever
|
|
// att posten flyttas till papperskorgen.
|
|
model EntityVersion {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
entityId String
|
|
userId String?
|
|
createdAt DateTime @default(now())
|
|
snapshot Json
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([entityId, createdAt])
|
|
@@index([bookId])
|
|
}
|
|
|
|
model BackupRun {
|
|
id String @id @default(cuid())
|
|
trigger String // "schedule" eller "manual"
|
|
status String // "running", "ok" eller "error"
|
|
startedAt DateTime @default(now())
|
|
finishedAt DateTime?
|
|
books Int @default(0)
|
|
megabytes Float @default(0)
|
|
folder String?
|
|
error String?
|
|
|
|
@@index([startedAt])
|
|
}
|