CREATE TABLE "TenantProviderMetric" (
  "id" TEXT NOT NULL,
  "tenantId" TEXT NOT NULL,
  "provider" "MailProvider" NOT NULL,
  "avgListingRate" DOUBLE PRECISION,
  "avgProcessingRate" DOUBLE PRECISION,
  "avgUnsubscribeRate" DOUBLE PRECISION,
  "avgRoutingRate" DOUBLE PRECISION,
  "listingSampleCount" INTEGER NOT NULL DEFAULT 0,
  "processingSampleCount" INTEGER NOT NULL DEFAULT 0,
  "unsubscribeSampleCount" INTEGER NOT NULL DEFAULT 0,
  "routingSampleCount" INTEGER NOT NULL DEFAULT 0,
  "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

CREATE UNIQUE INDEX "TenantProviderMetric_tenantId_provider_key" ON "TenantProviderMetric"("tenantId", "provider");
CREATE INDEX "TenantProviderMetric_tenantId_idx" ON "TenantProviderMetric"("tenantId");

ALTER TABLE "TenantProviderMetric"
ADD CONSTRAINT "TenantProviderMetric_tenantId_fkey"
FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
