/*
  Warnings:

  - You are about to drop the column `type` on the `binom_country` table. All the data in the column will be lost.
  - You are about to drop the column `externalId` on the `provider_entity` table. All the data in the column will be lost.
  - You are about to drop the column `imprint` on the `provider_entity` table. All the data in the column will be lost.
  - You are about to drop the column `name` on the `provider_entity` table. All the data in the column will be lost.
  - You are about to drop the column `status` on the `provider_entity` table. All the data in the column will be lost.
  - You are about to drop the column `target` on the `provider_entity` table. All the data in the column will be lost.
  - You are about to drop the column `tonicCountryId` on the `provider_entity` table. All the data in the column will be lost.
  - You are about to drop the column `tonicOfferId` on the `provider_entity` table. All the data in the column will be lost.
  - You are about to drop the column `type` on the `provider_entity` table. All the data in the column will be lost.
  - You are about to drop the column `url` on the `provider_entity` table. All the data in the column will be lost.
  - You are about to drop the `binom_rule_to_provider_entity` table. If the table is not empty, all the data it contains will be lost.
  - Added the required column `binomUserId` to the `binom_campaign` table without a default value. This is not possible if the table is not empty.
  - Added the required column `binomCampaignId` to the `binom_rule` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE "binom_rule_to_provider_entity" DROP CONSTRAINT "binom_rule_to_provider_entity_entityId_fkey";

-- DropForeignKey
ALTER TABLE "binom_rule_to_provider_entity" DROP CONSTRAINT "binom_rule_to_provider_entity_ruleId_fkey";

-- DropForeignKey
ALTER TABLE "provider_entity" DROP CONSTRAINT "provider_entity_tonicCountryId_fkey";

-- DropForeignKey
ALTER TABLE "provider_entity" DROP CONSTRAINT "provider_entity_tonicOfferId_fkey";

-- AlterTable
ALTER TABLE "binom_campaign" ADD COLUMN     "binomUserId" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "binom_country" DROP COLUMN "type";

-- AlterTable
ALTER TABLE "binom_rule" ADD COLUMN     "binomCampaignId" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "binom_user" ADD COLUMN     "userExternalId" TEXT;

-- AlterTable
ALTER TABLE "provider_entity" DROP COLUMN "externalId",
DROP COLUMN "imprint",
DROP COLUMN "name",
DROP COLUMN "status",
DROP COLUMN "target",
DROP COLUMN "tonicCountryId",
DROP COLUMN "tonicOfferId",
DROP COLUMN "type",
DROP COLUMN "url";

-- DropTable
DROP TABLE "binom_rule_to_provider_entity";

-- CreateTable
CREATE TABLE "tonic_campaign" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "externalId" TEXT,
    "name" TEXT,
    "status" "TonicCampaignStatus",
    "imprint" BOOLEAN,
    "url" TEXT,
    "target" TEXT,
    "type" TEXT,
    "tonicOfferId" INTEGER,
    "tonicCountryId" INTEGER,
    "providerEntityId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "binom_rule_to_offer" (
    "id" SERIAL NOT NULL,
    "binomOfferId" INTEGER NOT NULL,
    "ruleId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "binom_offer" (
    "id" SERIAL NOT NULL,
    "url" TEXT NOT NULL,
    "externalId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "countryId" INTEGER NOT NULL,
    "affNetworkId" INTEGER NOT NULL,
    "binomUserId" INTEGER NOT NULL,
    "providerEntityId" INTEGER NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "tonic_campaign_providerEntityId_key" ON "tonic_campaign"("providerEntityId");

-- AddForeignKey
ALTER TABLE "binom_campaign" ADD CONSTRAINT "binom_campaign_binomUserId_fkey" FOREIGN KEY ("binomUserId") REFERENCES "binom_user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tonic_campaign" ADD CONSTRAINT "tonic_campaign_tonicOfferId_fkey" FOREIGN KEY ("tonicOfferId") REFERENCES "tonic_offer"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tonic_campaign" ADD CONSTRAINT "tonic_campaign_tonicCountryId_fkey" FOREIGN KEY ("tonicCountryId") REFERENCES "tonic_country"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tonic_campaign" ADD CONSTRAINT "tonic_campaign_providerEntityId_fkey" FOREIGN KEY ("providerEntityId") REFERENCES "provider_entity"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "binom_rule" ADD CONSTRAINT "binom_rule_binomCampaignId_fkey" FOREIGN KEY ("binomCampaignId") REFERENCES "binom_campaign"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "binom_rule_to_offer" ADD CONSTRAINT "binom_rule_to_offer_binomOfferId_fkey" FOREIGN KEY ("binomOfferId") REFERENCES "binom_offer"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "binom_rule_to_offer" ADD CONSTRAINT "binom_rule_to_offer_ruleId_fkey" FOREIGN KEY ("ruleId") REFERENCES "binom_rule"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "binom_offer" ADD CONSTRAINT "binom_offer_countryId_fkey" FOREIGN KEY ("countryId") REFERENCES "binom_country"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "binom_offer" ADD CONSTRAINT "binom_offer_affNetworkId_fkey" FOREIGN KEY ("affNetworkId") REFERENCES "binom_aff_network"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "binom_offer" ADD CONSTRAINT "binom_offer_binomUserId_fkey" FOREIGN KEY ("binomUserId") REFERENCES "binom_user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "binom_offer" ADD CONSTRAINT "binom_offer_providerEntityId_fkey" FOREIGN KEY ("providerEntityId") REFERENCES "provider_entity"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
