From 5d5edef0b5d5455ab2e4947f05177586677c2d4a Mon Sep 17 00:00:00 2001 From: JiveOff Date: Thu, 12 Sep 2024 01:29:10 +0200 Subject: [PATCH] feat: stats datamodel --- .../migration.sql | 52 +++++++++++++++++ prisma/schema.prisma | 56 ++++++++++++++++++- 2 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 prisma/migrations/20240911232815_stats_datamodel/migration.sql diff --git a/prisma/migrations/20240911232815_stats_datamodel/migration.sql b/prisma/migrations/20240911232815_stats_datamodel/migration.sql new file mode 100644 index 0000000..371ff4a --- /dev/null +++ b/prisma/migrations/20240911232815_stats_datamodel/migration.sql @@ -0,0 +1,52 @@ +-- CreateEnum +CREATE TYPE "StatisticType" AS ENUM ('VALUE', 'TRANSACTION'); + +-- AlterTable +ALTER TABLE "Template" ALTER COLUMN "motd" SET DEFAULT ' &e&lEFREI CRAFT &8• &61.19.3 + &bBienvenue !'; + +-- CreateTable +CREATE TABLE "Statistic" ( + "id" TEXT NOT NULL, + "key" TEXT NOT NULL, + "displayName" TEXT, + "color" TEXT NOT NULL DEFAULT '&7', + "type" "StatisticType" NOT NULL DEFAULT 'TRANSACTION', + + CONSTRAINT "Statistic_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "PlayerStatisticTransaction" ( + "id" TEXT NOT NULL, + "playerUuid" TEXT NOT NULL, + "statisticId" TEXT NOT NULL, + "value" INTEGER NOT NULL, + "reason" TEXT, + "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "PlayerStatisticTransaction_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "PlayerStatisticValue" ( + "id" TEXT NOT NULL, + "playerUuid" TEXT NOT NULL, + "statisticId" TEXT NOT NULL, + "value" INTEGER NOT NULL, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "PlayerStatisticValue_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "PlayerStatisticTransaction" ADD CONSTRAINT "PlayerStatisticTransaction_playerUuid_fkey" FOREIGN KEY ("playerUuid") REFERENCES "Player"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "PlayerStatisticTransaction" ADD CONSTRAINT "PlayerStatisticTransaction_statisticId_fkey" FOREIGN KEY ("statisticId") REFERENCES "Statistic"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "PlayerStatisticValue" ADD CONSTRAINT "PlayerStatisticValue_playerUuid_fkey" FOREIGN KEY ("playerUuid") REFERENCES "Player"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "PlayerStatisticValue" ADD CONSTRAINT "PlayerStatisticValue_statisticId_fkey" FOREIGN KEY ("statisticId") REFERENCES "Statistic"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 61d773f..297afc9 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -43,13 +43,16 @@ model Player { party Party? @relation("partyOwner") partyId Int? - memberOfParty Party? @relation(fields: [memberOfPartyId], references: [id]) + memberOfParty Party? @relation(name: "memberOfParty", fields: [memberOfPartyId], references: [id]) memberOfPartyId Int? - invitedToParty Party[] @relation("partyInvited") + invitedToParty Party[] @relation(name: "partyInvited") member Member? @relation(fields: [memberDiscordId], references: [discordId]) memberDiscordId String? @unique + + statValues PlayerStatisticValue[] + statTransactions PlayerStatisticTransaction[] } model Member { @@ -67,7 +70,7 @@ model Party { owner Player @relation("partyOwner", fields: [ownerUuid], references: [uuid]) ownerUuid String @unique - members Player[] + members Player[] @relation("memberOfParty") invited Player[] @relation("partyInvited") public Boolean @default(false) @@ -301,4 +304,51 @@ model Log { gameServerName String? playerUuid String? templateName String? +} + +enum StatisticType { + VALUE + TRANSACTION +} + +model Statistic { + id String @id @default(uuid()) + key String + + displayName String? + color String @default("&7") + + type StatisticType @default(TRANSACTION) + + transactions PlayerStatisticTransaction[] + values PlayerStatisticValue[] +} + +model PlayerStatisticTransaction { + id String @id @default(uuid()) + + player Player @relation(fields: [playerUuid], references: [uuid]) + playerUuid String + + statistic Statistic @relation(fields: [statisticId], references: [id]) + statisticId String + + value Int + reason String? + + timestamp DateTime @default(now()) +} + +model PlayerStatisticValue { + id String @id @default(uuid()) + + player Player @relation(fields: [playerUuid], references: [uuid]) + playerUuid String + + statistic Statistic @relation(fields: [statisticId], references: [id]) + statisticId String + + value Int + + updatedAt DateTime @updatedAt } \ No newline at end of file