Store exact RUB balances, atomic transfers, linked refunds and versioned edits independently of T-Bank. Add migration, HTTP and durability verification.
100 lines
2.9 KiB
Plaintext
100 lines
2.9 KiB
Plaintext
generator client {
|
|
provider = "prisma-client"
|
|
output = "../generated/prisma"
|
|
moduleFormat = "cjs"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
}
|
|
|
|
model User {
|
|
id String @id
|
|
email String @unique
|
|
passwordHash String
|
|
bankCards BankCard[]
|
|
expenseCategories ExpenseCategory[]
|
|
bankCardOperations BankCardOperation[]
|
|
sessions Session[]
|
|
tbankConnection TbankConnection?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model TbankConnection {
|
|
userId String @unique
|
|
encryptedToken String
|
|
connectedAt DateTime
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
model Session {
|
|
id String @id
|
|
userId String
|
|
refreshTokenHash String
|
|
expiresAt DateTime
|
|
revokedAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
}
|
|
|
|
model BankCard {
|
|
id String @id
|
|
userId String
|
|
name String
|
|
bankName String?
|
|
lastFour String?
|
|
openingBalanceKopecks BigInt
|
|
openingDate String
|
|
version Int @default(1)
|
|
archivedAt DateTime?
|
|
createFingerprint String
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
user User @relation(fields: [userId], references: [id], onDelete: Restrict)
|
|
operations BankCardOperation[] @relation("SourceCard")
|
|
incomingOperations BankCardOperation[] @relation("TargetCard")
|
|
@@index([userId])
|
|
}
|
|
model ExpenseCategory {
|
|
id String @id
|
|
userId String
|
|
name String
|
|
nameKey String
|
|
seedKey String?
|
|
version Int @default(1)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Restrict)
|
|
operations BankCardOperation[]
|
|
@@unique([userId, nameKey])
|
|
@@unique([userId, seedKey])
|
|
}
|
|
model BankCardOperation {
|
|
id String @id
|
|
userId String
|
|
kind String
|
|
cardId String
|
|
targetCardId String?
|
|
categoryId String?
|
|
originalExpenseId String?
|
|
amountKopecks BigInt
|
|
date String
|
|
description String?
|
|
version Int @default(1)
|
|
deletedAt DateTime?
|
|
createFingerprint String
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
user User @relation(fields: [userId], references: [id], onDelete: Restrict)
|
|
card BankCard @relation("SourceCard", fields: [cardId], references: [id], onDelete: Restrict)
|
|
targetCard BankCard? @relation("TargetCard", fields: [targetCardId], references: [id], onDelete: Restrict)
|
|
category ExpenseCategory? @relation(fields: [categoryId], references: [id], onDelete: Restrict)
|
|
originalExpense BankCardOperation? @relation("RefundExpense", fields: [originalExpenseId], references: [id], onDelete: Restrict, onUpdate: NoAction)
|
|
refunds BankCardOperation[] @relation("RefundExpense")
|
|
@@index([userId, cardId, date])
|
|
@@index([userId, targetCardId, date])
|
|
@@index([originalExpenseId])
|
|
}
|