Skip to content

Commit

Permalink
feat: stats datamodel
Browse files Browse the repository at this point in the history
  • Loading branch information
JiveOff committed Sep 11, 2024
1 parent 8626d4c commit 5d5edef
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 3 deletions.
52 changes: 52 additions & 0 deletions prisma/migrations/20240911232815_stats_datamodel/migration.sql
Original file line number Diff line number Diff line change
@@ -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;
56 changes: 53 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 5d5edef

Please sign in to comment.