From de94b88be15b14181ec93e12e9657f748897b880 Mon Sep 17 00:00:00 2001 From: smyalygames Date: Thu, 2 Mar 2023 14:42:00 +0000 Subject: [PATCH] feat(database): add economy --- .../20230302130212_economy/migration.sql | 41 +++++++++++++++++++ prisma/schema.prisma | 33 +++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 prisma/migrations/20230302130212_economy/migration.sql diff --git a/prisma/migrations/20230302130212_economy/migration.sql b/prisma/migrations/20230302130212_economy/migration.sql new file mode 100644 index 0000000..81da8df --- /dev/null +++ b/prisma/migrations/20230302130212_economy/migration.sql @@ -0,0 +1,41 @@ +-- CreateTable +CREATE TABLE "Balance" ( + "userId" TEXT NOT NULL, + "balance" INTEGER NOT NULL, + + CONSTRAINT "Balance_pkey" PRIMARY KEY ("userId") +); + +-- CreateTable +CREATE TABLE "Daily" ( + "id" SERIAL NOT NULL, + "userId" TEXT NOT NULL, + "amount" INTEGER NOT NULL, + "time" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Daily_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Payment" ( + "id" SERIAL NOT NULL, + "senderId" TEXT NOT NULL, + "recipientId" TEXT NOT NULL, + "amount" INTEGER NOT NULL, + "reason" TEXT NOT NULL, + "time" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Payment_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "Balance" ADD CONSTRAINT "Balance_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Daily" ADD CONSTRAINT "Daily_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Payment" ADD CONSTRAINT "Payment_senderId_fkey" FOREIGN KEY ("senderId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Payment" ADD CONSTRAINT "Payment_recipientId_fkey" FOREIGN KEY ("recipientId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7835c65..dcc7705 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -37,6 +37,10 @@ model User { muted Boolean @default(false) VerifyUser Verify[] @relation("verUser") VerifyVerifier Verify[] @relation("verVerifier") + Balance Balance? + Daily Daily[] + SendPayment Payment[] @relation("sendPayment") + RecievePayment Payment[] @relation("recievePayment") LeaveLog LeaveLog[] EventLeader Event[] @relation("eventLeader") StatLeader Stat[] @relation("statLeader") @@ -88,6 +92,35 @@ model Verify { notes String? } +// Economy + +model Balance { + user User @relation(fields: [userId], references: [id]) + userId String @id + balance Int +} + +model Daily { + id Int @id @default(autoincrement()) + user User @relation(fields: [userId], references: [id]) + userId String + amount Int + time DateTime @default(now()) +} + +model Payment { + id Int @id @default(autoincrement()) + sender User @relation("sendPayment", fields: [senderId], references: [id]) + senderId String + recipient User @relation("recievePayment", fields: [recipientId], references: [id]) + recipientId String + amount Int + reason String + time DateTime @default(now()) +} + +// Tracking roles for leaving the server + model LeaveLog { id Int @id @default(autoincrement()) user User @relation(fields: [userId], references: [id])