91 lines
2.3 KiB
Plaintext
91 lines
2.3 KiB
Plaintext
// prisma/schema.prisma
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
binaryTargets = ["native", "debian-openssl-3.0.x"]
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(uuid())
|
|
email String @unique
|
|
createdAt DateTime @default(now())
|
|
|
|
variableCategories VariableCategory[]
|
|
fixedPlans FixedPlan[]
|
|
incomes IncomeEvent[]
|
|
allocations Allocation[]
|
|
transactions Transaction[]
|
|
}
|
|
|
|
model VariableCategory {
|
|
id String @id @default(uuid())
|
|
userId String
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
name String
|
|
percent Int
|
|
priority Int @default(100)
|
|
isSavings Boolean @default(false)
|
|
balanceCents BigInt @default(0)
|
|
|
|
@@unique([userId, name])
|
|
@@index([userId, priority])
|
|
}
|
|
|
|
model FixedPlan {
|
|
id String @id @default(uuid())
|
|
userId String
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
name String
|
|
cycleStart DateTime
|
|
dueOn DateTime
|
|
totalCents BigInt
|
|
fundedCents BigInt @default(0)
|
|
priority Int @default(100)
|
|
fundingMode String @default("auto-on-deposit")
|
|
scheduleJson Json?
|
|
|
|
@@unique([userId, name])
|
|
@@index([userId, dueOn])
|
|
@@index([userId, priority])
|
|
}
|
|
|
|
model IncomeEvent {
|
|
id String @id @default(uuid())
|
|
userId String
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
postedAt DateTime
|
|
amountCents BigInt
|
|
allocations Allocation[]
|
|
|
|
@@index([userId, postedAt])
|
|
}
|
|
|
|
model Allocation {
|
|
id String @id @default(uuid())
|
|
userId String
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
createdAt DateTime @default(now())
|
|
kind String
|
|
toId String
|
|
amountCents BigInt
|
|
incomeId String?
|
|
income IncomeEvent? @relation(fields: [incomeId], references: [id])
|
|
}
|
|
|
|
model Transaction {
|
|
id String @id @default(uuid())
|
|
userId String
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
occurredAt DateTime
|
|
kind String
|
|
categoryId String?
|
|
planId String?
|
|
amountCents BigInt
|
|
|
|
@@index([userId, occurredAt])
|
|
}
|