/*
  Warnings:

  - You are about to drop the column `fbAdIdRef` on the `ad_stat` table. All the data in the column will be lost.
  - You are about to drop the column `tikTokAdIdRef` on the `ad_stat` table. All the data in the column will be lost.
  - You are about to drop the `facebook_ad_stat` table. If the table is not empty, all the data it contains will be lost.
  - A unique constraint covering the columns `[date,accountId]` on the table `ad_stat` will be added. If there are existing duplicate values, this will fail.
  - Added the required column `accountIdRef` to the `ad_stat` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE "ad_stat" DROP CONSTRAINT "ad_stat_fbAdIdRef_fkey";

-- DropForeignKey
ALTER TABLE "ad_stat" DROP CONSTRAINT "ad_stat_tikTokAdIdRef_fkey";

-- DropForeignKey
ALTER TABLE "facebook_ad_stat" DROP CONSTRAINT "facebook_ad_stat_accountId_fkey";

-- DropIndex
DROP INDEX "ad_stat_date_adId_key";

-- AlterTable
ALTER TABLE "ad_stat" DROP COLUMN "fbAdIdRef",
DROP COLUMN "tikTokAdIdRef",
ADD COLUMN     "accountIdRef" INTEGER NOT NULL;

-- DropTable
DROP TABLE "facebook_ad_stat";

-- CreateIndex
CREATE UNIQUE INDEX "ad_stat_date_accountId_key" ON "ad_stat"("date", "accountId");

-- AddForeignKey
ALTER TABLE "ad_stat" ADD CONSTRAINT "ad_stat_accountIdRef_fkey" FOREIGN KEY ("accountIdRef") REFERENCES "account"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
