clone:legacy
This commit is contained in:
229
prisma/schema.prisma
Normal file
229
prisma/schema.prisma
Normal file
@@ -0,0 +1,229 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
previewFeatures = ["views"]
|
||||
}
|
||||
|
||||
generator dbml {
|
||||
provider = "prisma-dbml-generator"
|
||||
output = "../src"
|
||||
outputName = "schema.dbml"
|
||||
projectDatabaseType = "mysql"
|
||||
projectName = "BKON Wallet Schema"
|
||||
projectNote = "BKON Wallet Distributor Table"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model Board {
|
||||
id Int @id @default(autoincrement())
|
||||
title String?
|
||||
body String? @db.Text
|
||||
imgUrl String?
|
||||
count Int @default(0)
|
||||
categoryId Int?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
link String?
|
||||
category Category? @relation(fields: [categoryId], references: [id])
|
||||
|
||||
@@index([title], map: "title")
|
||||
@@index([categoryId], map: "Board_categoryId_fkey")
|
||||
}
|
||||
|
||||
model Category {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
Board Board[]
|
||||
}
|
||||
|
||||
model Node {
|
||||
id Int @id @default(autoincrement())
|
||||
address String @unique
|
||||
balance Decimal @default(0) @db.Decimal(65, 0)
|
||||
stakedBalance Decimal @default(0) @db.Decimal(65, 0)
|
||||
computingPower Decimal @default(0) @db.Decimal(65, 0)
|
||||
parentId Int?
|
||||
isActivated Boolean @default(false)
|
||||
nickname String?
|
||||
referral String @unique
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
userId String?
|
||||
childrenAccumulatedBalance Decimal @default(0) @db.Decimal(65, 0)
|
||||
childrenAccumulatedCount Decimal @default(0) @db.Decimal(65, 0)
|
||||
childrenAccumulatedActiveCount Decimal @default(0) @db.Decimal(65, 0)
|
||||
childrenAccumulatedDeactiveCount Decimal @default(0) @db.Decimal(65, 0)
|
||||
childrenAccumulatedStakedBalance Decimal @default(0) @db.Decimal(65, 0)
|
||||
childrenDepth Int @default(0)
|
||||
depth Int @default(0)
|
||||
depositedBalance Decimal @default(0) @db.Decimal(65, 0)
|
||||
realName String?
|
||||
parent Node? @relation("ParentChild", fields: [parentId], references: [id])
|
||||
children Node[] @relation("ParentChild")
|
||||
User User? @relation(fields: [userId], references: [userId])
|
||||
|
||||
@@index([parentId], map: "Node_parentId_fkey")
|
||||
@@index([userId], map: "Node_userId_fkey")
|
||||
}
|
||||
|
||||
model Txes {
|
||||
id Int @id @default(autoincrement())
|
||||
txid String
|
||||
from String
|
||||
to String
|
||||
value Decimal @default(0) @db.Decimal(65, 0)
|
||||
fee Decimal @default(0) @db.Decimal(65, 0)
|
||||
internalFee Decimal @default(0) @db.Decimal(65, 0)
|
||||
type String
|
||||
blockTimestamp DateTime
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
}
|
||||
|
||||
model User {
|
||||
userId String @id @unique @default(uuid())
|
||||
IMEI String?
|
||||
mac String?
|
||||
nickname String?
|
||||
fcmToken String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
pushAllowAt DateTime?
|
||||
language String?
|
||||
Node Node[]
|
||||
favoriteAddress favoriteAddress[]
|
||||
userNotification userNotification[]
|
||||
}
|
||||
|
||||
model favoriteAddress {
|
||||
address String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
userId String
|
||||
nickname String?
|
||||
User User @relation(fields: [userId], references: [userId])
|
||||
|
||||
@@id([address, userId])
|
||||
@@index([userId], map: "favoriteAddress_userId_fkey")
|
||||
}
|
||||
|
||||
model userNotification {
|
||||
id String @id @default(cuid())
|
||||
title String
|
||||
body String
|
||||
data Json
|
||||
userId String
|
||||
type NotificationType
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
link String
|
||||
user User @relation(fields: [userId], references: [userId])
|
||||
|
||||
@@index([userId], map: "userNotification_userId_fkey")
|
||||
}
|
||||
|
||||
model userToAddressBackup {
|
||||
userId String
|
||||
address String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
@@id([userId, address])
|
||||
@@index([userId], map: "userToAddressBackup_userId_fkey")
|
||||
}
|
||||
|
||||
model System {
|
||||
id Int @id @default(autoincrement())
|
||||
key String @unique
|
||||
value String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
}
|
||||
|
||||
model snapshot {
|
||||
id Int @id
|
||||
address String @unique
|
||||
nickname String?
|
||||
parentId Int?
|
||||
stakedBalance Decimal? @db.Decimal(65, 0)
|
||||
computingPower Decimal? @db.Decimal(65, 0)
|
||||
childrenAccumulatedBalance Decimal? @db.Decimal(65, 0)
|
||||
isActivated Boolean
|
||||
balance Decimal? @db.Decimal(65, 0)
|
||||
childrenAccumulatedCount Decimal? @db.Decimal(25, 4)
|
||||
childrenAccumulatedDeactiveCount Decimal? @db.Decimal(65, 4)
|
||||
childrenAccumulatedStakedBalance Decimal? @db.Decimal(65, 4)
|
||||
Txid String?
|
||||
isCPSent Boolean
|
||||
isRankSent Boolean
|
||||
isCPSendStarted Boolean
|
||||
isRankSendStarted Boolean
|
||||
}
|
||||
|
||||
model distribution {
|
||||
id Int @id
|
||||
nickname String?
|
||||
address String?
|
||||
parentId Int?
|
||||
ranking BigInt?
|
||||
stakedBalance Float?
|
||||
computingPower Float?
|
||||
childrenAccumulatedBalance Float?
|
||||
stakedBalanceOrig Decimal? @db.Decimal(65, 0)
|
||||
computingPowerOrig Decimal? @db.Decimal(65, 0)
|
||||
childrenAccumulatedBalanceOrig Decimal? @db.Decimal(65, 0)
|
||||
ranking_portion Decimal? @db.Decimal(25, 4)
|
||||
staked_portion Decimal? @db.Decimal(65, 4)
|
||||
computingPower_portion Decimal? @db.Decimal(65, 4)
|
||||
childrenAccumulatedBalance_portion Decimal? @db.Decimal(65, 4)
|
||||
ranking_estimated_dist Decimal? @db.Decimal(42, 16)
|
||||
computingPower_estimated_dist Decimal? @db.Decimal(65, 16)
|
||||
Txid String?
|
||||
isCPSent Boolean
|
||||
isRankSent Boolean
|
||||
isCPSendStarted Boolean
|
||||
isRankSendStarted Boolean
|
||||
}
|
||||
|
||||
model LockedCoin {
|
||||
id String @id @default(cuid())
|
||||
address String
|
||||
amount Decimal @default(0) @db.Decimal(65, 0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
unlocked Boolean @default(false)
|
||||
unlockAt DateTime?
|
||||
reason String?
|
||||
txId String?
|
||||
sendedAt DateTime?
|
||||
}
|
||||
|
||||
model TransferHistories {
|
||||
idx BigInt @id @default(autoincrement()) @db.UnsignedBigInt
|
||||
txhash String @db.VarChar(100)
|
||||
from_address String @db.VarChar(100)
|
||||
to_address String @db.VarChar(100)
|
||||
amount Decimal @db.Decimal(65, 0)
|
||||
memo String? @db.Text
|
||||
timestamp DateTime @default(now()) @db.DateTime
|
||||
createdAt DateTime @default(now()) @db.DateTime
|
||||
log_index BigInt @db.UnsignedBigInt
|
||||
blockNumber BigInt @db.UnsignedBigInt
|
||||
|
||||
@@unique([txhash, log_index, timestamp])
|
||||
@@index([idx])
|
||||
@@index([log_index], name: "log_index")
|
||||
@@index([from_address, to_address], name: "idxAddress")
|
||||
@@map("TransferHistories")
|
||||
}
|
||||
|
||||
enum NotificationType {
|
||||
SYSTEM
|
||||
USER
|
||||
TRANSACTION
|
||||
}
|
||||
91
prisma/views/DKON/NodeDashboard.sql
Normal file
91
prisma/views/DKON/NodeDashboard.sql
Normal file
@@ -0,0 +1,91 @@
|
||||
WITH `ranking_list` AS (
|
||||
SELECT
|
||||
`n`.`id` AS `id`,
|
||||
`n`.`nickname` AS `nickname`,
|
||||
`n`.`address` AS `address`,
|
||||
`n`.`stakedBalance` AS `stakedBalance`,
|
||||
`n`.`computingPower` AS `computingPower`,
|
||||
`n`.`childrenAccumulatedBalance` AS `childrenAccumulatedBalance`,
|
||||
rank() OVER (
|
||||
ORDER BY
|
||||
`n`.`stakedBalance`
|
||||
) AS `ranking`
|
||||
FROM
|
||||
`DKON`.`Node` `n`
|
||||
WHERE
|
||||
(`n`.`stakedBalance` >= 200000000000000000000)
|
||||
ORDER BY
|
||||
`n`.`stakedBalance` DESC
|
||||
)
|
||||
SELECT
|
||||
`ranking_list`.`id` AS `id`,
|
||||
`ranking_list`.`nickname` AS `nickname`,
|
||||
`ranking_list`.`address` AS `address`,
|
||||
`ranking_list`.`ranking` AS `ranking`,
|
||||
round((`ranking_list`.`stakedBalance` / pow(10, 18)), 4) AS `stakedBalance`,
|
||||
round((`ranking_list`.`computingPower` / pow(10, 18)), 4) AS `computingPower`,
|
||||
round(
|
||||
(
|
||||
`ranking_list`.`childrenAccumulatedBalance` / pow(10, 18)
|
||||
),
|
||||
4
|
||||
) AS `childrenAccumulatedBalance`,
|
||||
`ranking_list`.`stakedBalance` AS `stakedBalanceOrig`,
|
||||
`ranking_list`.`computingPower` AS `computingPowerOrig`,
|
||||
`ranking_list`.`childrenAccumulatedBalance` AS `childrenAccumulatedBalanceOrig`,
|
||||
(
|
||||
`ranking_list`.`ranking` / (
|
||||
SELECT
|
||||
sum(`ranking_list`.`ranking`)
|
||||
FROM
|
||||
`ranking_list`
|
||||
)
|
||||
) AS `ranking_portion`,
|
||||
(
|
||||
`ranking_list`.`stakedBalance` / (
|
||||
SELECT
|
||||
sum(`ranking_list`.`stakedBalance`)
|
||||
FROM
|
||||
`ranking_list`
|
||||
)
|
||||
) AS `staked_portion`,
|
||||
(
|
||||
`ranking_list`.`computingPower` / (
|
||||
SELECT
|
||||
sum(`ranking_list`.`computingPower`)
|
||||
FROM
|
||||
`ranking_list`
|
||||
)
|
||||
) AS `computingPower_portion`,
|
||||
(
|
||||
`ranking_list`.`childrenAccumulatedBalance` / (
|
||||
SELECT
|
||||
sum(`ranking_list`.`childrenAccumulatedBalance`)
|
||||
FROM
|
||||
`ranking_list`
|
||||
)
|
||||
) AS `childrenAccumulatedBalance_portion`,
|
||||
(
|
||||
(
|
||||
`ranking_list`.`ranking` / (
|
||||
SELECT
|
||||
sum(`ranking_list`.`ranking`)
|
||||
FROM
|
||||
`ranking_list`
|
||||
)
|
||||
) * 66666.666666666666
|
||||
) AS `ranking_estimated_dist`,
|
||||
(
|
||||
(
|
||||
`ranking_list`.`computingPower` / (
|
||||
SELECT
|
||||
sum(`ranking_list`.`computingPower`)
|
||||
FROM
|
||||
`ranking_list`
|
||||
)
|
||||
) * 66666.666666666666
|
||||
) AS `computingPower_estimated_dist`
|
||||
FROM
|
||||
`ranking_list`
|
||||
GROUP BY
|
||||
`ranking_list`.`address`
|
||||
66
prisma/views/DKON/NodeDashboardAll.sql
Normal file
66
prisma/views/DKON/NodeDashboardAll.sql
Normal file
@@ -0,0 +1,66 @@
|
||||
WITH `ranking_list` AS (
|
||||
SELECT
|
||||
`n`.`id` AS `id`,
|
||||
`n`.`nickname` AS `nickname`,
|
||||
`n`.`address` AS `address`,
|
||||
`n`.`stakedBalance` AS `stakedBalance`,
|
||||
`n`.`computingPower` AS `computingPower`,
|
||||
`n`.`childrenAccumulatedBalance` AS `childrenAccumulatedBalance`
|
||||
FROM
|
||||
`DKON`.`Node` `n`
|
||||
ORDER BY
|
||||
`n`.`stakedBalance` DESC
|
||||
)
|
||||
SELECT
|
||||
`ranking_list`.`id` AS `id`,
|
||||
`ranking_list`.`nickname` AS `nickname`,
|
||||
`ranking_list`.`address` AS `address`,
|
||||
round((`ranking_list`.`stakedBalance` / pow(10, 18)), 4) AS `stakedBalance`,
|
||||
round((`ranking_list`.`computingPower` / pow(10, 18)), 4) AS `computingPower`,
|
||||
round(
|
||||
(
|
||||
`ranking_list`.`childrenAccumulatedBalance` / pow(10, 18)
|
||||
),
|
||||
4
|
||||
) AS `childrenAccumulatedBalance`,
|
||||
`ranking_list`.`stakedBalance` AS `stakedBalanceOrig`,
|
||||
`ranking_list`.`computingPower` AS `computingPowerOrig`,
|
||||
`ranking_list`.`childrenAccumulatedBalance` AS `childrenAccumulatedBalanceOrig`,
|
||||
(
|
||||
`ranking_list`.`stakedBalance` / (
|
||||
SELECT
|
||||
sum(`ranking_list`.`stakedBalance`)
|
||||
FROM
|
||||
`ranking_list`
|
||||
)
|
||||
) AS `staked_portion`,
|
||||
(
|
||||
`ranking_list`.`computingPower` / (
|
||||
SELECT
|
||||
sum(`ranking_list`.`computingPower`)
|
||||
FROM
|
||||
`ranking_list`
|
||||
)
|
||||
) AS `computingPower_portion`,
|
||||
(
|
||||
`ranking_list`.`childrenAccumulatedBalance` / (
|
||||
SELECT
|
||||
sum(`ranking_list`.`childrenAccumulatedBalance`)
|
||||
FROM
|
||||
`ranking_list`
|
||||
)
|
||||
) AS `childrenAccumulatedBalance_portion`,
|
||||
(
|
||||
(
|
||||
`ranking_list`.`computingPower` / (
|
||||
SELECT
|
||||
sum(`ranking_list`.`computingPower`)
|
||||
FROM
|
||||
`ranking_list`
|
||||
)
|
||||
) * 66666.666666666666
|
||||
) AS `computingPower_estimated_dist`
|
||||
FROM
|
||||
`ranking_list`
|
||||
GROUP BY
|
||||
`ranking_list`.`address`
|
||||
Reference in New Issue
Block a user