/*
  Warnings:

  - A unique constraint covering the columns `[memberId,externalServiceId]` on the table `MemberPaycheck` will be added. If there are existing duplicate values, this will fail.

*/
-- CreateEnum
CREATE TYPE "MemberMergeModelName" AS ENUM ('MemberMerge');

-- DropIndex
DROP INDEX "MemberPaycheck_externalServiceId_key";

-- CreateTable
CREATE TABLE "MemberMerge" (
    "modelName" "MemberMergeModelName" NOT NULL DEFAULT 'MemberMerge',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "targetId" UUID NOT NULL,
    "sourceId" UUID NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "organizationId" UUID NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "MemberPaycheck_memberId_externalServiceId_key" ON "MemberPaycheck"("memberId", "externalServiceId");

-- AddForeignKey
ALTER TABLE "MemberMerge" ADD CONSTRAINT "MemberMerge_targetId_fkey" FOREIGN KEY ("targetId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberMerge" ADD CONSTRAINT "MemberMerge_sourceId_fkey" FOREIGN KEY ("sourceId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberMerge" ADD CONSTRAINT "MemberMerge_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
