chore: initialize SkyMoney (api + prisma + docker-compose) ( still in progress

This commit is contained in:
2025-11-07 22:52:33 -06:00
commit f4160b91db
13 changed files with 2014 additions and 0 deletions

87
api/prisma/schema.prisma Normal file
View File

@@ -0,0 +1,87 @@
// prisma/schema.prisma
generator client { provider = "prisma-client-js" }
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])
@@check(percent_gte_0, "percent >= 0")
@@check(percent_lte_100,"percent <= 100")
}
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") // or 'by-schedule'
scheduleJson Json?
@@unique([userId, name])
@@check(total_nonneg, "totalCents >= 0")
@@check(funded_nonneg, "fundedCents >= 0")
}
model IncomeEvent {
id String @id @default(uuid())
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
postedAt DateTime
amountCents BigInt
allocations Allocation[]
@@check(pos_amount, "amountCents > 0")
}
model Allocation {
id String @id @default(uuid())
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
kind String // 'savings' | 'variable' | 'fixed'
toId String
amountCents BigInt
incomeId String?
income IncomeEvent? @relation(fields: [incomeId], references: [id])
@@check(pos_amount, "amountCents > 0")
}
model Transaction {
id String @id @default(uuid())
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
occurredAt DateTime
kind String // 'variable-spend' | 'fixed-payment'
categoryId String?
planId String?
amountCents BigInt
@@check(pos_amount, "amountCents > 0")
}