Skip to content

Commit

Permalink
Fix prisma schema and migrations for view metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
uditdc committed Jul 3, 2024
1 parent 28e00c7 commit bed6d99
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
Warnings:
- You are about to drop the `Withdrawal` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
DROP TABLE "Withdrawal";

-- CreateTable
CREATE TABLE "WithdrawalQueued" (
"withdrawalRoot" TEXT NOT NULL,
"nonce" INTEGER NOT NULL,
"stakerAddress" TEXT NOT NULL,
"delegatedTo" TEXT NOT NULL,
"withdrawerAddress" TEXT NOT NULL,
"strategies" TEXT[],
"shares" TEXT[],
"createdAtBlock" BIGINT NOT NULL DEFAULT 0,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "WithdrawalQueued_pkey" PRIMARY KEY ("withdrawalRoot")
);

-- CreateTable
CREATE TABLE "WithdrawalCompleted" (
"withdrawalRoot" TEXT NOT NULL,
"receiveAsTokens" BOOLEAN NOT NULL DEFAULT false,
"createdAtBlock" BIGINT NOT NULL DEFAULT 0,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "WithdrawalCompleted_pkey" PRIMARY KEY ("withdrawalRoot")
);

-- CreateTable
CREATE TABLE "EventLogs_PodSharesUpdated" (
"address" TEXT NOT NULL,
"transactionHash" TEXT NOT NULL,
"transactionIndex" INTEGER NOT NULL,
"blockNumber" BIGINT NOT NULL,
"blockHash" TEXT NOT NULL,
"blockTime" TIMESTAMP(3) NOT NULL,
"podOwner" TEXT NOT NULL,
"sharesDelta" TEXT NOT NULL,

CONSTRAINT "EventLogs_PodSharesUpdated_pkey" PRIMARY KEY ("transactionHash","transactionIndex")
);

-- CreateTable
CREATE TABLE "MetricDepositHourly" (
"id" SERIAL NOT NULL,
"tvlEth" DECIMAL(20,8) NOT NULL,
"totalDeposits" INTEGER NOT NULL,
"changeTvlEth" DECIMAL(20,8) NOT NULL,
"changeDeposits" INTEGER NOT NULL,
"timestamp" TIMESTAMP(3) NOT NULL,

CONSTRAINT "MetricDepositHourly_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "MetricWithdrawalHourly" (
"id" SERIAL NOT NULL,
"tvlEth" DECIMAL(20,8) NOT NULL,
"totalWithdrawals" INTEGER NOT NULL,
"changeTvlEth" DECIMAL(20,8) NOT NULL,
"changeWithdrawals" INTEGER NOT NULL,
"timestamp" TIMESTAMP(3) NOT NULL,

CONSTRAINT "MetricWithdrawalHourly_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "WithdrawalQueued_withdrawalRoot_key" ON "WithdrawalQueued"("withdrawalRoot");

-- CreateIndex
CREATE UNIQUE INDEX "WithdrawalCompleted_withdrawalRoot_key" ON "WithdrawalCompleted"("withdrawalRoot");

-- CreateIndex
CREATE INDEX "EventLogs_PodSharesUpdated_podOwner_idx" ON "EventLogs_PodSharesUpdated"("podOwner");

-- CreateIndex
CREATE INDEX "MetricDepositHourly_timestamp_idx" ON "MetricDepositHourly"("timestamp");

-- CreateIndex
CREATE INDEX "MetricWithdrawalHourly_timestamp_idx" ON "MetricWithdrawalHourly"("timestamp");

-- AddForeignKey
ALTER TABLE "WithdrawalCompleted" ADD CONSTRAINT "WithdrawalCompleted_withdrawalRoot_fkey" FOREIGN KEY ("withdrawalRoot") REFERENCES "WithdrawalQueued"("withdrawalRoot") ON DELETE RESTRICT ON UPDATE CASCADE;
31 changes: 26 additions & 5 deletions packages/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
previewFeatures = ["views"]
}

datasource db {
Expand Down Expand Up @@ -430,8 +431,8 @@ model EventLogs_Deposit {
}

model MetricDepositHourly {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
tvlEth Decimal @db.Decimal(20, 8)
totalDeposits Int
changeTvlEth Decimal @db.Decimal(20, 8)
Expand All @@ -443,8 +444,8 @@ model MetricDepositHourly {
}

model MetricWithdrawalHourly {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
tvlEth Decimal @db.Decimal(20, 8)
totalWithdrawals Int
changeTvlEth Decimal @db.Decimal(20, 8)
Expand All @@ -461,3 +462,23 @@ model Evm_BlockData {
number BigInt @id
timestamp DateTime
}

// Views

view viewHourlyDepositData {
strategyAddress String
totalDeposits Int
totalShares BigInt
timestamp DateTime
@@unique([strategyAddress, timestamp])
}

view viewHourlyWithdrawalData {
strategyAddress String
totalWithdrawals Int
totalShares BigInt
timestamp DateTime
@@unique([strategyAddress, timestamp])
}

0 comments on commit bed6d99

Please sign in to comment.