-- DropForeignKey
ALTER TABLE "facebook_ad" DROP CONSTRAINT "facebook_ad_adgroupId_fkey";

-- DropForeignKey
ALTER TABLE "facebook_adgroup" DROP CONSTRAINT "facebook_adgroup_campaignId_fkey";

-- DropForeignKey
ALTER TABLE "facebook_campaign" DROP CONSTRAINT "facebook_campaign_accountId_fkey";

-- DropForeignKey
ALTER TABLE "tiktok_ad" DROP CONSTRAINT "tiktok_ad_adgroupId_fkey";

-- DropForeignKey
ALTER TABLE "tiktok_adgroup" DROP CONSTRAINT "tiktok_adgroup_campaignId_fkey";

-- AlterTable
ALTER TABLE "facebook_ad" ADD COLUMN     "accountId" INTEGER,
ALTER COLUMN "adgroupId" DROP NOT NULL;

-- AlterTable
ALTER TABLE "facebook_adgroup" ADD COLUMN     "accountId" INTEGER,
ALTER COLUMN "campaignId" DROP NOT NULL;

-- AlterTable
ALTER TABLE "facebook_campaign" ALTER COLUMN "accountId" DROP NOT NULL;

-- AlterTable
ALTER TABLE "tiktok_ad" ADD COLUMN     "accountId" INTEGER,
ALTER COLUMN "adgroupId" DROP NOT NULL;

-- AlterTable
ALTER TABLE "tiktok_adgroup" ADD COLUMN     "accountId" INTEGER,
ALTER COLUMN "campaignId" DROP NOT NULL;

-- AddForeignKey
ALTER TABLE "tiktok_adgroup" ADD CONSTRAINT "tiktok_adgroup_campaignId_fkey" FOREIGN KEY ("campaignId") REFERENCES "tiktok_campaign"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tiktok_adgroup" ADD CONSTRAINT "tiktok_adgroup_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tiktok_ad" ADD CONSTRAINT "tiktok_ad_adgroupId_fkey" FOREIGN KEY ("adgroupId") REFERENCES "tiktok_adgroup"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tiktok_ad" ADD CONSTRAINT "tiktok_ad_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "facebook_campaign" ADD CONSTRAINT "facebook_campaign_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "facebook_adgroup" ADD CONSTRAINT "facebook_adgroup_campaignId_fkey" FOREIGN KEY ("campaignId") REFERENCES "facebook_campaign"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "facebook_adgroup" ADD CONSTRAINT "facebook_adgroup_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "facebook_ad" ADD CONSTRAINT "facebook_ad_adgroupId_fkey" FOREIGN KEY ("adgroupId") REFERENCES "facebook_adgroup"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "facebook_ad" ADD CONSTRAINT "facebook_ad_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE SET NULL ON UPDATE CASCADE;
