From 52df3c61c347d1b7269cfdf881012a6d4edaf5da Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Tue, 4 Jan 2022 08:29:31 +0200 Subject: [PATCH] Player ids to tournament match game result schema --- app/models/TournamentMatch.ts | 5 ++++ .../migration.sql | 23 ++++++++++++++++++- prisma/schema.prisma | 15 +++++++----- 3 files changed, 36 insertions(+), 7 deletions(-) rename prisma/migrations/{20211226085156_initial => 20220103192041_initial}/migration.sql (91%) diff --git a/app/models/TournamentMatch.ts b/app/models/TournamentMatch.ts index 5f8e75590..ce4a9658b 100644 --- a/app/models/TournamentMatch.ts +++ b/app/models/TournamentMatch.ts @@ -30,17 +30,22 @@ export function createResult({ reporterId, winner, matchId, + playerIds, }: { position: number; reporterId: string; winner: TeamOrder; matchId: string; + playerIds: string[]; }) { return db.tournamentMatchGameResult.create({ data: { position, reporterId, winner, + players: { + connect: playerIds.map((id) => ({ id })), + }, match: { connect: { id: matchId, diff --git a/prisma/migrations/20211226085156_initial/migration.sql b/prisma/migrations/20220103192041_initial/migration.sql similarity index 91% rename from prisma/migrations/20211226085156_initial/migration.sql rename to prisma/migrations/20220103192041_initial/migration.sql index d7357f665..ba7bd4c74 100644 --- a/prisma/migrations/20211226085156_initial/migration.sql +++ b/prisma/migrations/20220103192041_initial/migration.sql @@ -137,11 +137,20 @@ CREATE TABLE "TournamentMatchParticipant" ( -- CreateTable CREATE TABLE "TournamentMatchGameResult" ( + "id" TEXT NOT NULL, "matchId" TEXT NOT NULL, "position" INTEGER NOT NULL, "winner" "TeamOrder" NOT NULL, "reporterId" TEXT NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "TournamentMatchGameResult_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "_TournamentMatchGameResultToUser" ( + "A" TEXT NOT NULL, + "B" TEXT NOT NULL ); -- CreateTable @@ -180,6 +189,12 @@ CREATE UNIQUE INDEX "TournamentMatchParticipant_teamId_matchId_key" ON "Tourname -- CreateIndex CREATE UNIQUE INDEX "TournamentMatchGameResult_matchId_position_key" ON "TournamentMatchGameResult"("matchId", "position"); +-- CreateIndex +CREATE UNIQUE INDEX "_TournamentMatchGameResultToUser_AB_unique" ON "_TournamentMatchGameResultToUser"("A", "B"); + +-- CreateIndex +CREATE INDEX "_TournamentMatchGameResultToUser_B_index" ON "_TournamentMatchGameResultToUser"("B"); + -- CreateIndex CREATE UNIQUE INDEX "_StageToTournament_AB_unique" ON "_StageToTournament"("A", "B"); @@ -237,6 +252,12 @@ ALTER TABLE "TournamentMatchParticipant" ADD CONSTRAINT "TournamentMatchParticip -- AddForeignKey ALTER TABLE "TournamentMatchGameResult" ADD CONSTRAINT "TournamentMatchGameResult_matchId_fkey" FOREIGN KEY ("matchId") REFERENCES "TournamentMatch"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +-- AddForeignKey +ALTER TABLE "_TournamentMatchGameResultToUser" ADD FOREIGN KEY ("A") REFERENCES "TournamentMatchGameResult"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_TournamentMatchGameResultToUser" ADD FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + -- AddForeignKey ALTER TABLE "_StageToTournament" ADD FOREIGN KEY ("A") REFERENCES "Stage"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5a174e4ed..d484182f1 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -8,8 +8,8 @@ datasource db { } model User { - id String @id @default(uuid()) - discordId String @unique + id String @id @default(uuid()) + discordId String @unique discordName String discordDiscriminator String discordAvatar String? @@ -18,12 +18,13 @@ model User { twitter String? youtubeId String? youtubeName String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - trustedUsers TrustRelationships[] @relation("trustGiver") - trustingUsers TrustRelationships[] @relation("trustReceiver") + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + trustedUsers TrustRelationships[] @relation("trustGiver") + trustingUsers TrustRelationships[] @relation("trustReceiver") ownedOrganization Organization? tournamentTeams TournamentTeamMember[] + tournamentMatches TournamentMatchGameResult[] } model Organization { @@ -187,12 +188,14 @@ model TournamentMatchParticipant { } model TournamentMatchGameResult { + id String @id @default(uuid()) matchId String position Int winner TeamOrder reporterId String createdAt DateTime @default(now()) match TournamentMatch @relation(fields: [matchId], references: [id]) + players User[] @@unique([matchId, position]) }