/*
  Warnings:

  - You are about to drop the column `templateId` on the `TemplateInfo` table. All the data in the column will be lost.
  - You are about to drop the column `badge` on the `templateProduct` table. All the data in the column will be lost.
  - Added the required column `organizationId` to the `templateProduct` table without a default value. This is not possible if the table is not empty.
  - Made the column `templateId` on table `templateProduct` required. This step will fail if there are existing NULL values in that column.

*/
-- DropForeignKey
ALTER TABLE "TemplateInfo" DROP CONSTRAINT "TemplateInfo_templateId_fkey";

-- DropForeignKey
ALTER TABLE "templateProduct" DROP CONSTRAINT "templateProduct_templateId_fkey";

-- DropForeignKey
ALTER TABLE "templates" DROP CONSTRAINT "templates_organizationTypeId_fkey";

-- DropIndex
DROP INDEX "templateProduct_productId_idx";

-- AlterTable
ALTER TABLE "TemplateInfo" DROP COLUMN "templateId";

-- AlterTable
ALTER TABLE "templateProduct" DROP COLUMN "badge",
ADD COLUMN     "badgeId" INTEGER,
ADD COLUMN     "organizationId" INTEGER NOT NULL,
ALTER COLUMN "templateId" SET NOT NULL;

-- CreateTable
CREATE TABLE "Badge" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "status" BOOLEAN NOT NULL DEFAULT true,
    "image" TEXT NOT NULL,

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

-- AddForeignKey
ALTER TABLE "templates" ADD CONSTRAINT "templates_organizationTypeId_fkey" FOREIGN KEY ("organizationTypeId") REFERENCES "organization_types"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "templateProduct" ADD CONSTRAINT "templateProduct_badgeId_fkey" FOREIGN KEY ("badgeId") REFERENCES "Badge"("id") ON DELETE SET NULL ON UPDATE CASCADE;
