BalanceSnapshot
Stores User token balance history
Schema
id
: UUIDprevSnapshotId
: UUIDamount
: BigInttransactionId
: UUIDeventId
: IDdelta
: BigInttokenId
: UUIDaccountId
: ID
Relations
- BalanceSnapshot(prevSnapshot) - ONE
- BalanceSnapshot(nextSnapshot) - ONE
- Event - ONE
- Balance - ONE
- Transaction - ONE
- Balance(dummy_balance)- ONE
model BalanceSnapshot {
id String @map("id") @db.Uuid
prevSnapshotId String? @map("prev_id") @db.Uuid
amount BigInt @map("amount")
transactionId String @map("transaction_id") @db.Uuid
eventId String @map("event_id")
delta BigInt @map("delta") // denormalized
tokenId String @map("token_id") @db.Uuid // denormalized
accountId String @map("account_id") // denormalized
prevSnapshot BalanceSnapshot? @relation("link", fields: [prevSnapshotId], references: [id], onUpdate: NoAction, onDelete: NoAction)
nextSnapshot BalanceSnapshot? @relation("link")
event Event @relation(fields: [eventId], references: [id], onUpdate: NoAction, onDelete: NoAction)
balance Balance @relation("snapshot_to_balance", fields: [tokenId, accountId], references: [tokenId, accountId], onUpdate: NoAction, onDelete: NoAction)
transaction Transaction @relation(fields: [transactionId], references: [id], onUpdate: NoAction, onDelete: NoAction)
dummy_balance Balance? @relation("balance_to_snapshot")
@@id([id])
@@unique([prevSnapshotId])
@@map("balance_snapshots")
}