diff --git a/prisma/migrations/20260331214013_add_cascade_delete/migration.sql b/prisma/migrations/20260331214013_add_cascade_delete/migration.sql new file mode 100644 index 0000000..c38ec99 --- /dev/null +++ b/prisma/migrations/20260331214013_add_cascade_delete/migration.sql @@ -0,0 +1,23 @@ +-- DropForeignKey +ALTER TABLE "bracket_matchups" DROP CONSTRAINT "bracket_matchups_matchId_fkey"; + +-- DropForeignKey +ALTER TABLE "elo_snapshots" DROP CONSTRAINT "elo_snapshots_matchId_fkey"; + +-- DropForeignKey +ALTER TABLE "matches" DROP CONSTRAINT "matches_eventId_fkey"; + +-- DropForeignKey +ALTER TABLE "partnership_games" DROP CONSTRAINT "partnership_games_matchId_fkey"; + +-- AddForeignKey +ALTER TABLE "bracket_matchups" ADD CONSTRAINT "bracket_matchups_matchId_fkey" FOREIGN KEY ("matchId") REFERENCES "matches"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "matches" ADD CONSTRAINT "matches_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "events"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "elo_snapshots" ADD CONSTRAINT "elo_snapshots_matchId_fkey" FOREIGN KEY ("matchId") REFERENCES "matches"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "partnership_games" ADD CONSTRAINT "partnership_games_matchId_fkey" FOREIGN KEY ("matchId") REFERENCES "matches"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e223385..e9274de 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -148,7 +148,7 @@ model BracketMatchup { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt event Event @relation(fields: [eventId], references: [id]) - match Match? @relation(fields: [matchId], references: [id]) + match Match? @relation(fields: [matchId], references: [id], onDelete: Cascade) round TournamentRound @relation(fields: [roundId], references: [id]) team1 Team? @relation("BracketTeam1", fields: [team1Id], references: [id]) team2 Team? @relation("BracketTeam2", fields: [team2Id], references: [id]) @@ -174,7 +174,7 @@ model Match { bracketMatchups BracketMatchup[] eloSnapshots EloSnapshot[] createdBy User? @relation("MatchCreator", fields: [createdById], references: [id]) - event Event? @relation(fields: [eventId], references: [id]) + event Event? @relation(fields: [eventId], references: [id], onDelete: Cascade) team1P1 Player @relation("MatchPlayer1", fields: [team1P1Id], references: [id]) team1P2 Player @relation("MatchPlayer2", fields: [team1P2Id], references: [id]) team2P1 Player @relation("MatchPlayer3", fields: [team2P1Id], references: [id]) @@ -192,7 +192,7 @@ model EloSnapshot { ratingAfter Int ratingChange Int createdAt DateTime @default(now()) - match Match @relation(fields: [matchId], references: [id]) + match Match @relation(fields: [matchId], references: [id], onDelete: Cascade) player Player @relation(fields: [playerId], references: [id]) @@map("elo_snapshots") @@ -208,7 +208,7 @@ model PartnershipGame { player1EloChange Int? player2EloChange Int? createdAt DateTime @default(now()) - match Match @relation(fields: [matchId], references: [id]) + match Match @relation(fields: [matchId], references: [id], onDelete: Cascade) player1 Player @relation("PartnershipPlayer1", fields: [player1Id], references: [id]) player2 Player @relation("PartnershipPlayer2", fields: [player2Id], references: [id])