/*
  Warnings:

  - The values [FINALIZADA,MARCADA,EM_ESPERA,EM_ANDAMENTO] on the enum `MatchStatus` will be removed. If these variants are still used in the database, this will fail.
  - The values [ABERTO,PREPARANDO,EM ANDAMENTO,FINALIZADO] on the enum `TournamentStatus` will be removed. If these variants are still used in the database, this will fail.
  - You are about to drop the column `team_id` on the `Points` table. All the data in the column will be lost.
  - Added the required column `home_team_id` to the `Points` table without a default value. This is not possible if the table is not empty.
  - Added the required column `loserId` to the `Points` table without a default value. This is not possible if the table is not empty.
  - Added the required column `visitors_team_id` to the `Points` table without a default value. This is not possible if the table is not empty.
  - Added the required column `winnerId` to the `Points` table without a default value. This is not possible if the table is not empty.

*/
-- AlterEnum
BEGIN;
CREATE TYPE "MatchStatus_new" AS ENUM ('FINISHING', 'MARKING', 'WAITING', 'RUNNING');
ALTER TABLE "Matches" ALTER COLUMN "match_status" DROP DEFAULT;
ALTER TABLE "Matches" ALTER COLUMN "match_status" TYPE "MatchStatus_new" USING ("match_status"::text::"MatchStatus_new");
ALTER TYPE "MatchStatus" RENAME TO "MatchStatus_old";
ALTER TYPE "MatchStatus_new" RENAME TO "MatchStatus";
DROP TYPE "MatchStatus_old";
ALTER TABLE "Matches" ALTER COLUMN "match_status" SET DEFAULT 'MARKING';
COMMIT;

-- AlterEnum
BEGIN;
CREATE TYPE "TournamentStatus_new" AS ENUM ('OPENING', 'PREPARING', 'RUNNING', 'FINISHING');
ALTER TABLE "Tournament" ALTER COLUMN "tournament_status" DROP DEFAULT;
ALTER TABLE "Tournament" ALTER COLUMN "tournament_status" TYPE "TournamentStatus_new" USING ("tournament_status"::text::"TournamentStatus_new");
ALTER TYPE "TournamentStatus" RENAME TO "TournamentStatus_old";
ALTER TYPE "TournamentStatus_new" RENAME TO "TournamentStatus";
DROP TYPE "TournamentStatus_old";
ALTER TABLE "Tournament" ALTER COLUMN "tournament_status" SET DEFAULT 'OPENING';
COMMIT;

-- DropForeignKey
ALTER TABLE "Points" DROP CONSTRAINT "Points_team_id_fkey";

-- AlterTable
ALTER TABLE "Matches" ALTER COLUMN "match_status" SET DEFAULT 'MARKING';

-- AlterTable
ALTER TABLE "Points" DROP COLUMN "team_id",
ADD COLUMN     "home_team_id" INTEGER NOT NULL,
ADD COLUMN     "loserId" INTEGER NOT NULL,
ADD COLUMN     "visitors_team_id" INTEGER NOT NULL,
ADD COLUMN     "winnerId" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "Tournament" ALTER COLUMN "tournament_status" SET DEFAULT 'OPENING';

-- AddForeignKey
ALTER TABLE "Points" ADD CONSTRAINT "Points_home_team_id_fkey" FOREIGN KEY ("home_team_id") REFERENCES "teams"("team_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Points" ADD CONSTRAINT "Points_visitors_team_id_fkey" FOREIGN KEY ("visitors_team_id") REFERENCES "teams"("team_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Points" ADD CONSTRAINT "Points_winnerId_fkey" FOREIGN KEY ("winnerId") REFERENCES "teams"("team_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Points" ADD CONSTRAINT "Points_loserId_fkey" FOREIGN KEY ("loserId") REFERENCES "teams"("team_id") ON DELETE RESTRICT ON UPDATE CASCADE;
