/*
  Warnings:

  - You are about to drop the `tiered_payout_rule_to_team` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `tiered_payout_rule_to_user` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "tiered_payout_rule_to_team" DROP CONSTRAINT "tiered_payout_rule_to_team_teamId_fkey";

-- DropForeignKey
ALTER TABLE "tiered_payout_rule_to_team" DROP CONSTRAINT "tiered_payout_rule_to_team_tieredPayoutRuleId_fkey";

-- DropForeignKey
ALTER TABLE "tiered_payout_rule_to_user" DROP CONSTRAINT "tiered_payout_rule_to_user_tieredPayoutRuleId_fkey";

-- DropForeignKey
ALTER TABLE "tiered_payout_rule_to_user" DROP CONSTRAINT "tiered_payout_rule_to_user_userId_fkey";

-- DropTable
DROP TABLE "tiered_payout_rule_to_team";

-- DropTable
DROP TABLE "tiered_payout_rule_to_user";

-- CreateTable
CREATE TABLE "tiered_payout_target_set" (
    "id" SERIAL NOT NULL,
    "tieredPayoutRuleId" INTEGER NOT NULL,

    CONSTRAINT "tiered_payout_target_set_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "tiered_payout_rule_target" (
    "id" SERIAL NOT NULL,
    "tieredPayoutTargetSetId" INTEGER NOT NULL,
    "userId" INTEGER NOT NULL,
    "teamId" INTEGER NOT NULL,

    CONSTRAINT "tiered_payout_rule_target_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "tiered_payout_target_set" ADD CONSTRAINT "tiered_payout_target_set_tieredPayoutRuleId_fkey" FOREIGN KEY ("tieredPayoutRuleId") REFERENCES "tiered_payout_rule"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tiered_payout_rule_target" ADD CONSTRAINT "tiered_payout_rule_target_tieredPayoutTargetSetId_fkey" FOREIGN KEY ("tieredPayoutTargetSetId") REFERENCES "tiered_payout_target_set"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tiered_payout_rule_target" ADD CONSTRAINT "tiered_payout_rule_target_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tiered_payout_rule_target" ADD CONSTRAINT "tiered_payout_rule_target_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "team"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
