This commit is contained in:
Dobromir Popov
2024-11-06 02:16:48 +02:00
parent 16bd673c7d
commit fb09daf983
5 changed files with 310 additions and 180 deletions

88
prisma/schema.prisma Normal file
View File

@ -0,0 +1,88 @@
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
username String @unique
password String
ownedWallets Wallet[] @relation("UserWallets")
followedWallets WalletFollow[] // Intermediate table relation
}
model Wallet {
id Int @id @default(autoincrement())
publicKey String
privateKey String
userId Int
owner User @relation("UserWallets", fields: [userId], references: [id])
followers WalletFollow[] // Intermediate table relation
holdings Holding[]
@@index([userId])
}
// Intermediate table for many-to-many follow relationship
model WalletFollow {
id Int @id @default(autoincrement())
userId Int
walletId Int
user User @relation(fields: [userId], references: [id])
wallet Wallet @relation(fields: [walletId], references: [id])
createdAt DateTime @default(now())
@@unique([userId, walletId]) // Prevent duplicate follows
@@index([userId])
@@index([walletId])
}
model Holding {
id Int @id @default(autoincrement())
tokenMint String @unique
tokenName String
ammount Float
totalAcquisitionValueUSD Float
totalSellValueUSD Float
walletId Int
wallet Wallet @relation(fields: [walletId], references: [id])
transactions Transaction[]
pnl Float @default(0.0)
}
enum TransactionStatus {
ORIGINAL
ORIGINAL_FOLLOWED
PENDING
FAILED
SENT
CONFIRMED
}
model Transaction {
id Int @id @default(autoincrement())
transactionId String
amount Float
date DateTime
amountUSD Float
holdingId Int
holding Holding @relation(fields: [holdingId], references: [id])
isClosed Boolean @default(false)
status TransactionStatus
originalId Int?
original Transaction? @relation("OriginalTransaction", fields: [originalId], references: [id])
relatedTo Transaction[] @relation("OriginalTransaction")
timestamp DateTime @default(now())
}
datasource db {
provider = "mysql"
url = "mysql://root:Zelen0ku4e@192.168.0.10:3306/trader"
}
model Timeseries {
id Int @id @default(autoincrement())
timestamp DateTime @default(now())
data String
}