177 lines
5.9 KiB
Plaintext
177 lines
5.9 KiB
Plaintext
generator client {
|
|
provider = "prisma-client-js"
|
|
output = "../node_modules/.prisma/client"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
enum Role {
|
|
BOARD
|
|
ORGA
|
|
FINANCE
|
|
MEMBER
|
|
}
|
|
|
|
enum ApprovalType {
|
|
CHAIR_A
|
|
CHAIR_B
|
|
FINANCE
|
|
}
|
|
|
|
enum ApprovalStatus {
|
|
PENDING
|
|
APPROVED
|
|
}
|
|
|
|
enum ExpenseRecurrence {
|
|
NONE
|
|
MONTHLY
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
name String
|
|
username String @unique
|
|
email String? @unique
|
|
passwordHash String @map("password_hash")
|
|
role Role
|
|
approvalPreference ApprovalType? @map("approval_preference")
|
|
approvalPermissions ApprovalType[] @default([]) @map("approval_permissions")
|
|
workingGroupId String? @map("working_group_id")
|
|
workingGroup WorkingGroup? @relation(fields: [workingGroupId], references: [id], onDelete: SetNull)
|
|
createdExpenses Expense[] @relation("ExpenseCreator")
|
|
approvals Approval[]
|
|
auditLogs AuditLog[]
|
|
pushSubscriptions PushSubscription[]
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@map("users")
|
|
}
|
|
|
|
model PushSubscription {
|
|
id String @id @default(cuid())
|
|
userId String @map("user_id")
|
|
endpoint String @unique
|
|
p256dh String
|
|
auth String
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@index([userId])
|
|
@@map("push_subscriptions")
|
|
}
|
|
|
|
model AccountingPeriod {
|
|
id String @id @default(cuid())
|
|
name String @unique
|
|
startsAt DateTime @map("starts_at")
|
|
endsAt DateTime @map("ends_at")
|
|
isCurrent Boolean @default(false) @map("is_current")
|
|
budgets Budget[]
|
|
expenses Expense[]
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@map("accounting_periods")
|
|
}
|
|
|
|
model AppSettings {
|
|
id String @id @default("global")
|
|
approvalThreshold Decimal @default(50) @db.Decimal(10, 2) @map("approval_threshold")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@map("app_settings")
|
|
}
|
|
|
|
model WorkingGroup {
|
|
id String @id @default(cuid())
|
|
name String @unique
|
|
members User[]
|
|
budgets Budget[]
|
|
expenses Expense[]
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@map("working_groups")
|
|
}
|
|
|
|
model Budget {
|
|
id String @id @default(cuid())
|
|
name String
|
|
totalBudget Decimal @db.Decimal(10, 2) @map("total_budget")
|
|
releasedAmount Decimal @default(0) @db.Decimal(10, 2) @map("released_amount")
|
|
colorCode String @map("color_code")
|
|
workingGroupId String @map("working_group_id")
|
|
periodId String @map("period_id")
|
|
workingGroup WorkingGroup @relation(fields: [workingGroupId], references: [id], onDelete: Cascade)
|
|
period AccountingPeriod @relation(fields: [periodId], references: [id], onDelete: Restrict)
|
|
expenses Expense[]
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@unique([workingGroupId, periodId, name])
|
|
@@map("budgets")
|
|
}
|
|
|
|
model Expense {
|
|
id String @id @default(cuid())
|
|
title String
|
|
description String?
|
|
amount Decimal @db.Decimal(10, 2)
|
|
creatorId String @map("creator_id")
|
|
agId String @map("ag_id")
|
|
budgetId String @map("budget_id")
|
|
periodId String @map("period_id")
|
|
approvalStatus ApprovalStatus @default(PENDING) @map("approval_status")
|
|
recurrence ExpenseRecurrence @default(NONE)
|
|
recurrenceStartAt DateTime? @map("recurrence_start_at")
|
|
paidAt DateTime? @map("paid_at")
|
|
documentedAt DateTime? @map("documented_at")
|
|
invoiceDate DateTime? @map("invoice_date")
|
|
proofUrl String? @map("proof_url")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
creator User @relation("ExpenseCreator", fields: [creatorId], references: [id], onDelete: Restrict)
|
|
workingGroup WorkingGroup @relation(fields: [agId], references: [id], onDelete: Cascade)
|
|
budget Budget @relation(fields: [budgetId], references: [id], onDelete: Restrict)
|
|
period AccountingPeriod @relation(fields: [periodId], references: [id], onDelete: Restrict)
|
|
approvals Approval[]
|
|
|
|
@@map("expenses")
|
|
}
|
|
|
|
model Approval {
|
|
id String @id @default(cuid())
|
|
expenseId String @map("expense_id")
|
|
userId String @map("user_id")
|
|
approvalType ApprovalType @map("approval_type")
|
|
timestamp DateTime @default(now())
|
|
expense Expense @relation(fields: [expenseId], references: [id], onDelete: Cascade)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([expenseId, approvalType])
|
|
@@map("approvals")
|
|
}
|
|
|
|
model AuditLog {
|
|
id String @id @default(cuid())
|
|
actorId String? @map("actor_id")
|
|
actor User? @relation(fields: [actorId], references: [id], onDelete: SetNull)
|
|
action String
|
|
entityType String @map("entity_type")
|
|
entityId String? @map("entity_id")
|
|
entityLabel String? @map("entity_label")
|
|
summary String
|
|
metadata Json?
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
@@index([createdAt])
|
|
@@map("audit_logs")
|
|
}
|