-- CreateEnum
CREATE TYPE "PayrollSyncErrorModelName" AS ENUM ('PayrollSyncError');

-- CreateTable
CREATE TABLE "PayrollSyncError" (
    "modelName" "PayrollSyncErrorModelName" NOT NULL DEFAULT 'PayrollSyncError',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "payrollSyncId" UUID NOT NULL,
    "modelType" TEXT NOT NULL,
    "memberId" UUID,
    "data" JSONB NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "organizationId" UUID NOT NULL,

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

-- AddForeignKey
ALTER TABLE "PayrollSyncError" ADD CONSTRAINT "PayrollSyncError_payrollSyncId_fkey" FOREIGN KEY ("payrollSyncId") REFERENCES "PayrollSync"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PayrollSyncError" ADD CONSTRAINT "PayrollSyncError_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE SET NULL ON UPDATE CASCADE;

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