Player ids to tournament match game result schema

This commit is contained in:
Kalle (Sendou)
2022-01-04 08:29:31 +02:00
parent c016813fbb
commit 52df3c61c3
3 changed files with 36 additions and 7 deletions

View File

@@ -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,

View File

@@ -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;

View File

@@ -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])
}