feat: add manual bank card ledger

Store exact RUB balances, atomic transfers, linked refunds and versioned edits independently of T-Bank. Add migration, HTTP and durability verification.
This commit is contained in:
2026-09-12 18:34:18 +03:00
parent 8ec172f48e
commit e6f58ef0ee
36 changed files with 2436 additions and 99 deletions
+60
View File
@@ -12,6 +12,9 @@ model User {
id String @id
email String @unique
passwordHash String
bankCards BankCard[]
expenseCategories ExpenseCategory[]
bankCardOperations BankCardOperation[]
sessions Session[]
tbankConnection TbankConnection?
createdAt DateTime @default(now())
@@ -37,3 +40,60 @@ model Session {
@@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])
}