-- CreateEnum
CREATE TYPE "MemberRoleOverrideModelName" AS ENUM ('MemberRoleOverride');

-- CreateTable
CREATE TABLE "MemberRoleOverride" (
    "modelName" "MemberRoleOverrideModelName" NOT NULL DEFAULT E'MemberRoleOverride',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "organizationId" UUID NOT NULL,
    "overriddenOrganizationId" UUID,
    "roleId" UUID NOT NULL,
    "criteria" JSONB NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "name" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',

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

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

-- AddForeignKey
ALTER TABLE "MemberRoleOverride" ADD CONSTRAINT "MemberRoleOverride_overriddenOrganizationId_fkey" FOREIGN KEY ("overriddenOrganizationId") REFERENCES "Organization"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberRoleOverride" ADD CONSTRAINT "MemberRoleOverride_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "MemberRole"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
