272 lines
9.1 KiB
Plaintext
272 lines
9.1 KiB
Plaintext
// Prisma schema for RayLab Core - Phase 1
|
|
// PostgreSQL datasource. DATABASE_URL must be set in environment.
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
authentikId String? @unique
|
|
authentikUserId String? @unique
|
|
authentikSubject String? @unique
|
|
username String? @unique @db.VarChar(255)
|
|
email String? @unique @db.VarChar(320)
|
|
name String? @db.VarChar(255)
|
|
picture String?
|
|
isActive Boolean @default(true)
|
|
deletedAt DateTime?
|
|
lastSeenAt DateTime?
|
|
lastSyncedAt DateTime?
|
|
syncStatus String?
|
|
storageQuota BigInt? @default(10737418240)
|
|
storageUsed BigInt? @default(0)
|
|
metadata Json?
|
|
roles UserRole[]
|
|
permissions UserPermission[]
|
|
auditLogs AuditLog[]
|
|
mediaObjects MediaObject[]
|
|
lastGroupHash String? @db.Text
|
|
// relations for debt module
|
|
debtGroupsOwned DebtGroup[]
|
|
debtGroupMembers DebtGroupMember[]
|
|
createdDebtTransactions DebtTransaction[]
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@index([authentikId])
|
|
@@index([username])
|
|
@@index([email])
|
|
}
|
|
|
|
model Role {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
code String @unique @db.VarChar(100)
|
|
name String @db.VarChar(255)
|
|
displayName String? @db.VarChar(255)
|
|
description String?
|
|
isDefault Boolean @default(false)
|
|
permissions RolePermission[]
|
|
userRoles UserRole[]
|
|
mappings AuthGroupRoleMapping[]
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model Permission {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
code String @unique @db.VarChar(150)
|
|
name String @db.VarChar(255)
|
|
displayName String? @db.VarChar(255)
|
|
description String?
|
|
rolePermissions RolePermission[]
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
UserPermission UserPermission[]
|
|
}
|
|
|
|
model RolePermission {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
|
roleId String @db.Uuid
|
|
permission Permission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
|
|
permissionId String @db.Uuid
|
|
createdAt DateTime @default(now())
|
|
|
|
@@unique([roleId, permissionId])
|
|
@@index([roleId])
|
|
@@index([permissionId])
|
|
}
|
|
|
|
model UserPermission {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
userId String @db.Uuid
|
|
permission Permission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
|
|
permissionId String @db.Uuid
|
|
assignedBy String? @db.VarChar(100)
|
|
createdAt DateTime @default(now())
|
|
|
|
@@unique([userId, permissionId])
|
|
@@index([userId])
|
|
@@index([permissionId])
|
|
}
|
|
|
|
enum UserRoleSource {
|
|
AUTHENTIK
|
|
SYSTEM
|
|
}
|
|
|
|
model UserRole {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
userId String @db.Uuid
|
|
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
|
roleId String @db.Uuid
|
|
source UserRoleSource @default(AUTHENTIK)
|
|
syncedAt DateTime @default(now())
|
|
createdAt DateTime @default(now())
|
|
|
|
@@unique([userId, roleId])
|
|
@@index([userId])
|
|
@@index([roleId])
|
|
}
|
|
|
|
model AuthGroupRoleMapping {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
authGroup String @db.VarChar(255)
|
|
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
|
roleId String @db.Uuid
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@index([authGroup])
|
|
}
|
|
|
|
model AuditLog {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
|
userId String? @db.Uuid
|
|
action String @db.VarChar(200)
|
|
resource String? @db.VarChar(200)
|
|
resourceId String?
|
|
details Json?
|
|
createdAt DateTime @default(now())
|
|
|
|
@@index([userId])
|
|
@@index([action])
|
|
}
|
|
|
|
model ScheduledJob {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
name String @db.VarChar(255)
|
|
payload Json?
|
|
cron String?
|
|
runAt DateTime?
|
|
status String @default("pending") @db.VarChar(50)
|
|
attempts Int @default(0)
|
|
lastRunAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@index([name])
|
|
@@index([status])
|
|
}
|
|
|
|
model MediaObject {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
ownerUserId String? @db.Uuid
|
|
owner User? @relation(fields: [ownerUserId], references: [id], onDelete: SetNull)
|
|
storageKey String @db.VarChar(1024)
|
|
filename String? @db.VarChar(1024)
|
|
mimeType String? @db.VarChar(255)
|
|
size BigInt?
|
|
isPublic Boolean @default(false)
|
|
metadata Json?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@index([ownerUserId])
|
|
@@index([storageKey])
|
|
}
|
|
|
|
model Application {
|
|
id String @id @default(dbgenerated("gen_random_uuid()")) @map("id") @db.Uuid
|
|
code String @unique @map("code") @db.VarChar(100)
|
|
name String @map("name") @db.VarChar(255)
|
|
description String? @map("description") @db.Text
|
|
icon String? @map("icon") @db.Text
|
|
url String? @map("url") @db.Text
|
|
applicationsClaim String @unique @map("applicationsClaim") @db.VarChar(255)
|
|
isActive Boolean @default(true) @map("isActive")
|
|
displayOrder Int @default(0) @map("displayOrder") @db.Integer
|
|
createdAt DateTime @default(dbgenerated("now()")) @map("createdAt") @db.Timestamptz
|
|
updatedAt DateTime @default(dbgenerated("now()")) @map("updatedAt") @db.Timestamptz
|
|
|
|
@@index([code], name: "Application_code_idx")
|
|
@@index([applicationsClaim], name: "Application_applicationsClaim_idx")
|
|
@@map("Application")
|
|
}
|
|
|
|
// Debt management models for /api/bot/debt
|
|
|
|
enum DebtTransactionType {
|
|
DEBT
|
|
PAYMENT
|
|
}
|
|
|
|
model DebtGroup {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
publicId String @unique @db.VarChar(20) // e.g. RL-X7K29P
|
|
name String @db.VarChar(255)
|
|
ownerId String @db.Uuid
|
|
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
|
members DebtGroupMember[]
|
|
people DebtPerson[]
|
|
transactions DebtTransaction[]
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@index([publicId])
|
|
@@index([ownerId])
|
|
}
|
|
|
|
model DebtGroupMember {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
group DebtGroup @relation(fields: [groupId], references: [id], onDelete: Cascade)
|
|
groupId String @db.Uuid
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
userId String @db.Uuid
|
|
createdAt DateTime @default(now())
|
|
|
|
@@unique([groupId, userId])
|
|
@@index([groupId])
|
|
@@index([userId])
|
|
}
|
|
|
|
model DebtPerson {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
group DebtGroup @relation(fields: [groupId], references: [id], onDelete: Cascade)
|
|
groupId String @db.Uuid
|
|
name String @db.VarChar(255)
|
|
isDeleted Boolean @default(false)
|
|
// relations back to transactions
|
|
transactionsFrom DebtTransaction[] @relation("fromPerson")
|
|
transactionsTo DebtTransaction[] @relation("toPerson")
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@unique([groupId, name])
|
|
@@index([groupId])
|
|
}
|
|
|
|
model DebtTransaction {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
group DebtGroup @relation(fields: [groupId], references: [id], onDelete: Cascade)
|
|
groupId String @db.Uuid
|
|
fromPerson DebtPerson @relation("fromPerson", fields: [fromPersonId], references: [id], onDelete: Restrict)
|
|
fromPersonId String @db.Uuid
|
|
toPerson DebtPerson @relation("toPerson", fields: [toPersonId], references: [id], onDelete: Restrict)
|
|
toPersonId String @db.Uuid
|
|
amount BigInt @db.BigInt
|
|
type DebtTransactionType
|
|
description String?
|
|
transactionDate DateTime @db.Date
|
|
createdAt DateTime @default(now())
|
|
createdByUserId String @db.Uuid
|
|
createdByUser User @relation(fields: [createdByUserId], references: [id], onDelete: SetNull)
|
|
requestId String? @db.VarChar(255)
|
|
|
|
@@index([groupId])
|
|
@@index([fromPersonId])
|
|
@@index([toPersonId])
|
|
@@unique([groupId, requestId])
|
|
}
|
|
|