-- ADR-0022 layered capacity policy. Org admins may set per-dimension lower
-- `organizationLimit` overrides; platform ceilings come from deployment config
-- (see `src/capacity/ceilings.ts`). `limits` is a JSON map of
-- CapacityDimension → number (only the set dimensions); service enforces
-- `LayeredLimit.Valid` (org limit ≤ platform ceiling).

-- CreateTable
CREATE TABLE "OrganizationCapacityPolicy" (
    "organizationId" TEXT NOT NULL,
    "limits" JSONB NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "OrganizationCapacityPolicy_pkey" PRIMARY KEY ("organizationId")
);

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