From ad7724cda654309f672962c5238cca0a9502cc74 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Fri, 3 Apr 2026 21:03:08 -0700 Subject: [PATCH] refactor(db): remove Team model and add player fields to BracketMatchup --- .../migration.sql | 52 +++++++++++++++++++ .../migration.sql | 30 +++++++++++ 2 files changed, 82 insertions(+) create mode 100644 prisma/migrations/20260404032014_refactor_remove_team_model/migration.sql create mode 100644 prisma/migrations/20260404040000_rename_match_player_fields/migration.sql diff --git a/prisma/migrations/20260404032014_refactor_remove_team_model/migration.sql b/prisma/migrations/20260404032014_refactor_remove_team_model/migration.sql new file mode 100644 index 0000000..31731b8 --- /dev/null +++ b/prisma/migrations/20260404032014_refactor_remove_team_model/migration.sql @@ -0,0 +1,52 @@ +/* + Warnings: + + - You are about to drop the column `team1Id` on the `bracket_matchups` table. All the data in the column will be lost. + - You are about to drop the column `team2Id` on the `bracket_matchups` table. All the data in the column will be lost. + - You are about to drop the column `teamId` on the `event_participants` table. All the data in the column will be lost. + - You are about to drop the `teams` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropForeignKey +ALTER TABLE "bracket_matchups" DROP CONSTRAINT "bracket_matchups_team1Id_fkey"; + +-- DropForeignKey +ALTER TABLE "bracket_matchups" DROP CONSTRAINT "bracket_matchups_team2Id_fkey"; + +-- DropForeignKey +ALTER TABLE "event_participants" DROP CONSTRAINT "event_participants_teamId_fkey"; + +-- DropForeignKey +ALTER TABLE "teams" DROP CONSTRAINT "teams_eventId_fkey"; + +-- DropForeignKey +ALTER TABLE "teams" DROP CONSTRAINT "teams_player1Id_fkey"; + +-- DropForeignKey +ALTER TABLE "teams" DROP CONSTRAINT "teams_player2Id_fkey"; + +-- AlterTable +ALTER TABLE "bracket_matchups" DROP COLUMN "team1Id", +DROP COLUMN "team2Id", +ADD COLUMN "player1P1Id" INTEGER, +ADD COLUMN "player1P2Id" INTEGER, +ADD COLUMN "player2P1Id" INTEGER, +ADD COLUMN "player2P2Id" INTEGER; + +-- AlterTable +ALTER TABLE "event_participants" DROP COLUMN "teamId"; + +-- DropTable +DROP TABLE "teams"; + +-- AddForeignKey +ALTER TABLE "bracket_matchups" ADD CONSTRAINT "bracket_matchups_player1P1Id_fkey" FOREIGN KEY ("player1P1Id") REFERENCES "players"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "bracket_matchups" ADD CONSTRAINT "bracket_matchups_player1P2Id_fkey" FOREIGN KEY ("player1P2Id") REFERENCES "players"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "bracket_matchups" ADD CONSTRAINT "bracket_matchups_player2P1Id_fkey" FOREIGN KEY ("player2P1Id") REFERENCES "players"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "bracket_matchups" ADD CONSTRAINT "bracket_matchups_player2P2Id_fkey" FOREIGN KEY ("player2P2Id") REFERENCES "players"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/migrations/20260404040000_rename_match_player_fields/migration.sql b/prisma/migrations/20260404040000_rename_match_player_fields/migration.sql new file mode 100644 index 0000000..8295ebb --- /dev/null +++ b/prisma/migrations/20260404040000_rename_match_player_fields/migration.sql @@ -0,0 +1,30 @@ +-- Rename player fields in matches table +-- First, add new columns as nullable +ALTER TABLE "matches" ADD COLUMN "player1P1Id" INTEGER; +ALTER TABLE "matches" ADD COLUMN "player1P2Id" INTEGER; +ALTER TABLE "matches" ADD COLUMN "player2P1Id" INTEGER; +ALTER TABLE "matches" ADD COLUMN "player2P2Id" INTEGER; + +-- Copy data from old columns to new columns +UPDATE "matches" SET "player1P1Id" = "team1P1Id"; +UPDATE "matches" SET "player1P2Id" = "team1P2Id"; +UPDATE "matches" SET "player2P1Id" = "team2P1Id"; +UPDATE "matches" SET "player2P2Id" = "team2P2Id"; + +-- Drop old foreign key constraints +ALTER TABLE "matches" DROP CONSTRAINT "matches_team1P1Id_fkey"; +ALTER TABLE "matches" DROP CONSTRAINT "matches_team1P2Id_fkey"; +ALTER TABLE "matches" DROP CONSTRAINT "matches_team2P1Id_fkey"; +ALTER TABLE "matches" DROP CONSTRAINT "matches_team2P2Id_fkey"; + +-- Drop old columns +ALTER TABLE "matches" DROP COLUMN "team1P1Id"; +ALTER TABLE "matches" DROP COLUMN "team1P2Id"; +ALTER TABLE "matches" DROP COLUMN "team2P1Id"; +ALTER TABLE "matches" DROP COLUMN "team2P2Id"; + +-- Add foreign key constraints for new columns +ALTER TABLE "matches" ADD CONSTRAINT "matches_player1P1Id_fkey" FOREIGN KEY ("player1P1Id") REFERENCES "players"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "matches" ADD CONSTRAINT "matches_player1P2Id_fkey" FOREIGN KEY ("player1P2Id") REFERENCES "players"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "matches" ADD CONSTRAINT "matches_player2P1Id_fkey" FOREIGN KEY ("player2P1Id") REFERENCES "players"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "matches" ADD CONSTRAINT "matches_player2P2Id_fkey" FOREIGN KEY ("player2P2Id") REFERENCES "players"("id") ON DELETE RESTRICT ON UPDATE CASCADE;