-- AlterEnum
ALTER TYPE "Provider" ADD VALUE 'INUVO';

-- CreateTable
CREATE TABLE "inuvo_domain" (
    "id" SERIAL NOT NULL,
    "domainId" INTEGER,

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

-- CreateTable
CREATE TABLE "inuvo_pixel" (
    "id" SERIAL NOT NULL,
    "pixelId" INTEGER,

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

-- CreateTable
CREATE TABLE "inuvo_campaign" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "externalInuvoCampaignId" INTEGER NOT NULL,
    "inuvoDomainId" INTEGER NOT NULL,
    "offerId" INTEGER,
    "inuvoLayoutId" INTEGER,
    "inuvoPixelId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "inuvo_layout" (
    "id" SERIAL NOT NULL,
    "key" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "offerType" "OfferType" NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "inuvo_domain_domainId_key" ON "inuvo_domain"("domainId");

-- CreateIndex
CREATE UNIQUE INDEX "inuvo_pixel_pixelId_key" ON "inuvo_pixel"("pixelId");

-- CreateIndex
CREATE UNIQUE INDEX "inuvo_campaign_offerId_key" ON "inuvo_campaign"("offerId");

-- CreateIndex
CREATE UNIQUE INDEX "inuvo_campaign_inuvoDomainId_externalInuvoCampaignId_key" ON "inuvo_campaign"("inuvoDomainId", "externalInuvoCampaignId");

-- AddForeignKey
ALTER TABLE "inuvo_domain" ADD CONSTRAINT "inuvo_domain_domainId_fkey" FOREIGN KEY ("domainId") REFERENCES "domain"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "inuvo_pixel" ADD CONSTRAINT "inuvo_pixel_pixelId_fkey" FOREIGN KEY ("pixelId") REFERENCES "pixel"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "inuvo_campaign" ADD CONSTRAINT "inuvo_campaign_inuvoDomainId_fkey" FOREIGN KEY ("inuvoDomainId") REFERENCES "inuvo_domain"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "inuvo_campaign" ADD CONSTRAINT "inuvo_campaign_offerId_fkey" FOREIGN KEY ("offerId") REFERENCES "offer"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "inuvo_campaign" ADD CONSTRAINT "inuvo_campaign_inuvoLayoutId_fkey" FOREIGN KEY ("inuvoLayoutId") REFERENCES "inuvo_layout"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "inuvo_campaign" ADD CONSTRAINT "inuvo_campaign_inuvoPixelId_fkey" FOREIGN KEY ("inuvoPixelId") REFERENCES "inuvo_pixel"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
