-- AlterEnum
ALTER TYPE "ApiAccessType" ADD VALUE 'BINOM';

-- AlterEnum
ALTER TYPE "TrafficSource" ADD VALUE 'GENERAL';

-- AlterTable
ALTER TABLE "api_access" ADD COLUMN     "url" TEXT;

-- AlterTable
ALTER TABLE "binom_campaign" ADD COLUMN     "binomGroupId" TEXT,
ADD COLUMN     "binomTfSourceId" TEXT;

-- AlterTable
ALTER TABLE "provider_account" ADD COLUMN     "login" TEXT,
ADD COLUMN     "password" TEXT;

-- CreateTable
CREATE TABLE "binom_rule" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "default" BOOLEAN NOT NULL,

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

-- CreateTable
CREATE TABLE "binom_country" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "type" TEXT NOT NULL DEFAULT '4',

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

-- CreateTable
CREATE TABLE "binom_rule_to_provider_entity" (
    "id" SERIAL NOT NULL,
    "entityId" INTEGER NOT NULL,
    "ruleId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "binom_rule_to_country" (
    "id" SERIAL NOT NULL,
    "countryId" INTEGER NOT NULL,
    "ruleId" INTEGER NOT NULL,

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

-- AddForeignKey
ALTER TABLE "binom_rule_to_provider_entity" ADD CONSTRAINT "binom_rule_to_provider_entity_entityId_fkey" FOREIGN KEY ("entityId") REFERENCES "provider_entity"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

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

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

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